@offckb/cli 0.2.7 → 0.3.0-canary-a9175e7.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 (90) hide show
  1. package/README.md +46 -19
  2. package/ckb/devnet/specs/dev.toml +7 -7
  3. package/dist/cfg/setting.d.ts +38 -0
  4. package/dist/cfg/setting.js +67 -7
  5. package/dist/cli.js +51 -32
  6. package/dist/cmd/clean.js +7 -5
  7. package/dist/cmd/config.d.ts +5 -3
  8. package/dist/cmd/config.js +39 -12
  9. package/dist/cmd/create.d.ts +1 -1
  10. package/dist/cmd/create.js +19 -8
  11. package/dist/cmd/debug.d.ts +13 -0
  12. package/dist/cmd/debug.js +100 -0
  13. package/dist/cmd/deploy.js +45 -25
  14. package/dist/cmd/deposit.js +9 -2
  15. package/dist/cmd/inject-config.d.ts +0 -3
  16. package/dist/cmd/inject-config.js +20 -80
  17. package/dist/cmd/list-hashes.d.ts +25 -1
  18. package/dist/cmd/list-hashes.js +24 -16
  19. package/dist/cmd/{deployed-scripts.d.ts → my-scripts.d.ts} +1 -1
  20. package/dist/cmd/my-scripts.js +25 -0
  21. package/dist/cmd/node.d.ts +5 -1
  22. package/dist/cmd/node.js +22 -8
  23. package/dist/cmd/proxy-rpc.d.ts +7 -0
  24. package/dist/cmd/proxy-rpc.js +23 -0
  25. package/dist/cmd/sync-config.js +16 -11
  26. package/dist/cmd/system-scripts.d.ts +42 -0
  27. package/dist/cmd/system-scripts.js +265 -0
  28. package/dist/deploy/migration.d.ts +45 -0
  29. package/dist/deploy/migration.js +131 -0
  30. package/dist/deploy/toml.d.ts +38 -0
  31. package/dist/deploy/toml.js +60 -0
  32. package/dist/deploy/util.d.ts +2 -0
  33. package/dist/deploy/util.js +19 -0
  34. package/dist/node/init-chain.js +41 -0
  35. package/dist/{cmd/develop → node}/install.d.ts +4 -5
  36. package/dist/{cmd/develop → node}/install.js +31 -31
  37. package/dist/scripts/gen.d.ts +5 -0
  38. package/dist/scripts/gen.js +69 -0
  39. package/dist/scripts/public.d.ts +8 -0
  40. package/dist/scripts/public.js +396 -0
  41. package/dist/scripts/type.d.ts +46 -0
  42. package/dist/scripts/type.js +19 -0
  43. package/dist/scripts/util.d.ts +3 -0
  44. package/dist/scripts/util.js +84 -0
  45. package/dist/template/config.d.ts +4 -0
  46. package/dist/template/config.js +60 -0
  47. package/dist/template/offckb.config.d.ts +69 -0
  48. package/dist/template/offckb.config.js +79 -0
  49. package/dist/{util/template.js → template/option.js} +2 -2
  50. package/dist/template/option.json +16 -0
  51. package/dist/tools/ckb-debugger.d.ts +12 -0
  52. package/dist/tools/ckb-debugger.js +31 -0
  53. package/dist/tools/ckb-tx-dumper.d.ts +6 -0
  54. package/dist/tools/ckb-tx-dumper.js +21 -0
  55. package/dist/tools/rpc-proxy.d.ts +9 -0
  56. package/dist/tools/rpc-proxy.js +84 -0
  57. package/dist/util/ckb.d.ts +3 -2
  58. package/dist/util/ckb.js +16 -3
  59. package/dist/util/encoding.d.ts +1 -0
  60. package/dist/util/encoding.js +7 -1
  61. package/dist/util/fs.d.ts +1 -2
  62. package/dist/util/fs.js +8 -32
  63. package/dist/util/git.js +19 -7
  64. package/dist/util/request.js +0 -1
  65. package/dist/util/type.d.ts +1 -0
  66. package/dist/util/validator.d.ts +1 -0
  67. package/dist/util/validator.js +13 -4
  68. package/package.json +6 -2
  69. package/dist/cfg/const.d.ts +0 -20
  70. package/dist/cfg/const.js +0 -51
  71. package/dist/cmd/deployed-scripts.js +0 -14
  72. package/dist/cmd/develop/build-account.d.ts +0 -1
  73. package/dist/cmd/develop/build-account.js +0 -9
  74. package/dist/cmd/develop/genkey.d.ts +0 -14
  75. package/dist/cmd/develop/genkey.js +0 -143
  76. package/dist/cmd/develop/init-chain.js +0 -76
  77. package/dist/cmd/develop/lumos-config.d.ts +0 -4
  78. package/dist/cmd/develop/lumos-config.js +0 -153
  79. package/dist/util/config.d.ts +0 -9
  80. package/dist/util/config.js +0 -136
  81. package/templates/config.json +0 -98
  82. /package/ckb/devnet/specs/{omni_lock → omnilock} +0 -0
  83. /package/ckb/devnet/specs/{spore-scripts → spore}/spore +0 -0
  84. /package/ckb/devnet/specs/{spore-scripts/cluster → spore/spore_cluster} +0 -0
  85. /package/ckb/devnet/specs/{spore-scripts/cluster_agent → spore/spore_cluster_agent} +0 -0
  86. /package/ckb/devnet/specs/{spore-scripts/cluster_proxy → spore/spore_cluster_proxy} +0 -0
  87. /package/ckb/devnet/specs/{spore-scripts → spore}/spore_extension_lua +0 -0
  88. /package/ckb/devnet/specs/{xudt_rce → xudt} +0 -0
  89. /package/dist/{cmd/develop → node}/init-chain.d.ts +0 -0
  90. /package/dist/{util/template.d.ts → template/option.d.ts} +0 -0
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.readUserDeployedScriptsInfo = void 0;
27
+ const fs = __importStar(require("fs"));
28
+ const util_1 = require("../deploy/util");
29
+ const migration_1 = require("../deploy/migration");
30
+ const fs_1 = require("../util/fs");
31
+ function readUserDeployedScriptsInfo(network) {
32
+ const deployedScriptsInfo = {};
33
+ // Read all files in the folder
34
+ const folder = (0, util_1.getContractsPath)(network);
35
+ if (!fs.existsSync(folder)) {
36
+ return deployedScriptsInfo;
37
+ }
38
+ const contractNames = (0, fs_1.getSubfolders)(folder);
39
+ for (const contractName of contractNames) {
40
+ const folderPath = (0, migration_1.getMigrationFolderPath)(contractName, network); // Replace with your function to get the folder path
41
+ const newestFilePath = (0, migration_1.getNewestMigrationFile)(folderPath);
42
+ if (newestFilePath) {
43
+ try {
44
+ // Read the file content
45
+ const recipe = (0, migration_1.readDeploymentRecipeJsonFile)(newestFilePath);
46
+ // todo: handle multiple cell recipes?
47
+ const firstCell = recipe.cellRecipes[0];
48
+ const isDepCode = recipe.depGroupRecipes.length > 0;
49
+ deployedScriptsInfo[firstCell.name] = {
50
+ codeHash: (firstCell.typeId ? firstCell.typeId : firstCell.dataHash),
51
+ hashType: firstCell.typeId ? 'type' : 'data1',
52
+ cellDeps: !isDepCode
53
+ ? [
54
+ {
55
+ cellDep: {
56
+ outPoint: {
57
+ txHash: firstCell.txHash,
58
+ index: +firstCell.index,
59
+ },
60
+ depType: 'code',
61
+ },
62
+ },
63
+ ]
64
+ : recipe.depGroupRecipes.map((depGroupRecipe) => {
65
+ return {
66
+ cellDep: {
67
+ outPoint: {
68
+ txHash: depGroupRecipe.txHash,
69
+ index: +depGroupRecipe.index,
70
+ },
71
+ depType: 'depGroup',
72
+ },
73
+ };
74
+ }),
75
+ };
76
+ }
77
+ catch (error) {
78
+ console.error(`Error reading or parsing file '${newestFilePath}':`, error);
79
+ }
80
+ }
81
+ }
82
+ return deployedScriptsInfo;
83
+ }
84
+ exports.readUserDeployedScriptsInfo = readUserDeployedScriptsInfo;
@@ -0,0 +1,4 @@
1
+ export declare class OffCKBConfigFile {
2
+ static updateVersion(version: string, filePath: string): void;
3
+ static readContractInfoFolder(filePath: string): string | null;
4
+ }
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.OffCKBConfigFile = void 0;
30
+ const fs = __importStar(require("fs"));
31
+ const path_1 = __importDefault(require("path"));
32
+ const fs_1 = require("../util/fs");
33
+ class OffCKBConfigFile {
34
+ static updateVersion(version, filePath) {
35
+ const versionTarget = '@offckb-update-version';
36
+ let fileContent = fs.readFileSync(filePath, 'utf-8');
37
+ fileContent = fileContent.replace(versionTarget, version);
38
+ // Write the updated content back to the file
39
+ fs.writeFileSync(filePath, fileContent, 'utf-8');
40
+ }
41
+ static readContractInfoFolder(filePath) {
42
+ // Read the contents of the TS file
43
+ const fileContents = fs.readFileSync(filePath, 'utf8');
44
+ // Use a regular expression to find the version value
45
+ const match = fileContents.match(/contractInfoFolder:\s*['"]([^'"]+)['"]/);
46
+ if (match && match[1]) {
47
+ const contractInfoFolderValue = match[1];
48
+ const folderPath = path_1.default.dirname(filePath);
49
+ const contractInfoFolder = (0, fs_1.isAbsolutePath)(contractInfoFolderValue)
50
+ ? contractInfoFolderValue
51
+ : path_1.default.resolve(folderPath, contractInfoFolderValue);
52
+ return contractInfoFolder;
53
+ }
54
+ else {
55
+ console.log('contractBinFolder value not found in offckb.config.ts');
56
+ return null;
57
+ }
58
+ }
59
+ }
60
+ exports.OffCKBConfigFile = OffCKBConfigFile;
@@ -0,0 +1,69 @@
1
+ export type Network = 'devnet' | 'testnet' | 'mainnet';
2
+ export type AddressPrefix = 'ckb' | 'ckt';
3
+ export declare enum SystemScriptName {
4
+ secp256k1_blake160_sighash_all = "secp256k1_blake160_sighash_all",
5
+ secp256k1_blake160_multisig_all = "secp256k1_blake160_multisig_all",
6
+ dao = "dao",
7
+ sudt = "sudt",
8
+ xudt = "xudt",
9
+ omnilock = "omnilock",
10
+ anyone_can_pay = "anyone_can_pay",
11
+ always_success = "always_success",
12
+ spore = "spore",
13
+ spore_cluster = "spore_cluster",
14
+ spore_cluster_agent = "spore_cluster_agent",
15
+ spore_cluster_proxy = "spore_cluster_proxy",
16
+ spore_extension_lua = "spore_extension_lua"
17
+ }
18
+ export interface ScriptInfo {
19
+ codeHash: `0x${string}`;
20
+ hashType: 'type' | 'data';
21
+ cellDeps: {
22
+ cellDep: {
23
+ outPoint: {
24
+ txHash: `0x${string}`;
25
+ index: number;
26
+ };
27
+ depType: 'code' | 'dep_group';
28
+ };
29
+ }[];
30
+ }
31
+ export interface SystemScript {
32
+ name: string;
33
+ file?: string;
34
+ script: ScriptInfo;
35
+ }
36
+ export type SystemScriptsRecord = Record<SystemScriptName, SystemScript | undefined>;
37
+ export interface NetworkSystemScripts {
38
+ devnet: SystemScriptsRecord;
39
+ testnet: SystemScriptsRecord;
40
+ mainnet: SystemScriptsRecord;
41
+ }
42
+ export type MyScriptsRecord = Record<string, ScriptInfo | undefined>;
43
+ export interface NetworkMyScripts {
44
+ devnet: MyScriptsRecord;
45
+ testnet: MyScriptsRecord;
46
+ mainnet: MyScriptsRecord;
47
+ }
48
+ export interface NetworkConfig {
49
+ rpc_url: string;
50
+ addressPrefix: AddressPrefix;
51
+ }
52
+ export interface OffCKBConfig {
53
+ readonly version: string;
54
+ readonly contractBinFolder: string;
55
+ readonly contractInfoFolder: string;
56
+ readonly networks: {
57
+ devnet: NetworkConfig;
58
+ testnet: NetworkConfig;
59
+ mainnet: NetworkConfig;
60
+ };
61
+ readonly currentNetwork: Network;
62
+ readonly addressPrefix: AddressPrefix;
63
+ readonly rpcUrl: string;
64
+ readonly systemScripts: SystemScriptsRecord;
65
+ readonly myScripts: MyScriptsRecord;
66
+ }
67
+ export declare function readEnvNetwork(): Network;
68
+ declare const offCKBConfig: OffCKBConfig;
69
+ export default offCKBConfig;
@@ -0,0 +1,79 @@
1
+ "use strict";
2
+ // this file is generated by offckb-cli
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.readEnvNetwork = exports.SystemScriptName = void 0;
5
+ var SystemScriptName;
6
+ (function (SystemScriptName) {
7
+ SystemScriptName["secp256k1_blake160_sighash_all"] = "secp256k1_blake160_sighash_all";
8
+ SystemScriptName["secp256k1_blake160_multisig_all"] = "secp256k1_blake160_multisig_all";
9
+ SystemScriptName["dao"] = "dao";
10
+ SystemScriptName["sudt"] = "sudt";
11
+ SystemScriptName["xudt"] = "xudt";
12
+ SystemScriptName["omnilock"] = "omnilock";
13
+ SystemScriptName["anyone_can_pay"] = "anyone_can_pay";
14
+ SystemScriptName["always_success"] = "always_success";
15
+ SystemScriptName["spore"] = "spore";
16
+ SystemScriptName["spore_cluster"] = "spore_cluster";
17
+ SystemScriptName["spore_cluster_agent"] = "spore_cluster_agent";
18
+ SystemScriptName["spore_cluster_proxy"] = "spore_cluster_proxy";
19
+ SystemScriptName["spore_extension_lua"] = "spore_extension_lua";
20
+ })(SystemScriptName || (exports.SystemScriptName = SystemScriptName = {}));
21
+ function readEnvNetwork() {
22
+ // you may need to update the env method
23
+ // according to your frontend framework
24
+ const network = process.env.NETWORK;
25
+ const defaultNetwork = 'devnet';
26
+ if (!network)
27
+ return defaultNetwork;
28
+ if (!['devnet', 'testnet', 'mainnet'].includes(network)) {
29
+ return defaultNetwork;
30
+ }
31
+ return network;
32
+ }
33
+ exports.readEnvNetwork = readEnvNetwork;
34
+ const offCKBConfig = {
35
+ version: '@offckb-update-version',
36
+ contractBinFolder: '../build/release',
37
+ // this folder record the script deployment information
38
+ // If you change this folder, you need to update the following get systemScripts and get myScripts method
39
+ contractInfoFolder: './offckb',
40
+ networks: {
41
+ devnet: {
42
+ rpc_url: 'http://127.0.0.1:8114',
43
+ addressPrefix: 'ckt',
44
+ },
45
+ testnet: {
46
+ rpc_url: 'https://testnet.ckb.dev/rpc',
47
+ addressPrefix: 'ckt',
48
+ },
49
+ mainnet: {
50
+ rpc_url: 'https://mainnet.ckb.dev/rpc',
51
+ addressPrefix: 'ckb',
52
+ },
53
+ },
54
+ get currentNetwork() {
55
+ const network = readEnvNetwork();
56
+ return network;
57
+ },
58
+ get addressPrefix() {
59
+ const network = readEnvNetwork();
60
+ return this.networks[network].addressPrefix;
61
+ },
62
+ get rpcUrl() {
63
+ const network = readEnvNetwork();
64
+ return this.networks[network].rpc_url;
65
+ },
66
+ get systemScripts() {
67
+ const network = readEnvNetwork();
68
+ const networkSystemScripts = require('./offckb/system-scripts.json');
69
+ const systemScripts = networkSystemScripts[network];
70
+ return systemScripts;
71
+ },
72
+ get myScripts() {
73
+ const network = readEnvNetwork();
74
+ const networkMyScripts = require('./offckb/my-scripts.json');
75
+ const myScripts = networkMyScripts[network];
76
+ return myScripts;
77
+ },
78
+ };
79
+ exports.default = offCKBConfig;
@@ -4,8 +4,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadBareTemplateOpts = void 0;
7
- const template_json_1 = __importDefault(require("../../templates/template.json"));
7
+ const option_json_1 = __importDefault(require("./option.json"));
8
8
  function loadBareTemplateOpts() {
9
- return template_json_1.default;
9
+ return option_json_1.default;
10
10
  }
11
11
  exports.loadBareTemplateOpts = loadBareTemplateOpts;
@@ -0,0 +1,16 @@
1
+ [
2
+ {
3
+ "name": "Remix-Vite Bare Templates",
4
+ "value": "remix-vite-template",
5
+ "description": "A full-stack template with Remix-vite and ckb-script-templates",
6
+ "tag": ["remix", "vite", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
7
+ "author": "retric@cryptape.com"
8
+ },
9
+ {
10
+ "name": "Next.js Bare Templates",
11
+ "value": "next-js-template",
12
+ "description": "A full-stack template with Next.js framework and ckb-script-templates",
13
+ "tag": ["next.js", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
14
+ "author": "retric@cryptape.com"
15
+ }
16
+ ]
@@ -0,0 +1,12 @@
1
+ export interface DebugOption {
2
+ fullTxJsonFilePath: string;
3
+ cellIndex: number;
4
+ cellType: 'output' | 'input';
5
+ scriptGroupType: 'lock' | 'type';
6
+ }
7
+ export declare class CKBDebugger {
8
+ static runRaw(options: string): void;
9
+ static runTxCellScript({ fullTxJsonFilePath, cellIndex, cellType, scriptGroupType }: DebugOption): void;
10
+ static isBinaryInstalled(): boolean;
11
+ static installCKBDebugger(): void;
12
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CKBDebugger = void 0;
4
+ const child_process_1 = require("child_process");
5
+ class CKBDebugger {
6
+ static runRaw(options) {
7
+ const command = `ckb-debugger ${options}`;
8
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
9
+ }
10
+ static runTxCellScript({ fullTxJsonFilePath, cellIndex, cellType, scriptGroupType }) {
11
+ const command = `ckb-debugger --tx-file ${fullTxJsonFilePath} --cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptGroupType}`;
12
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
13
+ }
14
+ static isBinaryInstalled() {
15
+ const result = (0, child_process_1.spawnSync)('ckb-debugger', ['--version'], { stdio: 'ignore' });
16
+ return result.status === 0;
17
+ }
18
+ static installCKBDebugger() {
19
+ const command = `cargo install --git https://github.com/nervosnetwork/ckb-standalone-debugger ckb-debugger`;
20
+ try {
21
+ console.log('Installing ckb-debugger...');
22
+ (0, child_process_1.execSync)(command);
23
+ console.log('ckb-debugger installed successfully.');
24
+ }
25
+ catch (error) {
26
+ console.error('Failed to install ckb-debugger:', error);
27
+ process.exit(1);
28
+ }
29
+ }
30
+ }
31
+ exports.CKBDebugger = CKBDebugger;
@@ -0,0 +1,6 @@
1
+ export interface DumpOption {
2
+ rpc: string;
3
+ txJsonFilePath: string;
4
+ outputFilePath: string;
5
+ }
6
+ export declare function dumpTransaction({ rpc, txJsonFilePath, outputFilePath }: DumpOption): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.dumpTransaction = void 0;
7
+ const path_1 = __importDefault(require("path"));
8
+ const child_process_1 = require("child_process");
9
+ const setting_1 = require("../cfg/setting");
10
+ function dumpTransaction({ rpc, txJsonFilePath, outputFilePath }) {
11
+ const ckbTransactionDumperPath = path_1.default.resolve(setting_1.packageRootPath, 'node_modules/.bin/ckb-transaction-dumper');
12
+ const command = `${ckbTransactionDumperPath} --rpc ${rpc} --tx "${txJsonFilePath}" --output "${outputFilePath}"`;
13
+ try {
14
+ (0, child_process_1.execSync)(command, { stdio: 'inherit' });
15
+ console.debug('Dump transaction successfully');
16
+ }
17
+ catch (error) {
18
+ console.error('Command failed:', error.message);
19
+ }
20
+ }
21
+ exports.dumpTransaction = dumpTransaction;
@@ -0,0 +1,9 @@
1
+ /// <reference types="node" />
2
+ import http from 'http';
3
+ import { Network } from '../util/type';
4
+ export declare function createRPCProxy(network: Network, targetRpcUrl: string, port: number): {
5
+ server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
6
+ network: Network;
7
+ start: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
8
+ stop: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
9
+ };
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.createRPCProxy = void 0;
7
+ const http_proxy_1 = __importDefault(require("http-proxy"));
8
+ const http_1 = __importDefault(require("http"));
9
+ const type_1 = require("../util/type");
10
+ const fs_1 = __importDefault(require("fs"));
11
+ const setting_1 = require("../cfg/setting");
12
+ const path_1 = __importDefault(require("path"));
13
+ // todo: if we use import this throws error in tsc building
14
+ const { cccA } = require('@ckb-ccc/core/advanced');
15
+ function createRPCProxy(network, targetRpcUrl, port) {
16
+ const proxy = http_proxy_1.default.createProxyServer({
17
+ target: targetRpcUrl, // Target RPC server
18
+ });
19
+ const server = http_1.default.createServer((req, res) => {
20
+ proxy.web(req, res, {}, (err) => {
21
+ if (err) {
22
+ console.error('Proxy error:', err);
23
+ res.writeHead(500, { 'Content-Type': 'text/plain' });
24
+ res.end('Proxy error');
25
+ }
26
+ });
27
+ proxy.on('proxyReq', (_, req) => {
28
+ let reqData = '';
29
+ req.on('data', (chunk) => {
30
+ reqData += chunk;
31
+ });
32
+ req.on('end', () => {
33
+ try {
34
+ const jsonRpcContent = JSON.parse(reqData);
35
+ console.debug('Incoming Request: ', jsonRpcContent);
36
+ const method = jsonRpcContent.method;
37
+ const params = jsonRpcContent.params;
38
+ if (method === 'send_transaction') {
39
+ const tx = params[0];
40
+ // todo: record tx
41
+ if (network === type_1.Network.devnet) {
42
+ const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
43
+ const txHash = cccTx.hash();
44
+ const settings = (0, setting_1.readSettings)();
45
+ console.log('txHash: ', txHash, settings, settings.devnet.transactionsPath);
46
+ if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
47
+ fs_1.default.mkdirSync(settings.devnet.transactionsPath);
48
+ }
49
+ const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
50
+ fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
51
+ }
52
+ }
53
+ }
54
+ catch (err) {
55
+ console.error('Error parsing JSON-RPC content:', err);
56
+ }
57
+ });
58
+ });
59
+ // Capture the content from the response (or request)
60
+ proxy.on('proxyRes', (proxyRes) => {
61
+ let data = '';
62
+ proxyRes.on('data', (chunk) => {
63
+ data += chunk;
64
+ });
65
+ proxyRes.on('end', () => {
66
+ console.log('Captured content:', data);
67
+ // Do something with the captured content
68
+ });
69
+ });
70
+ });
71
+ return {
72
+ server,
73
+ network,
74
+ start: () => {
75
+ return server.listen(port, () => {
76
+ console.debug(`CKB ${network} RPC Proxy server running on http://localhost:${port}`);
77
+ });
78
+ },
79
+ stop: () => {
80
+ return server.close();
81
+ },
82
+ };
83
+ }
84
+ exports.createRPCProxy = createRPCProxy;
@@ -69,7 +69,7 @@ export declare class CKB {
69
69
  };
70
70
  XUDT: {
71
71
  CODE_HASH: string;
72
- HASH_TYPE: "data1";
72
+ HASH_TYPE: "type";
73
73
  TX_HASH: string;
74
74
  INDEX: string;
75
75
  DEP_TYPE: "code";
@@ -125,7 +125,7 @@ export declare class CKB {
125
125
  };
126
126
  XUDT: {
127
127
  CODE_HASH: string;
128
- HASH_TYPE: "type";
128
+ HASH_TYPE: "data1";
129
129
  TX_HASH: string;
130
130
  INDEX: string;
131
131
  DEP_TYPE: "code";
@@ -137,4 +137,5 @@ export declare class CKB {
137
137
  transfer(options: Options, lumosConfig: config.Config): Promise<string>;
138
138
  transferAll(privateKey: string, toAddress: string, lumosConfig: config.Config): Promise<string>;
139
139
  }
140
+ export declare function readPredefinedDevnetLumosConfig(): config.Config;
140
141
  export {};
package/dist/util/ckb.js CHANGED
@@ -16,13 +16,13 @@ var __asyncValues = (this && this.__asyncValues) || function (o) {
16
16
  function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
17
17
  };
18
18
  Object.defineProperty(exports, "__esModule", { value: true });
19
- exports.CKB = void 0;
19
+ exports.readPredefinedDevnetLumosConfig = exports.CKB = void 0;
20
20
  const lumos_1 = require("@ckb-lumos/lumos");
21
21
  const base_1 = require("@ckb-lumos/base");
22
22
  const codec_1 = require("@ckb-lumos/codec");
23
- const config_1 = require("./config");
24
23
  const validator_1 = require("./validator");
25
24
  const type_1 = require("./type");
25
+ const system_scripts_1 = require("../cmd/system-scripts");
26
26
  const { ScriptValue } = base_1.values;
27
27
  const networks = {
28
28
  devnet: {
@@ -70,7 +70,7 @@ class CKB {
70
70
  }
71
71
  getLumosConfig() {
72
72
  if (this.network === type_1.Network.devnet) {
73
- return (0, config_1.readPredefinedDevnetLumosConfig)();
73
+ return readPredefinedDevnetLumosConfig();
74
74
  }
75
75
  if (this.network === type_1.Network.testnet) {
76
76
  return lumos_1.config.predefined.AGGRON4;
@@ -297,3 +297,16 @@ class CKB {
297
297
  }
298
298
  }
299
299
  exports.CKB = CKB;
300
+ function readPredefinedDevnetLumosConfig() {
301
+ try {
302
+ const systemScripts = (0, system_scripts_1.getSystemScriptsFromListHashes)();
303
+ if (systemScripts) {
304
+ return (0, system_scripts_1.toLumosConfig)(systemScripts);
305
+ }
306
+ throw new Error('systemScripts not found!');
307
+ }
308
+ catch (error) {
309
+ throw new Error('getSystemScriptsFromListHashes error' + error.message);
310
+ }
311
+ }
312
+ exports.readPredefinedDevnetLumosConfig = readPredefinedDevnetLumosConfig;
@@ -1 +1,2 @@
1
1
  export declare function setUTF8EncodingForWindows(): void;
2
+ export declare function encodeBinPathForTerminal(path: string): string;
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.setUTF8EncodingForWindows = void 0;
6
+ exports.encodeBinPathForTerminal = exports.setUTF8EncodingForWindows = void 0;
7
7
  const child_process_1 = require("child_process");
8
8
  const os_1 = __importDefault(require("os"));
9
9
  function setUTF8EncodingForWindows() {
@@ -17,3 +17,9 @@ function setUTF8EncodingForWindows() {
17
17
  }
18
18
  }
19
19
  exports.setUTF8EncodingForWindows = setUTF8EncodingForWindows;
20
+ function encodeBinPathForTerminal(path) {
21
+ // some path contains space in the string
22
+ // this fix the space in the terminal
23
+ return `"${path}"`;
24
+ }
25
+ exports.encodeBinPathForTerminal = encodeBinPathForTerminal;
package/dist/util/fs.d.ts CHANGED
@@ -3,10 +3,9 @@ export declare function copyFolderSync(source: string, destination: string): voi
3
3
  export declare function copyFileSync(source: string, target: string): void;
4
4
  export declare function copyFilesWithExclusion(sourceDir: string, destinationDir: string, excludedFolders: string[]): Promise<void>;
5
5
  export declare function copyRecursive(source: string, destination: string, excludedFolders: string[]): Promise<void>;
6
- export declare function updateVersionInTSFile(newVersion: string, filePath: string): void;
7
6
  export declare function readFileToUint8Array(filePath: string): Promise<Uint8Array>;
8
- export declare function convertFilenameToUppercase(filePath: string): string;
9
7
  export declare function listBinaryFilesInFolder(folderPath: string): string[];
10
8
  export declare function isBinaryFile(filePath: string): boolean;
11
9
  export declare function isAbsolutePath(filePath: string): boolean;
12
10
  export declare function findFileInFolder(folderPath: string, fileName: string): string | null;
11
+ export declare function getSubfolders(folderPath: string): string[];