@offckb/cli 0.4.7-canary-dfe1b5f.0 → 0.4.7-canary-a078424.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/build/index.js +226 -37
  2. package/package.json +1 -2
package/build/index.js CHANGED
@@ -377,9 +377,9 @@ program
377
377
  const txHash = option.txHash;
378
378
  if (option.singleScript) {
379
379
  const { cellType, cellIndex, scriptType } = (0, debug_1.parseSingleScriptOption)(option.singleScript);
380
- return (0, debug_1.debugSingleScript)(txHash, cellIndex, cellType, scriptType, option.network, option.bin);
380
+ return yield (0, debug_1.debugSingleScript)(txHash, cellIndex, cellType, scriptType, option.network, option.bin);
381
381
  }
382
- return (0, debug_1.debugTransaction)(txHash, option.network);
382
+ return yield (0, debug_1.debugTransaction)(txHash, option.network);
383
383
  }));
384
384
  program
385
385
  .command('system-scripts')
@@ -975,12 +975,14 @@ const base_1 = __nccwpck_require__(69951);
975
975
  const encoding_1 = __nccwpck_require__(6851);
976
976
  const logger_1 = __nccwpck_require__(65370);
977
977
  function debugTransaction(txHash, network) {
978
- const txFile = buildTxFileOptionBy(txHash, network);
979
- const opts = buildTransactionDebugOptions(txHash, network);
980
- for (const opt of opts) {
981
- logger_1.logger.section(opt.name, [], 'info');
982
- debugRaw(`${txFile} ${opt.cmdOption}`);
983
- }
978
+ return __awaiter(this, void 0, void 0, function* () {
979
+ const txFile = yield buildTxFileOptionBy(txHash, network);
980
+ const opts = buildTransactionDebugOptions(txHash, network);
981
+ for (const opt of opts) {
982
+ logger_1.logger.section(opt.name, [], 'info');
983
+ debugRaw(`${txFile} ${opt.cmdOption}`);
984
+ }
985
+ });
984
986
  }
985
987
  function buildTransactionDebugOptions(txHash, network) {
986
988
  var _a;
@@ -1011,12 +1013,14 @@ function buildTransactionDebugOptions(txHash, network) {
1011
1013
  return result;
1012
1014
  }
1013
1015
  function debugSingleScript(txHash, cellIndex, cellType, scriptType, network, bin) {
1014
- const txFile = buildTxFileOptionBy(txHash, network);
1015
- let opt = `--cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptType}`;
1016
- if (bin) {
1017
- opt = opt + ` --bin ${bin}`;
1018
- }
1019
- debugRaw(`${txFile} ${opt}`);
1016
+ return __awaiter(this, void 0, void 0, function* () {
1017
+ const txFile = yield buildTxFileOptionBy(txHash, network);
1018
+ let opt = `--cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptType}`;
1019
+ if (bin) {
1020
+ opt = opt + ` --bin ${bin}`;
1021
+ }
1022
+ debugRaw(`${txFile} ${opt}`);
1023
+ });
1020
1024
  }
1021
1025
  // Helper function to validate and parse the --script value
1022
1026
  function parseSingleScriptOption(value) {
@@ -1033,18 +1037,20 @@ function parseSingleScriptOption(value) {
1033
1037
  };
1034
1038
  }
1035
1039
  function buildTxFileOptionBy(txHash, network) {
1036
- const settings = (0, setting_1.readSettings)();
1037
- const outputFilePath = buildDebugFullTransactionFilePath(network, txHash);
1038
- if (!fs_1.default.existsSync(outputFilePath)) {
1039
- const rpc = settings[network].rpcUrl;
1040
- const txJsonFilePath = buildTransactionJsonFilePath(network, txHash);
1040
+ return __awaiter(this, void 0, void 0, function* () {
1041
+ const settings = (0, setting_1.readSettings)();
1042
+ const outputFilePath = buildDebugFullTransactionFilePath(network, txHash);
1041
1043
  if (!fs_1.default.existsSync(outputFilePath)) {
1042
- fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
1044
+ const rpc = settings[network].rpcUrl;
1045
+ const txJsonFilePath = buildTransactionJsonFilePath(network, txHash);
1046
+ if (!fs_1.default.existsSync(outputFilePath)) {
1047
+ fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
1048
+ }
1049
+ yield (0, ckb_tx_dumper_1.dumpTransaction)({ rpc, txJsonFilePath, outputFilePath });
1043
1050
  }
1044
- (0, ckb_tx_dumper_1.dumpTransaction)({ rpc, txJsonFilePath, outputFilePath });
1045
- }
1046
- const opt = `--tx-file ${(0, encoding_1.encodeBinPathForTerminal)(outputFilePath)}`;
1047
- return opt;
1051
+ const opt = `--tx-file ${(0, encoding_1.encodeBinPathForTerminal)(outputFilePath)}`;
1052
+ return opt;
1053
+ });
1048
1054
  }
1049
1055
  function buildTransactionJsonFilePath(network, txHash) {
1050
1056
  const settings = (0, setting_1.readSettings)();
@@ -5318,25 +5324,208 @@ CKBDebugger.wasmDebugger = null;
5318
5324
 
5319
5325
  "use strict";
5320
5326
 
5327
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
5328
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5329
+ return new (P || (P = Promise))(function (resolve, reject) {
5330
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5331
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
5332
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
5333
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
5334
+ });
5335
+ };
5321
5336
  var __importDefault = (this && this.__importDefault) || function (mod) {
5322
5337
  return (mod && mod.__esModule) ? mod : { "default": mod };
5323
5338
  };
5324
5339
  Object.defineProperty(exports, "__esModule", ({ value: true }));
5325
5340
  exports.dumpTransaction = dumpTransaction;
5341
+ const fs_1 = __importDefault(__nccwpck_require__(79896));
5326
5342
  const path_1 = __importDefault(__nccwpck_require__(16928));
5327
- const child_process_1 = __nccwpck_require__(35317);
5328
- const setting_1 = __nccwpck_require__(25546);
5343
+ const core_1 = __nccwpck_require__(51981);
5344
+ const advanced_1 = __nccwpck_require__(97875);
5329
5345
  const logger_1 = __nccwpck_require__(65370);
5330
- function dumpTransaction({ rpc, txJsonFilePath, outputFilePath }) {
5331
- const ckbTransactionDumperPath = path_1.default.resolve(setting_1.packageRootPath, 'node_modules/.bin/ckb-transaction-dumper');
5332
- const command = `${ckbTransactionDumperPath} --rpc ${rpc} --tx "${txJsonFilePath}" --output "${outputFilePath}"`;
5333
- try {
5334
- (0, child_process_1.execSync)(command, { stdio: 'inherit' });
5335
- logger_1.logger.debug('Dump transaction successfully');
5336
- }
5337
- catch (error) {
5338
- logger_1.logger.error('Command failed:', error.message);
5339
- }
5346
+ const OutPointCodec = core_1.ccc.mol.struct({
5347
+ txHash: core_1.ccc.mol.Byte32,
5348
+ index: core_1.ccc.mol.Uint32LE,
5349
+ });
5350
+ const OutPointVecCodec = core_1.ccc.mol.vector(OutPointCodec);
5351
+ function toMockScript(script) {
5352
+ if (!script)
5353
+ return null;
5354
+ return {
5355
+ code_hash: script.codeHash,
5356
+ hash_type: script.hashType,
5357
+ args: script.args,
5358
+ };
5359
+ }
5360
+ function toDepType(depType) {
5361
+ // Convert camelCase to snake_case for CKB JSON format
5362
+ if (depType === 'depGroup')
5363
+ return 'dep_group';
5364
+ return depType;
5365
+ }
5366
+ function resolveCellDeps(client, cellDeps) {
5367
+ return __awaiter(this, void 0, void 0, function* () {
5368
+ const resolved = [];
5369
+ for (const cellDep of cellDeps) {
5370
+ const cell = yield client.getCell(cellDep.outPoint);
5371
+ if (!cell) {
5372
+ throw new Error(`Cell not found: ${JSON.stringify(cellDep.outPoint)}`);
5373
+ }
5374
+ if (cellDep.depType === 'depGroup') {
5375
+ resolved.push({
5376
+ cell_dep: {
5377
+ out_point: {
5378
+ tx_hash: cellDep.outPoint.txHash,
5379
+ index: '0x' + cellDep.outPoint.index.toString(16),
5380
+ },
5381
+ dep_type: toDepType(cellDep.depType),
5382
+ },
5383
+ output: {
5384
+ capacity: '0x' + cell.cellOutput.capacity.toString(16),
5385
+ lock: toMockScript(cell.cellOutput.lock),
5386
+ type: toMockScript(cell.cellOutput.type),
5387
+ },
5388
+ data: cell.outputData,
5389
+ });
5390
+ const data = cell.outputData;
5391
+ if (data && data !== '0x') {
5392
+ const outpoints = OutPointVecCodec.decode(data);
5393
+ for (const op of outpoints) {
5394
+ const outPoint = core_1.ccc.OutPoint.from({
5395
+ txHash: op.txHash,
5396
+ index: '0x' + op.index.toString(16),
5397
+ });
5398
+ const refCell = yield client.getCell(outPoint);
5399
+ if (!refCell) {
5400
+ logger_1.logger.error(`Failed to resolve cell for depGroup out_point: tx_hash=${outPoint.txHash}, index=${outPoint.index.toString()}`);
5401
+ throw new Error('Failed to resolve all cells referenced by depGroup.');
5402
+ }
5403
+ resolved.push({
5404
+ cell_dep: {
5405
+ out_point: {
5406
+ tx_hash: outPoint.txHash,
5407
+ index: '0x' + outPoint.index.toString(16),
5408
+ },
5409
+ dep_type: 'code',
5410
+ },
5411
+ output: {
5412
+ capacity: '0x' + refCell.cellOutput.capacity.toString(16),
5413
+ lock: toMockScript(refCell.cellOutput.lock),
5414
+ type: toMockScript(refCell.cellOutput.type),
5415
+ },
5416
+ data: refCell.outputData,
5417
+ });
5418
+ }
5419
+ }
5420
+ }
5421
+ else {
5422
+ resolved.push({
5423
+ cell_dep: {
5424
+ out_point: {
5425
+ tx_hash: cellDep.outPoint.txHash,
5426
+ index: '0x' + cellDep.outPoint.index.toString(16),
5427
+ },
5428
+ dep_type: toDepType(cellDep.depType),
5429
+ },
5430
+ output: {
5431
+ capacity: '0x' + cell.cellOutput.capacity.toString(16),
5432
+ lock: toMockScript(cell.cellOutput.lock),
5433
+ type: toMockScript(cell.cellOutput.type),
5434
+ },
5435
+ data: cell.outputData,
5436
+ });
5437
+ }
5438
+ }
5439
+ return resolved;
5440
+ });
5441
+ }
5442
+ function resolveInputs(client, inputs) {
5443
+ return __awaiter(this, void 0, void 0, function* () {
5444
+ const resolved = [];
5445
+ for (const input of inputs) {
5446
+ const cell = yield client.getCell(input.previousOutput);
5447
+ if (!cell) {
5448
+ throw new Error(`Input cell not found: ${JSON.stringify(input.previousOutput)}`);
5449
+ }
5450
+ resolved.push({
5451
+ input: {
5452
+ previous_output: {
5453
+ tx_hash: input.previousOutput.txHash,
5454
+ index: '0x' + input.previousOutput.index.toString(16),
5455
+ },
5456
+ since: '0x' + input.since.toString(16),
5457
+ },
5458
+ output: {
5459
+ capacity: '0x' + cell.cellOutput.capacity.toString(16),
5460
+ lock: toMockScript(cell.cellOutput.lock),
5461
+ type: toMockScript(cell.cellOutput.type),
5462
+ },
5463
+ data: cell.outputData,
5464
+ });
5465
+ }
5466
+ return resolved;
5467
+ });
5468
+ }
5469
+ function dumpTransaction(_a) {
5470
+ return __awaiter(this, arguments, void 0, function* ({ rpc, txJsonFilePath, outputFilePath }) {
5471
+ try {
5472
+ const isTestnet = /testnet/i.test(rpc);
5473
+ const client = isTestnet
5474
+ ? new core_1.ccc.ClientPublicTestnet({
5475
+ url: rpc,
5476
+ fallbacks: [],
5477
+ })
5478
+ : new core_1.ccc.ClientPublicMainnet({
5479
+ url: rpc,
5480
+ fallbacks: [],
5481
+ });
5482
+ const txJson = JSON.parse(fs_1.default.readFileSync(txJsonFilePath, 'utf-8'));
5483
+ const tx = advanced_1.cccA.JsonRpcTransformers.transactionTo(txJson);
5484
+ const [cell_deps, inputs] = yield Promise.all([
5485
+ resolveCellDeps(client, tx.cellDeps),
5486
+ resolveInputs(client, tx.inputs),
5487
+ ]);
5488
+ const mockTx = {
5489
+ mock_info: {
5490
+ inputs,
5491
+ cell_deps,
5492
+ header_deps: tx.headerDeps.map((h) => h.toString()),
5493
+ },
5494
+ tx: {
5495
+ version: '0x' + tx.version.toString(16),
5496
+ cell_deps: tx.cellDeps.map((dep) => ({
5497
+ out_point: {
5498
+ tx_hash: dep.outPoint.txHash,
5499
+ index: '0x' + dep.outPoint.index.toString(16),
5500
+ },
5501
+ dep_type: toDepType(dep.depType),
5502
+ })),
5503
+ header_deps: tx.headerDeps.map((h) => h.toString()),
5504
+ inputs: tx.inputs.map((input) => ({
5505
+ previous_output: {
5506
+ tx_hash: input.previousOutput.txHash,
5507
+ index: '0x' + input.previousOutput.index.toString(16),
5508
+ },
5509
+ since: '0x' + input.since.toString(16),
5510
+ })),
5511
+ outputs: tx.outputs.map((output) => ({
5512
+ capacity: '0x' + output.capacity.toString(16),
5513
+ lock: toMockScript(output.lock),
5514
+ type: toMockScript(output.type),
5515
+ })),
5516
+ outputs_data: tx.outputsData,
5517
+ witnesses: tx.witnesses.map((w) => w.toString()),
5518
+ },
5519
+ };
5520
+ fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
5521
+ fs_1.default.writeFileSync(outputFilePath, JSON.stringify(mockTx, null, 2));
5522
+ logger_1.logger.debug('Dump transaction successfully');
5523
+ }
5524
+ catch (error) {
5525
+ logger_1.logger.error('Failed to dump transaction:', error instanceof Error ? error.message : String(error));
5526
+ throw error;
5527
+ }
5528
+ });
5340
5529
  }
5341
5530
 
5342
5531
 
@@ -147449,7 +147638,7 @@ module.exports = {"version":"3.17.0"};
147449
147638
  /***/ ((module) => {
147450
147639
 
147451
147640
  "use strict";
147452
- module.exports = /*#__PURE__*/JSON.parse('{"rE":"0.4.7-canary-dfe1b5f.0","h_":"ckb development network for your first try"}');
147641
+ module.exports = /*#__PURE__*/JSON.parse('{"rE":"0.4.7-canary-a078424.0","h_":"ckb development network for your first try"}');
147453
147642
 
147454
147643
  /***/ })
147455
147644
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.4.7-canary-dfe1b5f.0",
3
+ "version": "0.4.7-canary-a078424.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
@@ -86,7 +86,6 @@
86
86
  "blessed": "0.1.81",
87
87
  "chalk": "4.1.2",
88
88
  "child_process": "^1.0.2",
89
- "ckb-transaction-dumper": "^0.4.2",
90
89
  "commander": "^12.0.0",
91
90
  "http-proxy": "^1.18.1",
92
91
  "https-proxy-agent": "^7.0.5",