@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
package/dist/util/fs.js CHANGED
@@ -32,7 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
- exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.convertFilenameToUppercase = exports.readFileToUint8Array = exports.updateVersionInTSFile = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
35
+ exports.getSubfolders = exports.findFileInFolder = exports.isAbsolutePath = exports.isBinaryFile = exports.listBinaryFilesInFolder = exports.readFileToUint8Array = exports.copyRecursive = exports.copyFilesWithExclusion = exports.copyFileSync = exports.copyFolderSync = exports.isFolderExists = void 0;
36
36
  const fs = __importStar(require("fs"));
37
37
  const path = __importStar(require("path"));
38
38
  function isFolderExists(folderPath) {
@@ -121,29 +121,6 @@ function copyRecursive(source, destination, excludedFolders) {
121
121
  });
122
122
  }
123
123
  exports.copyRecursive = copyRecursive;
124
- function updateVersionInTSFile(newVersion, filePath) {
125
- try {
126
- // Read the contents of the TS file
127
- const fileContents = fs.readFileSync(filePath, 'utf8');
128
- // Use a regular expression to find the version value
129
- const regex = /const\s+offCKBConfig:\s+OffCKBConfig\s*=\s*\{\s*version:\s*'([^']+)'/;
130
- const match = fileContents.match(regex);
131
- if (match) {
132
- // Replace the version value with the new value
133
- const updatedContents = fileContents.replace(regex, `const offCKBConfig: OffCKBConfig = {\n version: '${newVersion}'`);
134
- // Write the updated contents back to the file
135
- fs.writeFileSync(filePath, updatedContents, 'utf8');
136
- console.log(`Version updated to '${newVersion}' in ${filePath}`);
137
- }
138
- else {
139
- console.error(`Could not find version value in ${filePath}`);
140
- }
141
- }
142
- catch (error) {
143
- console.error(`Error updating version in ${filePath}: ${error}`);
144
- }
145
- }
146
- exports.updateVersionInTSFile = updateVersionInTSFile;
147
124
  function readFileToUint8Array(filePath) {
148
125
  return __awaiter(this, void 0, void 0, function* () {
149
126
  return new Promise((resolve, reject) => {
@@ -158,14 +135,6 @@ function readFileToUint8Array(filePath) {
158
135
  });
159
136
  }
160
137
  exports.readFileToUint8Array = readFileToUint8Array;
161
- function convertFilenameToUppercase(filePath) {
162
- // Extract the filename from the file path
163
- const filename = path.basename(filePath);
164
- // Convert the filename to uppercase
165
- const uppercaseFilename = filename.toUpperCase();
166
- return uppercaseFilename;
167
- }
168
- exports.convertFilenameToUppercase = convertFilenameToUppercase;
169
138
  function listBinaryFilesInFolder(folderPath) {
170
139
  // Check if the provided path is a directory
171
140
  if (!fs.existsSync(folderPath) || !fs.lstatSync(folderPath).isDirectory()) {
@@ -216,3 +185,10 @@ function findFileInFolder(folderPath, fileName) {
216
185
  return null;
217
186
  }
218
187
  exports.findFileInFolder = findFileInFolder;
188
+ function getSubfolders(folderPath) {
189
+ return fs.readdirSync(folderPath).filter((file) => {
190
+ const fullPath = path.join(folderPath, file);
191
+ return fs.statSync(fullPath).isDirectory();
192
+ });
193
+ }
194
+ exports.getSubfolders = getSubfolders;
package/dist/util/git.js CHANGED
@@ -27,8 +27,8 @@ exports.gitCloneAndDownloadFolderSync = exports.isGitInstalled = void 0;
27
27
  const child_process_1 = require("child_process");
28
28
  const fs = __importStar(require("fs"));
29
29
  const path = __importStar(require("path"));
30
- const const_1 = require("../cfg/const");
31
30
  const fs_1 = require("./fs");
31
+ const setting_1 = require("../cfg/setting");
32
32
  function isGitInstalled() {
33
33
  try {
34
34
  (0, child_process_1.execSync)('git --version');
@@ -41,7 +41,8 @@ function isGitInstalled() {
41
41
  exports.isGitInstalled = isGitInstalled;
42
42
  function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPath) {
43
43
  console.log('start cloning the dapp template..');
44
- const tempFolder = path.resolve(const_1.dappTemplatePath, 'temp-clone-folder');
44
+ const settings = (0, setting_1.readSettings)();
45
+ const tempFolder = path.resolve(settings.dappTemplate.downloadPath, 'temp-clone-folder');
45
46
  if (!isGitInstalled()) {
46
47
  console.log('Git is not installed, please check https://git-scm.com/');
47
48
  return process.exit(1);
@@ -54,17 +55,21 @@ function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPat
54
55
  fs.mkdirSync(tempFolder, { recursive: true });
55
56
  // Clone the repository
56
57
  try {
57
- const cloneCommand = `git clone -n --depth=1 --single-branch --branch ${branch} --filter=tree:0 ${repoUrl} ${tempFolder}`;
58
+ const cloneCommand = `git clone -n --depth=1 --filter=tree:0 --single-branch --branch ${branch} ${repoUrl} ${tempFolder}`;
59
+ console.log(cloneCommand);
58
60
  (0, child_process_1.execSync)(cloneCommand);
59
61
  }
60
62
  catch (error) {
61
63
  console.error('Error:', error);
62
64
  process.exit(1);
63
65
  }
64
- // checkout the examples sub folder
66
+ // Set up sparse-checkout for the subfolder
65
67
  try {
66
- (0, child_process_1.execSync)(`git sparse-checkout set ${subFolderName}`, { cwd: tempFolder });
67
- (0, child_process_1.execSync)(`git checkout`, { cwd: tempFolder });
68
+ console.log(subFolderName, tempFolder);
69
+ (0, child_process_1.execSync)('git sparse-checkout init --cone', { cwd: tempFolder });
70
+ // Use the full path for sparse-checkout
71
+ (0, child_process_1.execSync)(`git sparse-checkout set "${subFolderName}"`, { cwd: tempFolder });
72
+ (0, child_process_1.execSync)('git checkout', { cwd: tempFolder });
68
73
  }
69
74
  catch (error) {
70
75
  console.error('Error:', error);
@@ -74,8 +79,15 @@ function gitCloneAndDownloadFolderSync(repoUrl, branch, subFolderName, targetPat
74
79
  if (!fs.existsSync(targetPath) || !fs.statSync(targetPath).isDirectory()) {
75
80
  fs.mkdirSync(targetPath, { recursive: true });
76
81
  }
82
+ // Copy the specific subfolder
77
83
  const source = path.resolve(tempFolder, subFolderName);
78
- (0, fs_1.copyFolderSync)(source, targetPath);
84
+ if (fs.existsSync(source)) {
85
+ (0, fs_1.copyFolderSync)(source, targetPath);
86
+ }
87
+ else {
88
+ console.error(`Subfolder ${subFolderName} not found in the cloned repository ${source}.`);
89
+ process.exit(1);
90
+ }
79
91
  // Empty the temp folder if it exists
80
92
  if (fs.existsSync(tempFolder)) {
81
93
  fs.rmSync(tempFolder, { recursive: true });
@@ -19,7 +19,6 @@ class Request {
19
19
  static send(_config) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const config = this.proxy ? Object.assign({ proxy: this.proxy }, _config) : _config;
22
- console.log(config);
23
22
  return yield (0, axios_1.default)(config);
24
23
  });
25
24
  }
@@ -6,3 +6,4 @@ export declare enum Network {
6
6
  export interface NetworkOption {
7
7
  network: Network;
8
8
  }
9
+ export type H256 = string;
@@ -2,3 +2,4 @@ export declare function validateTypescriptWorkspace(): void;
2
2
  export declare function validateExecDappEnvironment(): void;
3
3
  export declare function isValidNetworkString(network: string): boolean;
4
4
  export declare function validateNetworkOpt(network: string): void;
5
+ export declare function isValidVersion(version: unknown): boolean;
@@ -3,13 +3,12 @@ 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.validateNetworkOpt = exports.isValidNetworkString = exports.validateExecDappEnvironment = exports.validateTypescriptWorkspace = void 0;
6
+ exports.isValidVersion = exports.validateNetworkOpt = exports.isValidNetworkString = exports.validateExecDappEnvironment = exports.validateTypescriptWorkspace = void 0;
7
7
  const path_1 = __importDefault(require("path"));
8
- const const_1 = require("../cfg/const");
9
8
  const fs_1 = __importDefault(require("fs"));
10
9
  const type_1 = require("./type");
11
10
  function validateTypescriptWorkspace() {
12
- const cwd = const_1.currentExecPath;
11
+ const cwd = process.cwd();
13
12
  // Check if package.json exists
14
13
  const packageJsonPath = path_1.default.join(cwd, 'package.json');
15
14
  if (!fs_1.default.existsSync(packageJsonPath)) {
@@ -23,7 +22,7 @@ function validateTypescriptWorkspace() {
23
22
  }
24
23
  exports.validateTypescriptWorkspace = validateTypescriptWorkspace;
25
24
  function validateExecDappEnvironment() {
26
- const cwd = const_1.currentExecPath;
25
+ const cwd = process.cwd();
27
26
  // Check if package.json and tsconfig.json exists
28
27
  validateTypescriptWorkspace();
29
28
  // Check if offckb.config.ts exists
@@ -57,3 +56,13 @@ function validateNetworkOpt(network) {
57
56
  }
58
57
  }
59
58
  exports.validateNetworkOpt = validateNetworkOpt;
59
+ function isValidVersion(version) {
60
+ if (typeof version !== 'string') {
61
+ return false;
62
+ }
63
+ // Regular expression to match version strings like X.Y.Z
64
+ const versionRegex = /^\d+\.\d+\.\d+$/;
65
+ // Test the version against the regex
66
+ return versionRegex.test(version);
67
+ }
68
+ exports.isValidVersion = isValidVersion;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.2.7",
3
+ "version": "0.3.0-canary-a9175e7.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "Retric Su <retric@cryptape.com>",
6
6
  "license": "MIT",
@@ -16,7 +16,6 @@
16
16
  "dist",
17
17
  "account",
18
18
  "ckb",
19
- "templates/config.json",
20
19
  "templates/offckb.config.ts",
21
20
  "templates/template.json"
22
21
  ],
@@ -61,12 +60,17 @@
61
60
  "typescript": "^5.3.3"
62
61
  },
63
62
  "dependencies": {
63
+ "@ckb-ccc/core": "^0.0.11-alpha.3",
64
64
  "@ckb-lumos/lumos": "0.23.0",
65
+ "@iarna/toml": "^2.2.5",
65
66
  "@inquirer/prompts": "^4.1.0",
67
+ "@types/http-proxy": "^1.17.15",
66
68
  "adm-zip": "^0.5.10",
67
69
  "axios": "^1.6.7",
68
70
  "child_process": "^1.0.2",
71
+ "ckb-transaction-dumper": "^0.4.0",
69
72
  "commander": "^12.0.0",
73
+ "http-proxy": "^1.18.1",
70
74
  "semver": "^7.6.0",
71
75
  "tar": "^6.2.1"
72
76
  }
@@ -1,20 +0,0 @@
1
- export declare const currentExecPath: string;
2
- export declare const packageSrcPath: string;
3
- export declare const packageRootPath: string;
4
- export declare const dappTemplatePath: string;
5
- export declare const targetEnvironmentPath: string;
6
- export declare const predefinedOffCKBConfigTsPath: string;
7
- export declare const userOffCKBConfigPath: string;
8
- export declare const devnetSourcePath: string;
9
- export declare const devnetPath: string;
10
- export declare const devnetDataPath: string;
11
- export declare const ckbFolderPath: string;
12
- export declare const ckbBinPath: string;
13
- export declare const deployedContractInfoFolderPath: string;
14
- export declare const accountTargetDir: string;
15
- export declare const minimalRequiredCKBVersion = "0.113.1";
16
- export declare const defaultLumosVersion = "0.21.0";
17
- export declare const dappTemplateGitRepoUserAndName = "RetricSu/offckb";
18
- export declare const dappTemplateGitUrl = "https://github.com/RetricSu/offckb";
19
- export declare const dappTemplateGitBranch = "develop";
20
- export declare const dappTemplateGitFolder = "templates";
package/dist/cfg/const.js DELETED
@@ -1,51 +0,0 @@
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.dappTemplateGitFolder = exports.dappTemplateGitBranch = exports.dappTemplateGitUrl = exports.dappTemplateGitRepoUserAndName = exports.defaultLumosVersion = exports.minimalRequiredCKBVersion = exports.accountTargetDir = exports.deployedContractInfoFolderPath = exports.ckbBinPath = exports.ckbFolderPath = exports.devnetDataPath = exports.devnetPath = exports.devnetSourcePath = exports.userOffCKBConfigPath = exports.predefinedOffCKBConfigTsPath = exports.targetEnvironmentPath = exports.dappTemplatePath = exports.packageRootPath = exports.packageSrcPath = exports.currentExecPath = void 0;
27
- const path = __importStar(require("path"));
28
- // todo: move some to user settings
29
- // path
30
- exports.currentExecPath = process.cwd();
31
- exports.packageSrcPath = path.dirname(require.main.filename);
32
- exports.packageRootPath = path.resolve(exports.packageSrcPath, '../');
33
- exports.dappTemplatePath = path.resolve(exports.packageRootPath, './templates');
34
- exports.targetEnvironmentPath = path.resolve(exports.packageRootPath, './target');
35
- exports.predefinedOffCKBConfigTsPath = path.resolve(exports.dappTemplatePath, 'offckb.config.ts');
36
- exports.userOffCKBConfigPath = path.resolve(exports.currentExecPath, 'offckb.config.ts');
37
- exports.devnetSourcePath = path.resolve(exports.packageRootPath, './ckb/devnet');
38
- exports.devnetPath = path.resolve(exports.targetEnvironmentPath, `devnet`);
39
- exports.devnetDataPath = path.resolve(exports.devnetPath, `data`);
40
- exports.ckbFolderPath = path.resolve(exports.targetEnvironmentPath, 'ckb');
41
- exports.ckbBinPath = path.resolve(exports.ckbFolderPath, 'ckb');
42
- exports.deployedContractInfoFolderPath = path.resolve(exports.targetEnvironmentPath, 'contracts');
43
- exports.accountTargetDir = path.join(exports.packageRootPath, `account`);
44
- // Version
45
- exports.minimalRequiredCKBVersion = '0.113.1';
46
- exports.defaultLumosVersion = '0.21.0';
47
- // url
48
- exports.dappTemplateGitRepoUserAndName = 'RetricSu/offckb';
49
- exports.dappTemplateGitUrl = `https://github.com/${exports.dappTemplateGitRepoUserAndName}`;
50
- exports.dappTemplateGitBranch = 'develop';
51
- exports.dappTemplateGitFolder = 'templates';
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deployedScripts = void 0;
4
- const config_1 = require("../util/config");
5
- const type_1 = require("../util/type");
6
- const validator_1 = require("../util/validator");
7
- function deployedScripts(option = { network: type_1.Network.devnet }) {
8
- const network = option.network;
9
- (0, validator_1.validateNetworkOpt)(network);
10
- const scritpsInfo = (0, config_1.readUserDeployedScriptsInfo)(network);
11
- console.log(`User deployed scripts on ${network}`);
12
- console.log(JSON.stringify(scritpsInfo, null, 2));
13
- }
14
- exports.deployedScripts = deployedScripts;
@@ -1 +0,0 @@
1
- export declare function buildAccount(privKey: string): void;
@@ -1,9 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.buildAccount = void 0;
4
- const genkey_1 = require("./genkey");
5
- function buildAccount(privKey) {
6
- const account = (0, genkey_1.genAccount)(privKey);
7
- console.log(account);
8
- }
9
- exports.buildAccount = buildAccount;
@@ -1,14 +0,0 @@
1
- import { Address, HexString, Script } from '@ckb-lumos/lumos';
2
- interface Account {
3
- privkey: HexString;
4
- pubkey: HexString;
5
- args: HexString;
6
- lockScript: Script;
7
- address: Address;
8
- }
9
- export declare function genkey(): void;
10
- export declare function generateHex(length: number): string;
11
- export declare function buildAccounts(): Promise<void>;
12
- export declare function genAccount(privkey: HexString): Account;
13
- export declare function printIssueSectionForToml(): void;
14
- export {};
@@ -1,143 +0,0 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __asyncValues = (this && this.__asyncValues) || function (o) {
35
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
36
- var m = o[Symbol.asyncIterator], i;
37
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
38
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
39
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
40
- };
41
- Object.defineProperty(exports, "__esModule", { value: true });
42
- exports.printIssueSectionForToml = exports.genAccount = exports.buildAccounts = exports.generateHex = exports.genkey = void 0;
43
- const fs = __importStar(require("fs"));
44
- const path = __importStar(require("path"));
45
- const const_1 = require("../../cfg/const");
46
- const lumos_1 = require("@ckb-lumos/lumos");
47
- const readline = __importStar(require("readline"));
48
- function genkey() {
49
- const numKeys = 20; // Number of keys to generate
50
- const keyLength = 64; // Length of each key
51
- generateKeysFile(numKeys, keyLength);
52
- console.log(`Generated ${numKeys} keys in keys file.`);
53
- }
54
- exports.genkey = genkey;
55
- function generateHex(length) {
56
- const characters = 'abcdef0123456789';
57
- let result = '';
58
- for (let i = 0; i < length; i++) {
59
- result += characters[Math.floor(Math.random() * characters.length)];
60
- }
61
- return result;
62
- }
63
- exports.generateHex = generateHex;
64
- function generateKeysFile(numKeys, keyLength) {
65
- const targetDir = path.join(const_1.accountTargetDir, `keys`);
66
- const stream = fs.createWriteStream(targetDir);
67
- for (let i = 0; i < numKeys; i++) {
68
- const key = generateHex(keyLength);
69
- stream.write(key + '\n');
70
- }
71
- stream.end();
72
- }
73
- function buildAccounts() {
74
- var _a, e_1, _b, _c;
75
- return __awaiter(this, void 0, void 0, function* () {
76
- const keysDir = path.join(const_1.accountTargetDir, `keys`);
77
- // Create a Readable stream from the file
78
- const fileStream = fs.createReadStream(keysDir);
79
- // Create an interface for reading data from the stream line by line
80
- const rl = readline.createInterface({
81
- input: fileStream,
82
- crlfDelay: Infinity, // Specify Infinity to read all lines without removing newlines
83
- });
84
- const accounts = [];
85
- try {
86
- // Read each line from the file
87
- for (var _d = true, rl_1 = __asyncValues(rl), rl_1_1; rl_1_1 = yield rl_1.next(), _a = rl_1_1.done, !_a; _d = true) {
88
- _c = rl_1_1.value;
89
- _d = false;
90
- const line = _c;
91
- const privkey = `0x${line}`;
92
- const account = genAccount(privkey);
93
- accounts.push(account);
94
- }
95
- }
96
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
97
- finally {
98
- try {
99
- if (!_d && !_a && (_b = rl_1.return)) yield _b.call(rl_1);
100
- }
101
- finally { if (e_1) throw e_1.error; }
102
- }
103
- const accountDir = path.join(const_1.accountTargetDir, `account.json`);
104
- fs.writeFile(accountDir, JSON.stringify(accounts, null, 2), 'utf8', (err) => {
105
- if (err) {
106
- return console.error('Error writing file:', err);
107
- }
108
- });
109
- });
110
- }
111
- exports.buildAccounts = buildAccounts;
112
- function genAccount(privkey) {
113
- const pubkey = lumos_1.hd.key.privateToPublic(privkey);
114
- const args = lumos_1.hd.key.publicKeyToBlake160(pubkey);
115
- const lockScript = {
116
- codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
117
- hashType: 'type',
118
- args: args,
119
- };
120
- const address = lumos_1.helpers.encodeToAddress(lockScript);
121
- return {
122
- privkey,
123
- pubkey,
124
- lockScript,
125
- address,
126
- args,
127
- };
128
- }
129
- exports.genAccount = genAccount;
130
- function printIssueSectionForToml() {
131
- const config = require('../../account/account.json');
132
- for (const account of config) {
133
- const section = `# issue for account private key: ${account.privkey}
134
- [[genesis.issued_cells]]
135
- capacity = 42_000_000_00000000
136
- lock.code_hash = "${account.lockScript.codeHash}"
137
- lock.args = "${account.lockScript.args}"
138
- lock.hash_type = "${account.lockScript.hashType}"
139
- `;
140
- console.log(section);
141
- }
142
- }
143
- exports.printIssueSectionForToml = printIssueSectionForToml;
@@ -1,76 +0,0 @@
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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __importDefault = (this && this.__importDefault) || function (mod) {
35
- return (mod && mod.__esModule) ? mod : { "default": mod };
36
- };
37
- Object.defineProperty(exports, "__esModule", { value: true });
38
- exports.initChainIfNeeded = void 0;
39
- const fs = __importStar(require("fs"));
40
- const const_1 = require("../../cfg/const");
41
- const path_1 = __importDefault(require("path"));
42
- const fs_1 = require("../../util/fs");
43
- function initChainIfNeeded() {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- if (!(0, fs_1.isFolderExists)(const_1.devnetPath)) {
46
- yield doInitChain();
47
- }
48
- });
49
- }
50
- exports.initChainIfNeeded = initChainIfNeeded;
51
- function doInitChain() {
52
- return __awaiter(this, void 0, void 0, function* () {
53
- yield (0, fs_1.copyFilesWithExclusion)(const_1.devnetSourcePath, const_1.devnetPath, ['data']);
54
- console.debug(`init devnet config folder: ${const_1.devnetPath}`);
55
- copyAndEditMinerToml();
56
- });
57
- }
58
- function copyAndEditMinerToml() {
59
- const minerToml = path_1.default.join(const_1.devnetSourcePath, 'ckb-miner.toml');
60
- const newMinerToml = path_1.default.join(const_1.devnetPath, 'ckb-miner.toml');
61
- // Read the content of the ckb-miner.toml file
62
- fs.readFile(minerToml, 'utf8', (err, data) => {
63
- if (err) {
64
- return console.error('Error reading file:', err);
65
- }
66
- // Replace the URL
67
- const modifiedData = data.replace('http://ckb:8114/', 'http://localhost:8114');
68
- // Write the modified content back to the file
69
- fs.writeFile(newMinerToml, modifiedData, 'utf8', (err) => {
70
- if (err) {
71
- return console.error('Error writing file:', err);
72
- }
73
- console.debug('modified ', newMinerToml);
74
- });
75
- });
76
- }
@@ -1,4 +0,0 @@
1
- import { config } from '@ckb-lumos/lumos';
2
- export declare function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock: string, secondTxHashInGenesisBlock: string): config.Config;
3
- export declare function fetchDevnetLumosConfig(): Promise<config.Config>;
4
- export declare function writePredefinedDevnetLumosConfig(): Promise<void>;