@offckb/cli 0.2.7 → 0.3.0-canary-cfe9b48.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 +81 -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,42 @@
1
+ import { config } from '@ckb-lumos/lumos';
2
+ import { SystemCell } from './list-hashes';
3
+ import { CellDepInfoLike, Script } from '@ckb-ccc/core';
4
+ import { SystemScriptsRecord } from '../scripts/type';
5
+ export type PrintProps = 'lumos' | 'ccc';
6
+ export declare function printSystemScripts(props?: PrintProps): Promise<void>;
7
+ export declare function printInSystemStyle(systemScripts: SystemScriptsRecord): void;
8
+ export declare function printInLumosConfigStyle(scripts: SystemScriptsRecord): void;
9
+ export declare function printInCCCStyle(scripts: SystemScriptsRecord): void;
10
+ export declare function getSystemScriptsFromListHashes(): SystemScriptsRecord | null;
11
+ export declare function systemCellToScriptInfo(cell: SystemCell, depType: 'code' | 'depGroup', depGroup?: {
12
+ txHash: string;
13
+ index: number;
14
+ }): {
15
+ codeHash: string;
16
+ hashType: string;
17
+ cellDeps: {
18
+ cellDep: {
19
+ outPoint: {
20
+ txHash: string;
21
+ index: number;
22
+ };
23
+ depType: "code";
24
+ };
25
+ }[];
26
+ } | {
27
+ codeHash: string;
28
+ hashType: string;
29
+ cellDeps: {
30
+ cellDep: {
31
+ outPoint: {
32
+ txHash: string;
33
+ index: number;
34
+ };
35
+ depType: "depGroup";
36
+ };
37
+ }[];
38
+ };
39
+ export declare function toLumosConfig(scripts: SystemScriptsRecord, addressPrefix?: 'ckb' | 'ckt'): config.Config;
40
+ export declare function toCCCKnownScripts(scripts: SystemScriptsRecord): Record<string, Pick<Script, "codeHash" | "hashType"> & {
41
+ cellDeps: CellDepInfoLike[];
42
+ }>;
@@ -0,0 +1,265 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.toCCCKnownScripts = exports.toLumosConfig = exports.systemCellToScriptInfo = exports.getSystemScriptsFromListHashes = exports.printInCCCStyle = exports.printInLumosConfigStyle = exports.printInSystemStyle = exports.printSystemScripts = void 0;
16
+ const setting_1 = require("../cfg/setting");
17
+ const list_hashes_1 = require("./list-hashes");
18
+ const toml_1 = __importDefault(require("@iarna/toml"));
19
+ const core_1 = require("@ckb-ccc/core");
20
+ function printSystemScripts(props) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const systemScripts = getSystemScriptsFromListHashes();
23
+ if (systemScripts) {
24
+ if (!props) {
25
+ return printInSystemStyle(systemScripts);
26
+ }
27
+ if (props === 'lumos') {
28
+ return printInLumosConfigStyle(systemScripts);
29
+ }
30
+ if (props === 'ccc') {
31
+ return printInCCCStyle(systemScripts);
32
+ }
33
+ }
34
+ });
35
+ }
36
+ exports.printSystemScripts = printSystemScripts;
37
+ function printInSystemStyle(systemScripts) {
38
+ console.log('*** OffCKB Devnet System Scripts ***\n');
39
+ for (const [name, script] of Object.entries(systemScripts)) {
40
+ console.log(`- name: ${name}`);
41
+ if (script == null) {
42
+ return console.log(` undefined\n`);
43
+ }
44
+ console.log(` file: ${script.file}`);
45
+ console.log(` code_hash: ${script.script.codeHash}`);
46
+ console.log(` hash_type: ${script.script.hashType}`);
47
+ console.log(` cellDeps: ${JSON.stringify(script.script.cellDeps, null, 2)}\n`);
48
+ }
49
+ }
50
+ exports.printInSystemStyle = printInSystemStyle;
51
+ function printInLumosConfigStyle(scripts) {
52
+ const config = toLumosConfig(scripts);
53
+ console.log('*** OffCKB Devnet System Scripts As LumosConfig ***\n');
54
+ console.log(JSON.stringify(config, null, 2));
55
+ }
56
+ exports.printInLumosConfigStyle = printInLumosConfigStyle;
57
+ function printInCCCStyle(scripts) {
58
+ const knownsScripts = toCCCKnownScripts(scripts);
59
+ console.log('*** OffCKB Devnet System Scripts As CCC KnownScripts ***\n');
60
+ console.log(JSON.stringify(knownsScripts, null, 2));
61
+ }
62
+ exports.printInCCCStyle = printInCCCStyle;
63
+ function getSystemScriptsFromListHashes() {
64
+ const settings = (0, setting_1.readSettings)();
65
+ const listHashesString = (0, list_hashes_1.getListHashes)(settings.bins.defaultCKBVersion);
66
+ if (listHashesString) {
67
+ const listHashes = toml_1.default.parse(listHashesString);
68
+ const systemScriptArray = listHashes.offckb.system_cells
69
+ .map((cell) => {
70
+ var _a;
71
+ // Extract the file name
72
+ const name = ((_a = cell.path.split('/').pop()) === null || _a === void 0 ? void 0 : _a.replace(')', '')) || 'unknown script';
73
+ const depGroupIndex = listHashes.offckb.dep_groups.findIndex((depGroup) => depGroup.included_cells.includes(`Bundled(specs/cells/${name})`));
74
+ const depType = depGroupIndex === -1 ? 'code' : 'depGroup';
75
+ const depGroup = depGroupIndex === -1
76
+ ? undefined
77
+ : {
78
+ txHash: listHashes.offckb.dep_groups[depGroupIndex].tx_hash,
79
+ index: listHashes.offckb.dep_groups[depGroupIndex].index,
80
+ };
81
+ const scriptInfo = systemCellToScriptInfo(cell, depType, depGroup);
82
+ return {
83
+ name,
84
+ file: cell.path,
85
+ script: scriptInfo,
86
+ };
87
+ })
88
+ .filter((s) => s.name != 'secp256k1_data');
89
+ const systemScripts = systemScriptArray.reduce((acc, item) => {
90
+ const key = item.name;
91
+ acc[key] = item;
92
+ return acc;
93
+ }, {});
94
+ return systemScripts;
95
+ }
96
+ else {
97
+ console.log(`list-hashes not found!`);
98
+ return null;
99
+ }
100
+ }
101
+ exports.getSystemScriptsFromListHashes = getSystemScriptsFromListHashes;
102
+ function systemCellToScriptInfo(cell, depType, depGroup) {
103
+ if (depType === 'depGroup' && !depGroup) {
104
+ throw new Error('require depGroup info since the dep type is depGroup');
105
+ }
106
+ if (depType === 'code') {
107
+ return {
108
+ codeHash: cell.type_hash || cell.data_hash,
109
+ hashType: cell.type_hash ? 'type' : 'data',
110
+ cellDeps: [
111
+ {
112
+ cellDep: {
113
+ outPoint: {
114
+ txHash: cell.tx_hash,
115
+ index: cell.index,
116
+ },
117
+ depType,
118
+ },
119
+ },
120
+ ],
121
+ };
122
+ }
123
+ return {
124
+ codeHash: cell.type_hash || cell.data_hash,
125
+ hashType: cell.type_hash ? 'type' : 'data',
126
+ cellDeps: [
127
+ {
128
+ cellDep: {
129
+ outPoint: {
130
+ txHash: depGroup.txHash,
131
+ index: depGroup.index,
132
+ },
133
+ depType,
134
+ },
135
+ },
136
+ ],
137
+ };
138
+ }
139
+ exports.systemCellToScriptInfo = systemCellToScriptInfo;
140
+ function toLumosConfig(scripts, addressPrefix = 'ckt') {
141
+ const config = {
142
+ PREFIX: addressPrefix,
143
+ SCRIPTS: {
144
+ SECP256K1_BLAKE160: {
145
+ CODE_HASH: scripts.secp256k1_blake160_sighash_all.script.codeHash,
146
+ HASH_TYPE: scripts.secp256k1_blake160_sighash_all.script.hashType,
147
+ TX_HASH: scripts.secp256k1_blake160_sighash_all.script.cellDeps[0].cellDep.outPoint.txHash,
148
+ INDEX: '0x' + scripts.secp256k1_blake160_sighash_all.script.cellDeps[0].cellDep.outPoint.index.toString(16),
149
+ DEP_TYPE: scripts.secp256k1_blake160_sighash_all.script.cellDeps[0].cellDep.depType,
150
+ SHORT_ID: 1,
151
+ },
152
+ SECP256K1_BLAKE160_MULTISIG: {
153
+ CODE_HASH: scripts.secp256k1_blake160_multisig_all.script.codeHash,
154
+ HASH_TYPE: scripts.secp256k1_blake160_multisig_all.script.hashType,
155
+ TX_HASH: scripts.secp256k1_blake160_multisig_all.script.cellDeps[0].cellDep.outPoint.txHash,
156
+ INDEX: '0x' + scripts.secp256k1_blake160_multisig_all.script.cellDeps[0].cellDep.outPoint.index.toString(16),
157
+ DEP_TYPE: scripts.secp256k1_blake160_multisig_all.script.cellDeps[0].cellDep.depType,
158
+ },
159
+ DAO: {
160
+ CODE_HASH: scripts.dao.script.codeHash,
161
+ HASH_TYPE: scripts.dao.script.hashType,
162
+ TX_HASH: scripts.dao.script.cellDeps[0].cellDep.outPoint.txHash,
163
+ INDEX: '0x' + scripts.dao.script.cellDeps[0].cellDep.outPoint.index.toString(16),
164
+ DEP_TYPE: scripts.dao.script.cellDeps[0].cellDep.depType,
165
+ SHORT_ID: 2,
166
+ },
167
+ SUDT: {
168
+ CODE_HASH: scripts.sudt.script.codeHash,
169
+ HASH_TYPE: scripts.sudt.script.hashType,
170
+ TX_HASH: scripts.sudt.script.cellDeps[0].cellDep.outPoint.txHash,
171
+ INDEX: '0x' + scripts.sudt.script.cellDeps[0].cellDep.outPoint.index.toString(16),
172
+ DEP_TYPE: scripts.sudt.script.cellDeps[0].cellDep.depType,
173
+ },
174
+ XUDT: {
175
+ CODE_HASH: scripts.xudt.script.codeHash,
176
+ HASH_TYPE: scripts.xudt.script.hashType,
177
+ TX_HASH: scripts.xudt.script.cellDeps[0].cellDep.outPoint.txHash,
178
+ INDEX: '0x' + scripts.xudt.script.cellDeps[0].cellDep.outPoint.index.toString(16),
179
+ DEP_TYPE: scripts.xudt.script.cellDeps[0].cellDep.depType,
180
+ },
181
+ OMNILOCK: {
182
+ CODE_HASH: scripts.omnilock.script.codeHash,
183
+ HASH_TYPE: scripts.omnilock.script.hashType,
184
+ TX_HASH: scripts.omnilock.script.cellDeps[0].cellDep.outPoint.txHash,
185
+ INDEX: '0x' + scripts.omnilock.script.cellDeps[0].cellDep.outPoint.index.toString(16),
186
+ DEP_TYPE: scripts.omnilock.script.cellDeps[0].cellDep.depType,
187
+ },
188
+ ANYONE_CAN_PAY: {
189
+ CODE_HASH: scripts.anyone_can_pay.script.codeHash,
190
+ HASH_TYPE: scripts.anyone_can_pay.script.hashType,
191
+ TX_HASH: scripts.anyone_can_pay.script.cellDeps[0].cellDep.outPoint.txHash,
192
+ INDEX: '0x' + scripts.anyone_can_pay.script.cellDeps[0].cellDep.outPoint.index.toString(16),
193
+ DEP_TYPE: scripts.anyone_can_pay.script.cellDeps[0].cellDep.depType,
194
+ },
195
+ SPORE: {
196
+ CODE_HASH: scripts.spore.script.codeHash,
197
+ HASH_TYPE: scripts.spore.script.hashType,
198
+ TX_HASH: scripts.spore.script.cellDeps[0].cellDep.outPoint.txHash,
199
+ INDEX: '0x' + scripts.spore.script.cellDeps[0].cellDep.outPoint.index.toString(16),
200
+ DEP_TYPE: scripts.spore.script.cellDeps[0].cellDep.depType,
201
+ },
202
+ SPORE_CLUSTER: {
203
+ CODE_HASH: scripts.spore_cluster.script.codeHash,
204
+ HASH_TYPE: scripts.spore_cluster.script.hashType,
205
+ TX_HASH: scripts.spore_cluster.script.cellDeps[0].cellDep.outPoint.txHash,
206
+ INDEX: '0x' + scripts.spore_cluster.script.cellDeps[0].cellDep.outPoint.index.toString(16),
207
+ DEP_TYPE: scripts.spore_cluster.script.cellDeps[0].cellDep.depType,
208
+ },
209
+ },
210
+ };
211
+ if (scripts.always_success) {
212
+ config.SCRIPTS['ALWAYS_SUCCESS'] = {
213
+ CODE_HASH: scripts.always_success.script.codeHash,
214
+ HASH_TYPE: scripts.always_success.script.hashType,
215
+ TX_HASH: scripts.always_success.script.cellDeps[0].cellDep.outPoint.txHash,
216
+ INDEX: '0x' + scripts.always_success.script.cellDeps[0].cellDep.outPoint.index.toString(16),
217
+ DEP_TYPE: scripts.always_success.script.cellDeps[0].cellDep.depType,
218
+ };
219
+ }
220
+ if (scripts.spore_cluster_agent) {
221
+ config.SCRIPTS['SPORE_CLUSTER_AGENT'] = {
222
+ CODE_HASH: scripts.spore_cluster_agent.script.codeHash,
223
+ HASH_TYPE: scripts.spore_cluster_agent.script.hashType,
224
+ TX_HASH: scripts.spore_cluster_agent.script.cellDeps[0].cellDep.outPoint.txHash,
225
+ INDEX: '0x' + scripts.spore_cluster_agent.script.cellDeps[0].cellDep.outPoint.index.toString(16),
226
+ DEP_TYPE: scripts.spore_cluster_agent.script.cellDeps[0].cellDep.depType,
227
+ };
228
+ }
229
+ if (scripts.spore_cluster_proxy) {
230
+ config.SCRIPTS['SPORE_CLUSTER_PROXY'] = {
231
+ CODE_HASH: scripts.spore_cluster_proxy.script.codeHash,
232
+ HASH_TYPE: scripts.spore_cluster_proxy.script.hashType,
233
+ TX_HASH: scripts.spore_cluster_proxy.script.cellDeps[0].cellDep.outPoint.txHash,
234
+ INDEX: '0x' + scripts.spore_cluster_proxy.script.cellDeps[0].cellDep.outPoint.index.toString(16),
235
+ DEP_TYPE: scripts.spore_cluster_proxy.script.cellDeps[0].cellDep.depType,
236
+ };
237
+ }
238
+ if (scripts.spore_extension_lua) {
239
+ config.SCRIPTS['SPORE_LUA'] = {
240
+ CODE_HASH: scripts.spore_extension_lua.script.codeHash,
241
+ HASH_TYPE: scripts.spore_extension_lua.script.hashType,
242
+ TX_HASH: scripts.spore_extension_lua.script.cellDeps[0].cellDep.outPoint.txHash,
243
+ INDEX: '0x' + scripts.spore_extension_lua.script.cellDeps[0].cellDep.outPoint.index.toString(16),
244
+ DEP_TYPE: scripts.spore_extension_lua.script.cellDeps[0].cellDep.depType,
245
+ };
246
+ }
247
+ return config;
248
+ }
249
+ exports.toLumosConfig = toLumosConfig;
250
+ function toCCCKnownScripts(scripts) {
251
+ const DEVNET_SCRIPTS = {
252
+ [core_1.KnownScript.Secp256k1Blake160]: scripts.secp256k1_blake160_sighash_all.script,
253
+ [core_1.KnownScript.Secp256k1Multisig]: scripts.secp256k1_blake160_multisig_all.script,
254
+ [core_1.KnownScript.AnyoneCanPay]: scripts.anyone_can_pay.script,
255
+ [core_1.KnownScript.OmniLock]: scripts.omnilock.script,
256
+ [core_1.KnownScript.XUdt]: scripts.xudt.script,
257
+ [core_1.KnownScript.TypeId]: {
258
+ codeHash: '0x00000000000000000000000000000000000000000000000000545950455f4944',
259
+ hashType: 'type',
260
+ cellDeps: [],
261
+ },
262
+ };
263
+ return DEVNET_SCRIPTS;
264
+ }
265
+ exports.toCCCKnownScripts = toCCCKnownScripts;
@@ -0,0 +1,45 @@
1
+ import { HexNumber } from '@ckb-lumos/lumos';
2
+ import { Network } from '../util/type';
3
+ export interface CellRecipe {
4
+ name: string;
5
+ txHash: string;
6
+ index: HexNumber;
7
+ occupiedCapacity: HexNumber;
8
+ dataHash: string;
9
+ typeId?: string;
10
+ }
11
+ export interface DepGroupRecipe {
12
+ name: string;
13
+ txHash: string;
14
+ index: HexNumber;
15
+ dataHash: string;
16
+ occupiedCapacity: HexNumber;
17
+ }
18
+ export interface DeploymentRecipe {
19
+ cellRecipes: CellRecipe[];
20
+ depGroupRecipes: DepGroupRecipe[];
21
+ }
22
+ export interface DeploymentRecipeJson {
23
+ cell_recipes: {
24
+ name: string;
25
+ tx_hash: string;
26
+ index: HexNumber;
27
+ occupied_capacity: HexNumber;
28
+ data_hash: string;
29
+ type_id?: string;
30
+ }[];
31
+ dep_group_recipes: {
32
+ name: string;
33
+ tx_hash: string;
34
+ index: HexNumber;
35
+ data_hash: string;
36
+ occupied_capacity: HexNumber;
37
+ }[];
38
+ }
39
+ export declare function generateDeploymentRecipeJsonFile(name: string, deploymentRecipe: DeploymentRecipe, network?: Network): void;
40
+ export declare function readDeploymentRecipeJsonFile(filePath: string): DeploymentRecipe;
41
+ export declare function getFormattedMigrationDate(): string;
42
+ export declare function getMigrationFolderPath(scriptName: string, network: Network): string;
43
+ export declare function getNewestMigrationFile(folderPath: string): string | undefined;
44
+ export declare function deploymentRecipeToJson(recipe: DeploymentRecipe): DeploymentRecipeJson;
45
+ export declare function deploymentRecipeFromJson(json: DeploymentRecipeJson): DeploymentRecipe;
@@ -0,0 +1,131 @@
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.deploymentRecipeFromJson = exports.deploymentRecipeToJson = exports.getNewestMigrationFile = exports.getMigrationFolderPath = exports.getFormattedMigrationDate = exports.readDeploymentRecipeJsonFile = exports.generateDeploymentRecipeJsonFile = void 0;
30
+ const type_1 = require("../util/type");
31
+ const path_1 = __importStar(require("path"));
32
+ const fs_1 = __importDefault(require("fs"));
33
+ const util_1 = require("./util");
34
+ function generateDeploymentRecipeJsonFile(name, deploymentRecipe, network = type_1.Network.devnet) {
35
+ const cellRecipes = deploymentRecipe.cellRecipes;
36
+ const depGroupRecipes = deploymentRecipe.depGroupRecipes;
37
+ const jsonString = JSON.stringify(deploymentRecipeToJson({ cellRecipes, depGroupRecipes }), null, 2);
38
+ const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${name}/migrations/${getFormattedMigrationDate()}.json`;
39
+ if (outputFilePath) {
40
+ if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
41
+ fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
42
+ }
43
+ fs_1.default.writeFileSync(outputFilePath, jsonString);
44
+ console.log(`${name} migration json file ${outputFilePath} generated successfully.`);
45
+ }
46
+ }
47
+ exports.generateDeploymentRecipeJsonFile = generateDeploymentRecipeJsonFile;
48
+ function readDeploymentRecipeJsonFile(filePath) {
49
+ const jsonString = fs_1.default.readFileSync(filePath, 'utf-8');
50
+ const data = JSON.parse(jsonString);
51
+ return deploymentRecipeFromJson(data);
52
+ }
53
+ exports.readDeploymentRecipeJsonFile = readDeploymentRecipeJsonFile;
54
+ function getFormattedMigrationDate() {
55
+ const now = new Date();
56
+ const year = now.getFullYear();
57
+ const month = String(now.getMonth() + 1).padStart(2, '0'); // Months are zero-based
58
+ const day = String(now.getDate()).padStart(2, '0');
59
+ const hours = String(now.getHours()).padStart(2, '0');
60
+ const minutes = String(now.getMinutes()).padStart(2, '0');
61
+ const seconds = String(now.getSeconds()).padStart(2, '0');
62
+ return `${year}-${month}-${day}-${hours}${minutes}${seconds}`;
63
+ }
64
+ exports.getFormattedMigrationDate = getFormattedMigrationDate;
65
+ function getMigrationFolderPath(scriptName, network) {
66
+ const contractsPath = (0, util_1.getContractsPath)(network);
67
+ return path_1.default.resolve(contractsPath, `${scriptName}/migrations`);
68
+ }
69
+ exports.getMigrationFolderPath = getMigrationFolderPath;
70
+ function getNewestMigrationFile(folderPath) {
71
+ const files = fs_1.default
72
+ .readdirSync(folderPath)
73
+ .filter((file) => file.endsWith('.json')) // Ensure only JSON files are considered
74
+ .sort((a, b) => {
75
+ // Extract the timestamp part of the filename and compare them
76
+ const timestampA = a.split('.json')[0];
77
+ const timestampB = b.split('.json')[0];
78
+ return timestampA.localeCompare(timestampB);
79
+ });
80
+ // Return the full path of the newest file (last in sorted array) or undefined if no files
81
+ return files.length > 0 ? path_1.default.join(folderPath, files[files.length - 1]) : undefined;
82
+ }
83
+ exports.getNewestMigrationFile = getNewestMigrationFile;
84
+ function deploymentRecipeToJson(recipe) {
85
+ return {
86
+ cell_recipes: recipe.cellRecipes.map((val) => {
87
+ return {
88
+ name: val.name,
89
+ tx_hash: val.txHash,
90
+ index: val.index,
91
+ occupied_capacity: val.occupiedCapacity,
92
+ data_hash: val.dataHash,
93
+ type_id: val.typeId,
94
+ };
95
+ }),
96
+ dep_group_recipes: recipe.depGroupRecipes.map((val) => {
97
+ return {
98
+ name: val.name,
99
+ tx_hash: val.txHash,
100
+ index: val.index,
101
+ data_hash: val.dataHash,
102
+ occupied_capacity: val.occupiedCapacity,
103
+ };
104
+ }),
105
+ };
106
+ }
107
+ exports.deploymentRecipeToJson = deploymentRecipeToJson;
108
+ function deploymentRecipeFromJson(json) {
109
+ return {
110
+ cellRecipes: json.cell_recipes.map((val) => {
111
+ return {
112
+ name: val.name,
113
+ txHash: val.tx_hash,
114
+ index: val.index,
115
+ occupiedCapacity: val.occupied_capacity,
116
+ dataHash: val.data_hash,
117
+ typeId: val.type_id,
118
+ };
119
+ }),
120
+ depGroupRecipes: json.dep_group_recipes.map((val) => {
121
+ return {
122
+ name: val.name,
123
+ txHash: val.tx_hash,
124
+ index: val.index,
125
+ dataHash: val.data_hash,
126
+ occupiedCapacity: val.occupied_capacity,
127
+ };
128
+ }),
129
+ };
130
+ }
131
+ exports.deploymentRecipeFromJson = deploymentRecipeFromJson;
@@ -0,0 +1,38 @@
1
+ import { Script } from '@ckb-lumos/lumos';
2
+ import { Network } from '../util/type';
3
+ import { HashType } from '@ckb-ccc/core';
4
+ export interface DeploymentOptions {
5
+ name: string;
6
+ binFilePath: string;
7
+ enableTypeId: boolean;
8
+ lockScript: Script;
9
+ }
10
+ export interface DeploymentToml {
11
+ cells: {
12
+ name: string;
13
+ enable_type_id: 'true' | 'false';
14
+ location: {
15
+ file: string;
16
+ };
17
+ }[];
18
+ lock: {
19
+ code_hash: string;
20
+ args: string;
21
+ hash_type: HashType;
22
+ };
23
+ }
24
+ export declare function generateDeploymentToml(options: DeploymentOptions, network: Network): void;
25
+ export declare function readDeploymentToml(scriptName: string, network: Network): {
26
+ cells: {
27
+ name: string;
28
+ enableTypeId: boolean;
29
+ location: {
30
+ file: string;
31
+ };
32
+ }[];
33
+ lock: {
34
+ codeHash: string;
35
+ args: string;
36
+ hashType: string;
37
+ };
38
+ };
@@ -0,0 +1,60 @@
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.readDeploymentToml = exports.generateDeploymentToml = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const toml_1 = __importDefault(require("@iarna/toml"));
9
+ const path_1 = require("path");
10
+ const util_1 = require("./util");
11
+ function generateDeploymentToml(options, network) {
12
+ const data = {
13
+ cells: [
14
+ {
15
+ name: options.name,
16
+ enable_type_id: options.enableTypeId ? 'true' : 'false',
17
+ location: {
18
+ file: options.binFilePath,
19
+ },
20
+ },
21
+ ],
22
+ lock: {
23
+ code_hash: options.lockScript.codeHash,
24
+ args: options.lockScript.args,
25
+ hash_type: options.lockScript.hashType,
26
+ },
27
+ };
28
+ const tomlString = toml_1.default.stringify(data);
29
+ const outputFilePath = `${(0, util_1.getContractsPath)(network)}/${options.name}/deployment.toml`;
30
+ if (outputFilePath) {
31
+ if (!fs_1.default.existsSync((0, path_1.dirname)(outputFilePath))) {
32
+ fs_1.default.mkdirSync((0, path_1.dirname)(outputFilePath), { recursive: true });
33
+ }
34
+ fs_1.default.writeFileSync(outputFilePath, tomlString);
35
+ console.log(`${options.name} deployment.toml file ${outputFilePath} generated successfully.`);
36
+ }
37
+ }
38
+ exports.generateDeploymentToml = generateDeploymentToml;
39
+ function readDeploymentToml(scriptName, network) {
40
+ const filePath = `${(0, util_1.getContractsPath)(network)}/${scriptName}/deployment.toml`;
41
+ const file = fs_1.default.readFileSync(filePath, 'utf-8');
42
+ const data = toml_1.default.parse(file);
43
+ return {
44
+ cells: [
45
+ {
46
+ name: data.cells[0].name,
47
+ enableTypeId: data.cells[0].enable_type_id === 'true' ? true : false,
48
+ location: {
49
+ file: data.cells[0].location.file,
50
+ },
51
+ },
52
+ ],
53
+ lock: {
54
+ codeHash: data.lock.code_hash,
55
+ args: data.lock.args,
56
+ hashType: data.lock.hash_type,
57
+ },
58
+ };
59
+ }
60
+ exports.readDeploymentToml = readDeploymentToml;
@@ -0,0 +1,2 @@
1
+ import { Network } from '../util/type';
2
+ export declare function getContractsPath(network: Network): string;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getContractsPath = void 0;
4
+ const setting_1 = require("../cfg/setting");
5
+ const type_1 = require("../util/type");
6
+ function getContractsPath(network) {
7
+ const settings = (0, setting_1.readSettings)();
8
+ if (network === type_1.Network.devnet) {
9
+ return settings.devnet.contractsPath;
10
+ }
11
+ if (network === type_1.Network.testnet) {
12
+ return settings.testnet.contractsPath;
13
+ }
14
+ if (network === type_1.Network.mainnet) {
15
+ return settings.mainnet.contractsPath;
16
+ }
17
+ throw new Error(`invalid network ${network}`);
18
+ }
19
+ exports.getContractsPath = getContractsPath;
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ exports.initChainIfNeeded = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
17
+ const path_1 = __importDefault(require("path"));
18
+ const fs_2 = require("../util/fs");
19
+ const setting_1 = require("../cfg/setting");
20
+ function initChainIfNeeded() {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ const settings = (0, setting_1.readSettings)();
23
+ const devnetSourcePath = path_1.default.resolve(setting_1.packageRootPath, './ckb/devnet');
24
+ const devnetConfigPath = settings.devnet.configPath;
25
+ if (!(0, fs_2.isFolderExists)(devnetConfigPath)) {
26
+ const devnetConfigPath = settings.devnet.configPath;
27
+ yield (0, fs_2.copyFilesWithExclusion)(devnetSourcePath, devnetConfigPath, ['data']);
28
+ console.debug(`init devnet config folder: ${devnetConfigPath}`);
29
+ // copy and edit ckb-miner.toml
30
+ const minerToml = path_1.default.join(devnetSourcePath, 'ckb-miner.toml');
31
+ const newMinerToml = path_1.default.join(devnetConfigPath, 'ckb-miner.toml');
32
+ // Read the content of the ckb-miner.toml file
33
+ const data = fs_1.default.readFileSync(minerToml, 'utf8');
34
+ // Replace the URL
35
+ const modifiedData = data.replace('http://ckb:8114/', settings.devnet.rpcUrl);
36
+ // Write the modified content back to the file
37
+ fs_1.default.writeFileSync(newMinerToml, modifiedData, 'utf8');
38
+ }
39
+ });
40
+ }
41
+ exports.initChainIfNeeded = initChainIfNeeded;
@@ -1,10 +1,9 @@
1
- export declare function installDependency(): Promise<void>;
2
- export declare function downloadBinaryAndUnzip(): Promise<void>;
3
- export declare function downloadAndSaveCKBBinary(tempFilePath: string): Promise<void>;
1
+ export declare function installCKBBinary(version: string): Promise<void>;
2
+ export declare function downloadCKBBinaryAndUnzip(version: string): Promise<void>;
3
+ export declare function downloadAndSaveCKBBinary(version: string, tempFilePath: string): Promise<void>;
4
4
  export declare function unZipFile(filePath: string, extractDir: string, useTar?: boolean): Promise<void>;
5
5
  export declare function decompressTarGzAsync(tarballPath: string, destinationDir: string): Promise<void>;
6
- export declare function getInstalledVersion(): string | null;
7
- export declare function isVersionOutdated(installedVersion: string): boolean;
6
+ export declare function getVersionFromBinary(binPath: string): string | null;
8
7
  export declare function getOS(): string;
9
8
  export declare function getArch(): string;
10
9
  export declare function getExtension(): 'tar.gz' | 'zip';