@offckb/cli 0.2.6 → 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 (96) hide show
  1. package/README.md +59 -17
  2. package/ckb/devnet/specs/dev.toml +7 -7
  3. package/dist/cfg/env-path.d.ts +9 -0
  4. package/dist/cfg/env-path.js +63 -0
  5. package/dist/cfg/setting.d.ts +45 -0
  6. package/dist/cfg/setting.js +124 -0
  7. package/dist/cli.js +54 -30
  8. package/dist/cmd/clean.js +7 -5
  9. package/dist/cmd/config.d.ts +11 -0
  10. package/dist/cmd/config.js +102 -0
  11. package/dist/cmd/create.d.ts +1 -1
  12. package/dist/cmd/create.js +19 -8
  13. package/dist/cmd/debug.d.ts +13 -0
  14. package/dist/cmd/debug.js +100 -0
  15. package/dist/cmd/deploy.js +45 -25
  16. package/dist/cmd/deposit.js +11 -7
  17. package/dist/cmd/inject-config.d.ts +0 -3
  18. package/dist/cmd/inject-config.js +20 -80
  19. package/dist/cmd/list-hashes.d.ts +25 -1
  20. package/dist/cmd/list-hashes.js +24 -16
  21. package/dist/cmd/{deployed-scripts.d.ts → my-scripts.d.ts} +1 -1
  22. package/dist/cmd/my-scripts.js +25 -0
  23. package/dist/cmd/node.d.ts +5 -1
  24. package/dist/cmd/node.js +22 -8
  25. package/dist/cmd/proxy-rpc.d.ts +7 -0
  26. package/dist/cmd/proxy-rpc.js +23 -0
  27. package/dist/cmd/sync-config.js +16 -11
  28. package/dist/cmd/system-scripts.d.ts +42 -0
  29. package/dist/cmd/system-scripts.js +265 -0
  30. package/dist/deploy/migration.d.ts +45 -0
  31. package/dist/deploy/migration.js +131 -0
  32. package/dist/deploy/toml.d.ts +38 -0
  33. package/dist/deploy/toml.js +60 -0
  34. package/dist/deploy/util.d.ts +2 -0
  35. package/dist/deploy/util.js +19 -0
  36. package/dist/node/init-chain.js +41 -0
  37. package/dist/{cmd/develop → node}/install.d.ts +4 -5
  38. package/dist/{cmd/develop → node}/install.js +32 -32
  39. package/dist/scripts/gen.d.ts +5 -0
  40. package/dist/scripts/gen.js +69 -0
  41. package/dist/scripts/public.d.ts +8 -0
  42. package/dist/scripts/public.js +396 -0
  43. package/dist/scripts/type.d.ts +46 -0
  44. package/dist/scripts/type.js +19 -0
  45. package/dist/scripts/util.d.ts +3 -0
  46. package/dist/scripts/util.js +84 -0
  47. package/dist/template/config.d.ts +4 -0
  48. package/dist/template/config.js +60 -0
  49. package/dist/template/offckb.config.d.ts +69 -0
  50. package/dist/template/offckb.config.js +81 -0
  51. package/dist/{util/template.d.ts → template/option.d.ts} +1 -1
  52. package/dist/template/option.js +11 -0
  53. package/dist/template/option.json +16 -0
  54. package/dist/tools/ckb-debugger.d.ts +12 -0
  55. package/dist/tools/ckb-debugger.js +31 -0
  56. package/dist/tools/ckb-tx-dumper.d.ts +6 -0
  57. package/dist/tools/ckb-tx-dumper.js +21 -0
  58. package/dist/tools/rpc-proxy.d.ts +9 -0
  59. package/dist/tools/rpc-proxy.js +84 -0
  60. package/dist/util/ckb.d.ts +64 -0
  61. package/dist/util/ckb.js +16 -3
  62. package/dist/util/encoding.d.ts +1 -0
  63. package/dist/util/encoding.js +7 -1
  64. package/dist/util/fs.d.ts +1 -2
  65. package/dist/util/fs.js +8 -32
  66. package/dist/util/git.js +19 -7
  67. package/dist/util/request.d.ts +8 -0
  68. package/dist/util/request.js +57 -0
  69. package/dist/util/type.d.ts +1 -0
  70. package/dist/util/validator.d.ts +1 -0
  71. package/dist/util/validator.js +13 -4
  72. package/package.json +9 -4
  73. package/templates/offckb.config.ts +3 -3
  74. package/templates/template.json +16 -0
  75. package/dist/cfg/const.d.ts +0 -21
  76. package/dist/cfg/const.js +0 -51
  77. package/dist/cmd/deployed-scripts.js +0 -14
  78. package/dist/cmd/develop/build-account.d.ts +0 -1
  79. package/dist/cmd/develop/build-account.js +0 -9
  80. package/dist/cmd/develop/genkey.d.ts +0 -14
  81. package/dist/cmd/develop/genkey.js +0 -143
  82. package/dist/cmd/develop/init-chain.js +0 -76
  83. package/dist/cmd/develop/lumos-config.d.ts +0 -4
  84. package/dist/cmd/develop/lumos-config.js +0 -153
  85. package/dist/util/config.d.ts +0 -9
  86. package/dist/util/config.js +0 -136
  87. package/dist/util/template.js +0 -30
  88. package/templates/config.json +0 -98
  89. /package/ckb/devnet/specs/{omni_lock → omnilock} +0 -0
  90. /package/ckb/devnet/specs/{spore-scripts → spore}/spore +0 -0
  91. /package/ckb/devnet/specs/{spore-scripts/cluster → spore/spore_cluster} +0 -0
  92. /package/ckb/devnet/specs/{spore-scripts/cluster_agent → spore/spore_cluster_agent} +0 -0
  93. /package/ckb/devnet/specs/{spore-scripts/cluster_proxy → spore/spore_cluster_proxy} +0 -0
  94. /package/ckb/devnet/specs/{spore-scripts → spore}/spore_extension_lua +0 -0
  95. /package/ckb/devnet/specs/{xudt_rce → xudt} +0 -0
  96. /package/dist/{cmd/develop → node}/init-chain.d.ts +0 -0
@@ -0,0 +1,102 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.Config = exports.ConfigItem = exports.ConfigAction = void 0;
13
+ const setting_1 = require("../cfg/setting");
14
+ const request_1 = require("../util/request");
15
+ const validator_1 = require("../util/validator");
16
+ var ConfigAction;
17
+ (function (ConfigAction) {
18
+ ConfigAction["list"] = "list";
19
+ ConfigAction["get"] = "get";
20
+ ConfigAction["set"] = "set";
21
+ ConfigAction["rm"] = "rm";
22
+ })(ConfigAction || (exports.ConfigAction = ConfigAction = {}));
23
+ var ConfigItem;
24
+ (function (ConfigItem) {
25
+ ConfigItem["proxy"] = "proxy";
26
+ ConfigItem["ckbVersion"] = "ckb-version";
27
+ })(ConfigItem || (exports.ConfigItem = ConfigItem = {}));
28
+ function Config(action, item, value) {
29
+ return __awaiter(this, void 0, void 0, function* () {
30
+ if (action === ConfigAction.list) {
31
+ console.log('config file: ', setting_1.configPath);
32
+ return console.log((0, setting_1.readSettings)());
33
+ }
34
+ if (action === ConfigAction.get) {
35
+ switch (item) {
36
+ case ConfigItem.proxy: {
37
+ const settings = (0, setting_1.readSettings)();
38
+ const proxy = settings.proxy;
39
+ if (proxy == null) {
40
+ console.log(`No Proxy.`);
41
+ process.exit(0);
42
+ }
43
+ return console.log(`${request_1.Request.proxyConfigToUrl(proxy)}`);
44
+ }
45
+ case ConfigItem.ckbVersion: {
46
+ const settings = (0, setting_1.readSettings)();
47
+ const version = settings.bins.defaultCKBVersion;
48
+ return console.log(`${version}`);
49
+ }
50
+ default:
51
+ break;
52
+ }
53
+ }
54
+ if (action === ConfigAction.set) {
55
+ switch (item) {
56
+ case ConfigItem.proxy: {
57
+ if (value == null)
58
+ throw new Error('No proxyUrl!');
59
+ try {
60
+ const proxy = request_1.Request.parseProxyUrl(value);
61
+ const settings = (0, setting_1.readSettings)();
62
+ settings.proxy = proxy;
63
+ return (0, setting_1.writeSettings)(settings);
64
+ }
65
+ catch (error) {
66
+ return console.error(`invalid proxyURL, `, error.message);
67
+ }
68
+ }
69
+ case ConfigItem.ckbVersion: {
70
+ const settings = (0, setting_1.readSettings)();
71
+ try {
72
+ if ((0, validator_1.isValidVersion)(value)) {
73
+ settings.bins.defaultCKBVersion = value;
74
+ return (0, setting_1.writeSettings)(settings);
75
+ }
76
+ else {
77
+ return console.error(`invalid version value, `, value);
78
+ }
79
+ }
80
+ catch (error) {
81
+ return console.error(`invalid version value, `, error.message);
82
+ }
83
+ }
84
+ default:
85
+ break;
86
+ }
87
+ }
88
+ if (action === ConfigAction.rm) {
89
+ switch (item) {
90
+ case ConfigItem.proxy: {
91
+ const settings = (0, setting_1.readSettings)();
92
+ settings.proxy = undefined;
93
+ return (0, setting_1.writeSettings)(settings);
94
+ }
95
+ default:
96
+ break;
97
+ }
98
+ }
99
+ throw new Error('invalid config action.');
100
+ });
101
+ }
102
+ exports.Config = Config;
@@ -1,4 +1,4 @@
1
- import { BareTemplateOption } from '../util/template';
1
+ import { BareTemplateOption } from '../template/option';
2
2
  export interface CreateOption {
3
3
  script: boolean;
4
4
  }
@@ -14,12 +14,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.selectBareTemplate = exports.create = exports.createScriptProject = void 0;
16
16
  const path_1 = __importDefault(require("path"));
17
- const const_1 = require("../cfg/const");
18
17
  const fs_1 = require("../util/fs");
19
- const template_1 = require("../util/template");
20
18
  const git_1 = require("../util/git");
21
19
  const prompts_1 = require("@inquirer/prompts");
22
20
  const child_process_1 = require("child_process");
21
+ const gen_1 = require("../scripts/gen");
22
+ const setting_1 = require("../cfg/setting");
23
+ const option_1 = require("../template/option");
24
+ const config_1 = require("../template/config");
23
25
  const version = require('../../package.json').version;
24
26
  function createScriptProject(name) {
25
27
  const cmd = `cargo generate gh:cryptape/ckb-script-templates workspace --name ${name}`;
@@ -33,14 +35,23 @@ function createScriptProject(name) {
33
35
  exports.createScriptProject = createScriptProject;
34
36
  function create(name, template) {
35
37
  return __awaiter(this, void 0, void 0, function* () {
36
- const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
37
- const dappTemplateFolderPath = `${const_1.dappTemplateGitFolder}/${template.value}`;
38
- (0, git_1.gitCloneAndDownloadFolderSync)(const_1.dappTemplateGitUrl, const_1.dappTemplateGitBranch, dappTemplateFolderPath, targetPath);
38
+ const targetPath = path_1.default.resolve(process.cwd(), name);
39
+ const settings = (0, setting_1.readSettings)();
40
+ const dappTemplateFolderPath = `${settings.dappTemplate.gitFolder}/${template.value}`;
41
+ (0, git_1.gitCloneAndDownloadFolderSync)(settings.dappTemplate.gitRepoUrl, settings.dappTemplate.gitBranch, dappTemplateFolderPath, targetPath);
39
42
  // update the version
40
- const projectFolder = path_1.default.resolve(const_1.currentExecPath, name);
43
+ const projectFolder = path_1.default.resolve(process.cwd(), name);
41
44
  const targetConfigPath = (0, fs_1.findFileInFolder)(projectFolder, 'offckb.config.ts');
42
45
  if (targetConfigPath) {
43
- (0, fs_1.updateVersionInTSFile)(version, targetConfigPath);
46
+ config_1.OffCKBConfigFile.updateVersion(version, targetConfigPath);
47
+ const contractInfoFolder = config_1.OffCKBConfigFile.readContractInfoFolder(targetConfigPath);
48
+ if (!contractInfoFolder) {
49
+ throw new Error('No contract info folder found in offckb.config.ts!');
50
+ }
51
+ const systemJsonFilePath = path_1.default.resolve(contractInfoFolder, 'system-scripts.json');
52
+ (0, gen_1.genSystemScriptsJsonFile)(systemJsonFilePath);
53
+ const myScriptsJsonFilePath = path_1.default.resolve(contractInfoFolder, 'my-scripts.json');
54
+ (0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
44
55
  }
45
56
  else {
46
57
  console.log("Couldn't find the offckb config file in project. abort.");
@@ -50,7 +61,7 @@ function create(name, template) {
50
61
  exports.create = create;
51
62
  function selectBareTemplate() {
52
63
  return __awaiter(this, void 0, void 0, function* () {
53
- const opts = yield (0, template_1.loadBareTemplateOpts)();
64
+ const opts = yield (0, option_1.loadBareTemplateOpts)();
54
65
  const answer = yield (0, prompts_1.select)({
55
66
  message: 'Select a bare template',
56
67
  choices: opts.map((opt) => {
@@ -0,0 +1,13 @@
1
+ export declare function debugTransaction(txHash: string): void;
2
+ export declare function buildTransactionDebugOptions(txHash: string): {
3
+ name: string;
4
+ cmdOption: string;
5
+ }[];
6
+ export declare function debugSingleScript(txHash: string, cellIndex: number, cellType: 'input' | 'output', scriptType: 'type' | 'lock', bin?: string): void;
7
+ export declare function parseSingleScriptOption(value: string): {
8
+ cellType: "output" | "input";
9
+ cellIndex: number;
10
+ scriptType: "type" | "lock";
11
+ };
12
+ export declare function buildTxFileOptionBy(txHash: string): string;
13
+ export declare function debugRaw(options: string): void;
@@ -0,0 +1,100 @@
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.debugRaw = exports.buildTxFileOptionBy = exports.parseSingleScriptOption = exports.debugSingleScript = exports.buildTransactionDebugOptions = exports.debugTransaction = void 0;
7
+ const setting_1 = require("../cfg/setting");
8
+ const ckb_debugger_1 = require("../tools/ckb-debugger");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const ckb_tx_dumper_1 = require("../tools/ckb-tx-dumper");
11
+ const path_1 = __importDefault(require("path"));
12
+ // todo: if we use import this throws error in tsc building
13
+ //import { cccA } from '@ckb-ccc/core/dist.commonjs/advanced';
14
+ const { cccA } = require('@ckb-ccc/core/advanced');
15
+ function debugTransaction(txHash) {
16
+ const txFile = buildTxFileOptionBy(txHash);
17
+ const opts = buildTransactionDebugOptions(txHash);
18
+ for (const opt of opts) {
19
+ console.log(`\n******************************`);
20
+ console.log(`****** ${opt.name} ******\n`);
21
+ debugRaw(`${txFile} ${opt.cmdOption}`);
22
+ }
23
+ }
24
+ exports.debugTransaction = debugTransaction;
25
+ function buildTransactionDebugOptions(txHash) {
26
+ var _a;
27
+ const settings = (0, setting_1.readSettings)();
28
+ const txJsonFilePath = `${settings.devnet.transactionsPath}/${txHash}.json`;
29
+ const txJson = JSON.parse(fs_1.default.readFileSync(txJsonFilePath, 'utf-8'));
30
+ const cccTx = cccA.JsonRpcTransformers.transactionTo(txJson);
31
+ const result = [];
32
+ for (const [index, input] of cccTx.inputs.entries()) {
33
+ result.push({
34
+ name: `Input[${index}].Lock`,
35
+ cmdOption: `--cell-index ${index} --cell-type input --script-group-type lock`,
36
+ });
37
+ if ((_a = input.cellOutput) === null || _a === void 0 ? void 0 : _a.type) {
38
+ result.push({
39
+ name: `Input[${index}].Type`,
40
+ cmdOption: `--cell-index ${index} --cell-type input --script-group-type type`,
41
+ });
42
+ }
43
+ }
44
+ for (const [index, output] of cccTx.outputs.entries()) {
45
+ if (output.type) {
46
+ result.push({
47
+ name: `Output[${index}].Type`,
48
+ cmdOption: `--cell-index ${index} --cell-type output --script-group-type type`,
49
+ });
50
+ }
51
+ }
52
+ return result;
53
+ }
54
+ exports.buildTransactionDebugOptions = buildTransactionDebugOptions;
55
+ function debugSingleScript(txHash, cellIndex, cellType, scriptType, bin) {
56
+ const txFile = buildTxFileOptionBy(txHash);
57
+ let opt = `--cell-index ${cellIndex} --cell-type ${cellType} --script-group-type ${scriptType}`;
58
+ if (bin) {
59
+ opt = opt + ` --bin ${bin}`;
60
+ }
61
+ debugRaw(`${txFile} ${opt}`);
62
+ }
63
+ exports.debugSingleScript = debugSingleScript;
64
+ // Helper function to validate and parse the --script value
65
+ function parseSingleScriptOption(value) {
66
+ const regex = /^(input|output)\[(\d+)\]\.(lock|type)$/i;
67
+ const match = value.match(regex);
68
+ if (!match) {
69
+ throw new Error(`Invalid --script value: ${value}, example format: "input[0].lock"`);
70
+ }
71
+ const [_, cellType, cellIndex, scriptType] = match;
72
+ return {
73
+ cellType: cellType.toLowerCase(), // input or output
74
+ cellIndex: parseInt(cellIndex, 10), // number in []
75
+ scriptType: scriptType.toLowerCase(), // lock or type
76
+ };
77
+ }
78
+ exports.parseSingleScriptOption = parseSingleScriptOption;
79
+ function buildTxFileOptionBy(txHash) {
80
+ const settings = (0, setting_1.readSettings)();
81
+ const outputFilePath = `${settings.devnet.debugFullTransactionsPath}/${txHash}.json`;
82
+ if (!fs_1.default.existsSync(outputFilePath)) {
83
+ const rpc = settings.devnet.rpcUrl;
84
+ const txJsonFilePath = `${settings.devnet.transactionsPath}/${txHash}.json`;
85
+ if (!fs_1.default.existsSync(outputFilePath)) {
86
+ fs_1.default.mkdirSync(path_1.default.dirname(outputFilePath), { recursive: true });
87
+ }
88
+ (0, ckb_tx_dumper_1.dumpTransaction)({ rpc, txJsonFilePath, outputFilePath });
89
+ }
90
+ const opt = `--tx-file ${outputFilePath}`;
91
+ return opt;
92
+ }
93
+ exports.buildTxFileOptionBy = buildTxFileOptionBy;
94
+ function debugRaw(options) {
95
+ if (!ckb_debugger_1.CKBDebugger.isBinaryInstalled()) {
96
+ ckb_debugger_1.CKBDebugger.installCKBDebugger();
97
+ }
98
+ return ckb_debugger_1.CKBDebugger.runRaw(options);
99
+ }
100
+ exports.debugRaw = debugRaw;
@@ -15,14 +15,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.deploy = void 0;
16
16
  const lumos_1 = require("@ckb-lumos/lumos");
17
17
  const fs_1 = __importDefault(require("fs"));
18
- const const_1 = require("../cfg/const");
19
18
  const type_1 = require("../util/type");
20
19
  const path_1 = __importDefault(require("path"));
21
20
  const ckb_1 = require("../util/ckb");
22
21
  const account_1 = require("../cfg/account");
23
- const config_1 = require("../util/config");
24
22
  const fs_2 = require("../util/fs");
25
23
  const validator_1 = require("../util/validator");
24
+ const toml_1 = require("../deploy/toml");
25
+ const migration_1 = require("../deploy/migration");
26
+ const utils_1 = require("@ckb-lumos/lumos/utils");
27
+ const gen_1 = require("../scripts/gen");
28
+ const config_1 = require("../template/config");
26
29
  function deploy(opt = { network: type_1.Network.devnet, target: null }) {
27
30
  return __awaiter(this, void 0, void 0, function* () {
28
31
  const network = opt.network;
@@ -34,12 +37,12 @@ function deploy(opt = { network: type_1.Network.devnet, target: null }) {
34
37
  const from = ckb_1.CKB.generateAccountFromPrivateKey(privateKey, lumosConfig);
35
38
  const targetFolder = opt.target;
36
39
  if (targetFolder) {
37
- const binFolder = (0, fs_2.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(const_1.currentExecPath, targetFolder);
40
+ const binFolder = (0, fs_2.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(process.cwd(), targetFolder);
38
41
  const bins = (0, fs_2.listBinaryFilesInFolder)(binFolder);
39
42
  const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
40
43
  const results = yield deployBinaries(binPaths, from, ckb);
41
44
  // record the deployed contract infos
42
- recordDeployResult(results, network, false); // we don't update offCKB.config since we don't know where the file is
45
+ recordDeployResult(results, network, false); // we don't update my-scripts.json since we don't know where the file is
43
46
  return;
44
47
  }
45
48
  // check if target workspace is valid
@@ -58,13 +61,14 @@ function deploy(opt = { network: type_1.Network.devnet, target: null }) {
58
61
  }
59
62
  exports.deploy = deploy;
60
63
  function getToDeployBinsPath() {
61
- const fileContent = fs_1.default.readFileSync(const_1.userOffCKBConfigPath, 'utf-8');
64
+ const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
65
+ const fileContent = fs_1.default.readFileSync(userOffCKBConfigPath, 'utf-8');
62
66
  const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
63
67
  if (match && match[1]) {
64
68
  const contractBinFolderValue = match[1];
65
69
  const binFolderPath = (0, fs_2.isAbsolutePath)(contractBinFolderValue)
66
70
  ? contractBinFolderValue
67
- : path_1.default.resolve(const_1.currentExecPath, contractBinFolderValue);
71
+ : path_1.default.resolve(process.cwd(), contractBinFolderValue);
68
72
  const bins = (0, fs_2.listBinaryFilesInFolder)(binFolderPath);
69
73
  return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
70
74
  }
@@ -73,25 +77,23 @@ function getToDeployBinsPath() {
73
77
  return [];
74
78
  }
75
79
  }
76
- function recordDeployResult(results, network, updateOffCKBConfig = true) {
80
+ function recordDeployResult(results, network, updateMyScriptsJsonFile = true) {
77
81
  return __awaiter(this, void 0, void 0, function* () {
78
82
  if (results.length === 0) {
79
83
  return;
80
84
  }
81
85
  for (const result of results) {
82
- const { scriptConfig, contractName } = result;
83
- const jsonContent = JSON.stringify(scriptConfig, null, 2);
84
- const filename = `${contractName}.json`;
85
- const filePath = path_1.default.resolve(const_1.deployedContractInfoFolderPath, network, filename);
86
- if (!(0, fs_2.isFolderExists)(path_1.default.resolve(const_1.deployedContractInfoFolderPath, network))) {
87
- fs_1.default.mkdirSync(path_1.default.resolve(const_1.deployedContractInfoFolderPath, network), { recursive: true });
88
- }
89
- fs_1.default.writeFileSync(filePath, jsonContent);
86
+ (0, toml_1.generateDeploymentToml)(result.deploymentOptions, network);
87
+ (0, migration_1.generateDeploymentRecipeJsonFile)(result.deploymentOptions.name, result.deploymentRecipe, network);
90
88
  }
91
- // update lumos config in offckb.config.ts
92
- if (updateOffCKBConfig) {
93
- const newLumosConfig = (0, config_1.buildFullLumosConfig)(network);
94
- (0, config_1.updateScriptInfoInOffCKBConfigTs)(newLumosConfig, const_1.userOffCKBConfigPath, network);
89
+ // update my-scripts.json
90
+ if (updateMyScriptsJsonFile) {
91
+ const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
92
+ const folder = config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
93
+ if (folder) {
94
+ const myScriptsFilePath = path_1.default.resolve(folder, 'my-scripts.json');
95
+ (0, gen_1.genMyScriptsJsonFile)(myScriptsFilePath);
96
+ }
95
97
  }
96
98
  console.log('done.');
97
99
  });
@@ -112,7 +114,7 @@ function deployBinaries(binPaths, from, ckb) {
112
114
  function deployBinary(binPath, from, ckb) {
113
115
  return __awaiter(this, void 0, void 0, function* () {
114
116
  const bin = yield (0, fs_2.readFileToUint8Array)(binPath);
115
- const contractName = (0, fs_2.convertFilenameToUppercase)(binPath);
117
+ const contractName = path_1.default.basename(binPath);
116
118
  const result = yield lumos_1.commons.deploy.generateDeployWithTypeIdTx({
117
119
  cellProvider: ckb.indexer,
118
120
  fromInfo: from.address,
@@ -127,11 +129,29 @@ function deployBinary(binPath, from, ckb) {
127
129
  const tx = lumos_1.helpers.sealTransaction(txSkeleton, [Sig]);
128
130
  const res = yield ckb.rpc.sendTransaction(tx, 'passthrough');
129
131
  console.log(`contract ${contractName} deployed, tx hash:`, res);
130
- //todo: upgrade lumos
131
- // indexer.waitForSync has a bug, we use negative number to workaround.
132
- // the negative number presents the block difference from current tip to wait
133
132
  console.log('wait 4 blocks..');
134
- yield ckb.indexer.waitForSync(-4);
135
- return Object.assign({ contractName }, result);
133
+ yield ckb.indexer.waitForSync(-4); // why negative 4? a bug in ckb-lumos
134
+ // todo: handle multiple cell recipes?
135
+ return {
136
+ deploymentOptions: {
137
+ name: contractName,
138
+ binFilePath: binPath,
139
+ enableTypeId: true,
140
+ lockScript: tx.outputs[+result.scriptConfig.INDEX].lock,
141
+ },
142
+ deploymentRecipe: {
143
+ cellRecipes: [
144
+ {
145
+ name: contractName,
146
+ txHash: result.scriptConfig.TX_HASH,
147
+ index: result.scriptConfig.INDEX,
148
+ occupiedCapacity: '0x' + BigInt(tx.outputsData[+result.scriptConfig.INDEX].slice(2).length / 2).toString(16),
149
+ dataHash: (0, utils_1.ckbHash)(tx.outputsData[+result.scriptConfig.INDEX]),
150
+ typeId: (0, utils_1.computeScriptHash)(result.typeId),
151
+ },
152
+ ],
153
+ depGroupRecipes: [],
154
+ },
155
+ };
136
156
  });
137
157
  }
@@ -8,18 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
9
9
  });
10
10
  };
11
- var __importDefault = (this && this.__importDefault) || function (mod) {
12
- return (mod && mod.__esModule) ? mod : { "default": mod };
13
- };
14
11
  Object.defineProperty(exports, "__esModule", { value: true });
15
12
  exports.deposit = void 0;
16
13
  const ckb_1 = require("../util/ckb");
17
- const axios_1 = __importDefault(require("axios"));
18
- const genkey_1 = require("./develop/genkey");
19
14
  const account_1 = require("../cfg/account");
20
15
  const type_1 = require("../util/type");
21
16
  const link_1 = require("../util/link");
22
17
  const validator_1 = require("../util/validator");
18
+ const request_1 = require("../util/request");
23
19
  function deposit(toAddress, amount, opt = { network: type_1.Network.devnet }) {
24
20
  return __awaiter(this, void 0, void 0, function* () {
25
21
  const network = opt.network;
@@ -45,7 +41,7 @@ function depositFromTestnetFaucet(ckbAddress, ckb) {
45
41
  return __awaiter(this, void 0, void 0, function* () {
46
42
  console.log('testnet faucet only supports fixed-amount claim: 10,000 CKB');
47
43
  const lumosConfig = ckb.getLumosConfig();
48
- const randomAccountPrivateKey = '0x' + (0, genkey_1.generateHex)(64);
44
+ const randomAccountPrivateKey = '0x' + generateHex(64);
49
45
  const randomAccount = ckb_1.CKB.generateAccountFromPrivateKey(randomAccountPrivateKey, lumosConfig);
50
46
  console.log(`use random account to claim from faucet: \n\nprivate key: ${randomAccountPrivateKey}\n\n address: ${randomAccount.address}`);
51
47
  try {
@@ -85,7 +81,7 @@ function sendClaimRequest(toAddress) {
85
81
  data: body,
86
82
  };
87
83
  try {
88
- const response = yield (0, axios_1.default)(config);
84
+ const response = yield request_1.Request.send(config);
89
85
  console.log('send claim request, status: ', response.status); // Handle the response data here
90
86
  }
91
87
  catch (error) {
@@ -93,3 +89,11 @@ function sendClaimRequest(toAddress) {
93
89
  }
94
90
  });
95
91
  }
92
+ function generateHex(length) {
93
+ const characters = 'abcdef0123456789';
94
+ let result = '';
95
+ for (let i = 0; i < length; i++) {
96
+ result += characters[Math.floor(Math.random() * characters.length)];
97
+ }
98
+ return result;
99
+ }
@@ -1,4 +1 @@
1
- /// <reference types="node" />
2
1
  export declare function injectConfig(): void;
3
- export declare function readLumosVersionFromOffCKBConfig(): string;
4
- export declare function installLumosPackage(version: string): Buffer;
@@ -1,100 +1,40 @@
1
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
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
26
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
27
4
  };
28
5
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.installLumosPackage = exports.readLumosVersionFromOffCKBConfig = exports.injectConfig = void 0;
30
- const path_1 = __importDefault(require("path"));
31
- const const_1 = require("../cfg/const");
32
- const child_process_1 = require("child_process");
33
- const fs_1 = __importStar(require("fs"));
34
- const config_1 = require("../util/config");
6
+ exports.injectConfig = void 0;
7
+ const fs_1 = require("fs");
35
8
  const validator_1 = require("../util/validator");
36
- const type_1 = require("../util/type");
9
+ const path_1 = __importDefault(require("path"));
10
+ const gen_1 = require("../scripts/gen");
11
+ const config_1 = require("../template/config");
12
+ const version = require('../../package.json').version;
37
13
  function injectConfig() {
38
14
  (0, validator_1.validateTypescriptWorkspace)();
39
15
  // inject the offckb.config.ts file into users workspace
40
16
  // copy config template
41
- (0, fs_1.copyFileSync)(const_1.predefinedOffCKBConfigTsPath, const_1.userOffCKBConfigPath);
17
+ const predefinedOffCKBConfigTsPath = path_1.default.resolve('../template', 'offckb.config.ts');
18
+ const userOffCKBConfigPath = path_1.default.resolve(process.cwd(), 'offckb.config.ts');
19
+ (0, fs_1.copyFileSync)(predefinedOffCKBConfigTsPath, userOffCKBConfigPath);
42
20
  // update the version in the offckb.config.ts
43
- (0, config_1.updateOffCKBConfigVersion)(const_1.userOffCKBConfigPath);
44
- // update the config
45
- const devnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.devnet);
46
- const testnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.testnet);
47
- const mainnetFullLumosConfig = (0, config_1.buildFullLumosConfig)(type_1.Network.mainnet);
48
- (0, config_1.updateScriptInfoInOffCKBConfigTs)(devnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.devnet);
49
- (0, config_1.updateScriptInfoInOffCKBConfigTs)(testnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.testnet);
50
- (0, config_1.updateScriptInfoInOffCKBConfigTs)(mainnetFullLumosConfig, const_1.userOffCKBConfigPath, type_1.Network.mainnet);
51
- console.log(`Inject offckb.config.ts file.`);
52
- // todo: select yarn/npm/pnpm to install the lumos version from user
53
- const version = readLumosVersionFromOffCKBConfig();
54
- installLumosPackage(version);
21
+ config_1.OffCKBConfigFile.updateVersion(version, userOffCKBConfigPath);
22
+ const contractInfoFolder = config_1.OffCKBConfigFile.readContractInfoFolder(userOffCKBConfigPath);
23
+ if (!contractInfoFolder) {
24
+ throw new Error('No contract info folder found in offckb.config.ts!');
25
+ }
26
+ const systemJsonFilePath = path_1.default.resolve(contractInfoFolder, 'system-scripts.json');
27
+ (0, gen_1.genSystemScriptsJsonFile)(systemJsonFilePath);
28
+ const myScriptsJsonFilePath = path_1.default.resolve(contractInfoFolder, 'my-scripts.json');
29
+ (0, gen_1.genMyScriptsJsonFile)(myScriptsJsonFilePath);
55
30
  console.log(`\n\nAll good. You can now use it in your project like:
56
31
 
57
32
  import offCKB from "offckb.config";
58
33
 
59
- const lumosConfig = offCKB.lumosConfig;
60
- const indexer = offCKB.indexer;
61
- const rpc = offCKB.rpc;
34
+ const myScriptCodeHash = offCKB.myScripts['script-name'].codeHash;
35
+ const omnilockScriptCodeHash = offCKB.systemScripts['omnilock'].codeHash;
62
36
 
63
37
  Check example at https://github.com/nervosnetwork/docs.nervos.org/tree/develop/examples/simple-transfer
64
38
  `);
65
39
  }
66
40
  exports.injectConfig = injectConfig;
67
- function readLumosVersionFromOffCKBConfig() {
68
- const fileContent = fs_1.default.readFileSync(const_1.userOffCKBConfigPath, 'utf-8');
69
- const match = fileContent.match(/lumosVersion:\s*['"]([^'"]+)['"]/);
70
- if (match && match[1]) {
71
- return match[1];
72
- }
73
- else {
74
- console.log('lumosVersion value not found in offckb.config.ts', match);
75
- return const_1.defaultLumosVersion;
76
- }
77
- }
78
- exports.readLumosVersionFromOffCKBConfig = readLumosVersionFromOffCKBConfig;
79
- function installLumosPackage(version) {
80
- // Check if package.json exists
81
- const packageJsonPath = path_1.default.join(const_1.currentExecPath, 'package.json');
82
- if (!fs_1.default.existsSync(packageJsonPath)) {
83
- throw new Error('package.json not found in the current directory');
84
- }
85
- const packageLock = path_1.default.join(const_1.currentExecPath, 'package-lock.json');
86
- if (fs_1.default.existsSync(packageLock)) {
87
- return (0, child_process_1.execSync)(`npm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
88
- }
89
- const yarnLock = path_1.default.join(const_1.currentExecPath, 'yarn.lock');
90
- if (fs_1.default.existsSync(yarnLock)) {
91
- console.log(`yarn add @ckb-lumos/lumos@${version}`);
92
- return (0, child_process_1.execSync)(`yarn add @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
93
- }
94
- const pnpmLock = path_1.default.join(const_1.currentExecPath, 'pnpm-lock.json');
95
- if (fs_1.default.existsSync(pnpmLock)) {
96
- return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
97
- }
98
- return (0, child_process_1.execSync)(`pnpm i @ckb-lumos/lumos@${version}`, { stdio: 'inherit' });
99
- }
100
- exports.installLumosPackage = installLumosPackage;
@@ -1 +1,25 @@
1
- export declare function listHashes(): Promise<void>;
1
+ import { H256 } from '../util/type';
2
+ export interface SystemCell {
3
+ path: string;
4
+ tx_hash: H256;
5
+ index: number;
6
+ data_hash: H256;
7
+ type_hash?: H256;
8
+ }
9
+ export interface DepGroupCell {
10
+ included_cells: string[];
11
+ tx_hash: H256;
12
+ index: number;
13
+ }
14
+ export interface SpecHashes {
15
+ spec_hash: H256;
16
+ genesis: H256;
17
+ cellbase: H256;
18
+ system_cells: SystemCell[];
19
+ dep_groups: DepGroupCell[];
20
+ }
21
+ export interface ListHashes {
22
+ offckb: SpecHashes;
23
+ }
24
+ export declare function listHashes(version?: string): Promise<void>;
25
+ export declare function getListHashes(version?: string): string | null;