|
| 1 | +# Replace ckb-transaction-dumper with ccc-based implementation |
| 2 | + |
| 3 | +## TL;DR |
| 4 | + |
| 5 | +> **Quick Summary**: Replace `ckb-transaction-dumper` npm package with a pure ccc-based implementation. |
| 6 | +> |
| 7 | +> **Deliverables**: |
| 8 | +> |
| 9 | +> - New `src/tools/ckb-tx-dumper.ts` (replaces old implementation) |
| 10 | +> - Removed `ckb-transaction-dumper` from package.json |
| 11 | +> |
| 12 | +> **Estimated Effort**: Medium (2-3 hours) |
| 13 | +> **Parallel Execution**: NO - sequential |
| 14 | +
|
| 15 | +--- |
| 16 | + |
| 17 | +## Context |
| 18 | + |
| 19 | +### Request |
| 20 | + |
| 21 | +Replace `ckb-transaction-dumper` with ccc-based implementation (no external dependencies, use ccc throughout). |
| 22 | + |
| 23 | +### Current Implementation |
| 24 | + |
| 25 | +- `src/tools/ckb-tx-dumper.ts` spawns `ckb-transaction-dumper` binary |
| 26 | +- Depends on npm package `ckb-transaction-dumper@0.4.2` |
| 27 | + |
| 28 | +### What TransactionDumper Does |
| 29 | + |
| 30 | +1. Load transaction (from file or fetch by hash) |
| 31 | +2. Resolve cell deps (handle dep_group type) |
| 32 | +3. Resolve inputs |
| 33 | +4. Output mock transaction JSON for ckb-debugger |
| 34 | + |
| 35 | +### ccc Molecule Support |
| 36 | + |
| 37 | +ccc provides full molecule codec: |
| 38 | + |
| 39 | +- `ccc.molecule.struct()` - for OutPoint { tx_hash, index } |
| 40 | +- `ccc.molecule.vector()` - for OutPointVec |
| 41 | +- `ccc.Byte32`, `ccc.Uint32LE` - predefined codecs |
| 42 | + |
| 43 | +No manual bytes parsing needed! |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Work Objectives |
| 48 | + |
| 49 | +### Core Objective |
| 50 | + |
| 51 | +Replace `ckb-transaction-dumper` with pure ccc implementation. |
| 52 | + |
| 53 | +### Must Have |
| 54 | + |
| 55 | +- Keep `DumpOption` interface |
| 56 | +- Keep `dumpTransaction()` signature |
| 57 | +- Same JSON output format |
| 58 | + |
| 59 | +### Must NOT Have |
| 60 | + |
| 61 | +- Breaking API changes |
| 62 | +- New dependencies |
| 63 | + |
| 64 | +--- |
| 65 | + |
| 66 | +## TODOs |
| 67 | + |
| 68 | +- [ ] 1. Implement ccc-based transaction dumper |
| 69 | + |
| 70 | + **What to do**: |
| 71 | + |
| 72 | + - Rewrite `src/tools/ckb-tx-dumper.ts` |
| 73 | + - Use ccc Client for RPC calls |
| 74 | + - Use ccc molecule codecs for dep_group unpacking |
| 75 | + |
| 76 | + **Key implementation**: |
| 77 | + |
| 78 | + ```typescript |
| 79 | + import { ccc } from '@ckb-ccc/core'; |
| 80 | + |
| 81 | + // OutPoint codec for dep_group unpacking |
| 82 | + const OutPointCodec = ccc.molecule.struct({ |
| 83 | + txHash: ccc.Byte32, |
| 84 | + index: ccc.Uint32LE, |
| 85 | + }); |
| 86 | + |
| 87 | + const OutPointVecCodec = ccc.molecule.vector(OutPointCodec); |
| 88 | + |
| 89 | + // Unpack dep_group data |
| 90 | + function unpackDepGroup(data: string): ccc.OutPoint[] { |
| 91 | + return OutPointVecCodec.decode(data).map((o) => |
| 92 | + ccc.OutPoint.from({ txHash: o.txHash, index: '0x' + o.index.toString(16) }), |
| 93 | + ); |
| 94 | + } |
| 95 | + ``` |
| 96 | + |
| 97 | + **Acceptance Criteria**: |
| 98 | + |
| 99 | + - [ ] Uses ccc Client for RPC |
| 100 | + - [ ] Uses ccc molecule for dep_group |
| 101 | + - [ ] Same output format |
| 102 | + |
| 103 | + **QA Scenarios**: |
| 104 | + |
| 105 | + ``` |
| 106 | + Scenario: Compiles successfully |
| 107 | + Tool: Bash |
| 108 | + Steps: npm run typecheck |
| 109 | + Expected: No errors |
| 110 | + ``` |
| 111 | + |
| 112 | + **Commit**: `feat: implement transaction dumper with ccc` |
| 113 | + |
| 114 | +--- |
| 115 | + |
| 116 | +- [ ] 2. Remove ckb-transaction-dumper dependency |
| 117 | + |
| 118 | + **What to do**: |
| 119 | + |
| 120 | + - Remove from `package.json` |
| 121 | + - Run `pnpm install` |
| 122 | + |
| 123 | + **Commit**: `chore: remove ckb-transaction-dumper` |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## Verification |
| 128 | + |
| 129 | +```bash |
| 130 | +npm run typecheck |
| 131 | +npm run lint |
| 132 | +grep -c "ckb-transaction-dumper" package.json || echo "Clean" |
| 133 | +``` |
| 134 | + |
| 135 | +## Key Implementation Notes |
| 136 | + |
| 137 | +### Dep Group Unpacking with ccc |
| 138 | + |
| 139 | +```typescript |
| 140 | +const OutPointCodec = ccc.molecule.struct({ |
| 141 | + txHash: ccc.Byte32, |
| 142 | + index: ccc.Uint32LE, |
| 143 | +}); |
| 144 | +const OutPointVecCodec = ccc.molecule.vector(OutPointCodec); |
| 145 | + |
| 146 | +// Usage |
| 147 | +const outpoints = OutPointVecCodec.decode(cellData); |
| 148 | +``` |
| 149 | + |
| 150 | +### Mock Transaction Structure |
| 151 | + |
| 152 | +```typescript |
| 153 | +interface MockTransaction { |
| 154 | + mock_info: { |
| 155 | + inputs: MockInput[]; |
| 156 | + cell_deps: MockCellDep[]; |
| 157 | + header_deps: any[]; |
| 158 | + }; |
| 159 | + tx: Transaction; |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +### Algorithm |
| 164 | + |
| 165 | +1. Load tx from file |
| 166 | +2. For each cell_dep: |
| 167 | + - Fetch cell |
| 168 | + - If dep_type === 'dep_group': |
| 169 | + - Decode cell.data as OutPointVec |
| 170 | + - Fetch each referenced cell |
| 171 | + - Add to mock_info.cell_deps |
| 172 | +3. For each input: |
| 173 | + - Fetch referenced cell |
| 174 | + - Add to mock_info.inputs |
| 175 | +4. Write JSON output |
0 commit comments