@offckb/cli 0.1.0-rc2 → 0.1.0-rc4

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 (42) hide show
  1. package/README.md +55 -16
  2. package/{docker → ckb}/devnet/specs/dev.toml +1 -1
  3. package/dist/cfg/const.d.ts +1 -0
  4. package/dist/cfg/const.js +4 -3
  5. package/dist/cfg/select.d.ts +1 -0
  6. package/dist/cfg/select.js +52 -0
  7. package/dist/cli.js +37 -19
  8. package/dist/cmd/build-lumos-config.d.ts +2 -2
  9. package/dist/cmd/build-lumos-config.js +92 -69
  10. package/dist/cmd/clean.d.ts +1 -0
  11. package/dist/cmd/clean.js +21 -0
  12. package/dist/cmd/genkey.js +3 -7
  13. package/dist/cmd/init-chain.js +1 -43
  14. package/dist/cmd/init.d.ts +1 -1
  15. package/dist/cmd/init.js +10 -4
  16. package/dist/util.d.ts +5 -0
  17. package/dist/util.js +101 -1
  18. package/package.json +8 -8
  19. package/templates/transfer/index.html +13 -0
  20. package/templates/transfer/index.tsx +89 -0
  21. package/templates/xudt/lib.ts +153 -0
  22. package/templates/xudt/package.json +29 -0
  23. package/templates/xudt/tsconfig.json +10 -0
  24. package/templates/xudt/yarn.lock +2315 -0
  25. package/docker/docker-compose.yml +0 -37
  26. /package/{docker → ckb}/devnet/check-ckb-started-successfully.sh +0 -0
  27. /package/{docker → ckb}/devnet/ckb-miner.toml +0 -0
  28. /package/{docker → ckb}/devnet/ckb.toml +0 -0
  29. /package/{docker → ckb}/devnet/default.db-options +0 -0
  30. /package/{docker → ckb}/devnet/specs/always_success +0 -0
  31. /package/{docker → ckb}/devnet/specs/anyone_can_pay +0 -0
  32. /package/{docker → ckb}/devnet/specs/omni_lock +0 -0
  33. /package/{docker → ckb}/devnet/specs/sudt +0 -0
  34. /package/{docker → ckb}/devnet/specs/xudt_rce +0 -0
  35. /package/{template → templates}/ckb.ts +0 -0
  36. /package/{template → templates}/config.json +0 -0
  37. /package/{template → templates/transfer}/lib.ts +0 -0
  38. /package/{template → templates/transfer}/package.json +0 -0
  39. /package/{template → templates/transfer}/tsconfig.json +0 -0
  40. /package/{template → templates/transfer}/yarn.lock +0 -0
  41. /package/{template → templates/xudt}/index.html +0 -0
  42. /package/{template → templates/xudt}/index.tsx +0 -0
package/README.md CHANGED
@@ -1,34 +1,73 @@
1
1
  ## OffCKB
2
2
 
3
- ckb development environment for professionals
3
+ CKB local development environment for your first try
4
4
 
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- git clone https://github.com/RetricSu/offckb.git
9
- cd offckb && alias offckb='yarn start'
8
+ npm install -g @offckb/cli
10
9
  ```
11
10
 
12
- eventually you will do simple
11
+ ## Usage
12
+
13
13
  ```sh
14
- npm install -g offckb // not yet, todo
14
+ offckb node # start the devnet of CKB, `ctrl-c` to stop running the chain
15
+ offckb clean # clean the devnet data, needs to stop running the chain first
16
+
17
+ offckb init <project-name> # init a CKB Dapp typescript boilerplate from multiple templates
18
+
19
+ offckb accounts # list 20 accounts info with prefund CKB tokens
20
+ offckb list-hashes # list built-in scripts hashes, equals `ckb list-hashes`
15
21
  ```
16
22
 
17
- ## Usage
23
+ ### Get started
24
+
25
+ ```sh
26
+ offckb init my-awesome-ckb-dapp
27
+
28
+ ## select the template for your boilerplate
29
+ ? Select a dapp template (Use arrow keys)
30
+ ❯ Transfer CKB
31
+ Issue Coin With XUDT scripts
32
+ a simple dapp to check CKB balance and transfer CKB from address to address
33
+ init CKB dapp project: /Users/ckb/Desktop/offckb/my-awesome-ckb-dapp
34
+ ✨ Done in 7.52s.
35
+
36
+ ## start running
37
+ cd my-awesome-ckb-dapp
38
+ yarn && yarn start
39
+
40
+ ## results
41
+ yarn run v1.22.19
42
+ $ parcel index.html
43
+ Server running at http://localhost:1234
44
+ ✨ Built in 10ms
45
+ ```
46
+
47
+ open another terminal and start the devnet:
18
48
 
19
49
  ```sh
20
- offckb node // start the devnet of CKB
21
- offckb init // init a typescript boilerplate with lumos to get started with to build CKB DAPP,think 'hardhat init'
22
- offckb list-hashes // list scripts hashes, equals `ckb list-hashes`
23
- offckb accounts // list 20 accounts info with prefund CKB tokens
50
+ offckb node
24
51
  ```
25
52
 
53
+ open another terminal and check the accounts to use:
54
+
55
+ ```sh
56
+ offckb accounts
57
+ ```
58
+
59
+ Copy some private keys and visit http://localhost:1234 to play your first CKB Dapp!
60
+
26
61
  ### Built-in scripts
27
62
 
28
63
  - [x] xUDT https://github.com/nervosnetwork/rfcs/pull/428
64
+ - commit id: 410b16c
29
65
  - [x] Omnilock https://github.com/cryptape/omnilock
66
+ - commit id: cd764d7
30
67
  - [x] AnyoneCanPay https://github.com/cryptape/anyone-can-pay
68
+ - commit id: b845b3b
31
69
  - [x] AlwaysSuccess https://github.com/nervosnetwork/ckb-production-scripts/blob/master/c/always_success.c
70
+ - commit id: 410b16c
32
71
  - [ ] Spore https://github.com/sporeprotocol/spore-contract
33
72
 
34
73
  ### Accounts
@@ -38,11 +77,11 @@ offckb accounts // list 20 accounts info with prefund CKB tokens
38
77
  all the private keys are recorded in the `account/keys` file.
39
78
  detail informations about each account are recorded in the `account/account.json` file.
40
79
 
41
- ## Development
42
80
 
43
- update built-in scripts:
81
+ ## About Lumos
44
82
 
45
- update submodule inside `docker` and then run
46
- ```sh
47
- make all
48
- ```
83
+ `offckb` uses [Lumos](https://github.com/ckb-js/lumos) as the CKB Dapp framework to build the template projects.
84
+
85
+ ## Development
86
+
87
+ check [development doc](/docs/develop.md)
@@ -1,4 +1,4 @@
1
- name = "ckb_dev"
1
+ name = "offckb"
2
2
 
3
3
  [genesis]
4
4
  version = 0
@@ -5,6 +5,7 @@ export declare const dappTemplatePath: string;
5
5
  export declare const targetEnvironmentPath: string;
6
6
  export declare const devnetSourcePath: string;
7
7
  export declare const devnetPath: string;
8
+ export declare const devnetDataPath: string;
8
9
  export declare const ckbFolderPath: string;
9
10
  export declare const ckbBinPath: string;
10
11
  export declare const accountTargetDir: string;
package/dist/cfg/const.js CHANGED
@@ -23,16 +23,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.minimalRequiredCKBVersion = exports.accountTargetDir = exports.ckbBinPath = exports.ckbFolderPath = exports.devnetPath = exports.devnetSourcePath = exports.targetEnvironmentPath = exports.dappTemplatePath = exports.packageRootPath = exports.packageSrcPath = exports.currentExecPath = void 0;
26
+ exports.minimalRequiredCKBVersion = exports.accountTargetDir = exports.ckbBinPath = exports.ckbFolderPath = exports.devnetDataPath = exports.devnetPath = exports.devnetSourcePath = exports.targetEnvironmentPath = exports.dappTemplatePath = exports.packageRootPath = exports.packageSrcPath = exports.currentExecPath = void 0;
27
27
  const path = __importStar(require("path"));
28
28
  // path
29
29
  exports.currentExecPath = process.cwd();
30
30
  exports.packageSrcPath = path.dirname(require.main.filename);
31
31
  exports.packageRootPath = path.resolve(exports.packageSrcPath, '../');
32
- exports.dappTemplatePath = path.resolve(exports.packageRootPath, './template');
32
+ exports.dappTemplatePath = path.resolve(exports.packageRootPath, './templates');
33
33
  exports.targetEnvironmentPath = path.resolve(exports.packageRootPath, './target');
34
- exports.devnetSourcePath = path.resolve(exports.packageRootPath, './docker/devnet');
34
+ exports.devnetSourcePath = path.resolve(exports.packageRootPath, './ckb/devnet');
35
35
  exports.devnetPath = path.resolve(exports.targetEnvironmentPath, `devnet`);
36
+ exports.devnetDataPath = path.resolve(exports.devnetPath, `data`);
36
37
  exports.ckbFolderPath = path.resolve(exports.targetEnvironmentPath, 'ckb');
37
38
  exports.ckbBinPath = path.resolve(exports.ckbFolderPath, 'ckb');
38
39
  exports.accountTargetDir = path.join(exports.packageRootPath, `account`);
@@ -0,0 +1 @@
1
+ export declare function selectTemplate(): Promise<string>;
@@ -0,0 +1,52 @@
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.selectTemplate = void 0;
16
+ const prompts_1 = require("@inquirer/prompts");
17
+ const select_1 = __importDefault(require("@inquirer/select"));
18
+ function selectTemplate() {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const answer = yield (0, select_1.default)({
21
+ message: 'Select a dapp template',
22
+ choices: [
23
+ {
24
+ name: 'Transfer CKB',
25
+ value: 'transfer',
26
+ description: 'a simple dapp to check CKB balance and transfer CKB from address to address',
27
+ },
28
+ new prompts_1.Separator(),
29
+ {
30
+ name: 'Issue Token With XUDT scripts(coming)',
31
+ value: 'xudt',
32
+ description: 'a simple dapp to issue your own token with XUDT scripts(coming)',
33
+ disabled: true,
34
+ },
35
+ {
36
+ name: 'Issue Token With Max Supply via Omnilock And XUDT scripts(coming)',
37
+ value: 'xudt',
38
+ description: 'a simple dapp to issue your own token with XUDT scripts',
39
+ disabled: true,
40
+ },
41
+ {
42
+ name: 'Create NFT With Spore scripts(coming)',
43
+ value: 'xudt',
44
+ description: 'a simple dapp to issue your own token with XUDT scripts',
45
+ disabled: true,
46
+ },
47
+ ],
48
+ });
49
+ return answer;
50
+ });
51
+ }
52
+ exports.selectTemplate = selectTemplate;
package/dist/cli.js CHANGED
@@ -1,5 +1,14 @@
1
1
  #!/usr/bin/env node
2
2
  "use strict";
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
5
+ return new (P || (P = Promise))(function (resolve, reject) {
6
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
7
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
8
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
9
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
10
+ });
11
+ };
3
12
  Object.defineProperty(exports, "__esModule", { value: true });
4
13
  const commander_1 = require("commander");
5
14
  const install_1 = require("./cmd/install");
@@ -10,33 +19,42 @@ const init_chain_1 = require("./cmd/init-chain");
10
19
  const build_lumos_config_1 = require("./cmd/build-lumos-config");
11
20
  const init_1 = require("./cmd/init");
12
21
  const accounts_1 = require("./cmd/accounts");
22
+ const select_1 = require("./cfg/select");
23
+ const clean_1 = require("./cmd/clean");
13
24
  const version = require('../package.json').version;
14
25
  const program = new commander_1.Command();
15
26
  program
16
27
  .name('offckb')
17
28
  .description('CLI to provide full ckb development environment for professionals')
18
29
  .version(version);
19
- // Define the CLI commands and options
20
- program.command('install').description('Install the ckb dependency binary').action(install_1.installDependency);
21
- program.command('genkey').description('generate 20 accounts').action(genkey_1.genkey);
22
- program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(list_hashes_1.listHashes);
23
- program.command('node').description('Use the CKB to start devnet').action(node_1.node);
24
- program.command('init-chain').description('Use the CKB to init devnet').action(init_chain_1.initChainIfNeeded);
25
- program.command('build-lumos-config').description('Use the CKB to generate lumos config.json').action(build_lumos_config_1.buildLumosConfig);
26
- program.command('build-accounts').description('generate accounts with prefunded CKB tokens').action(genkey_1.buildAccounts);
27
- program
28
- .command('print-account-issue-info')
29
- .description('print account issue cells config toml sections')
30
- .action(genkey_1.printIssueSectionForToml);
31
- program.command('accounts').description('print account list info').action(accounts_1.accounts);
32
30
  program
33
- .command('init')
31
+ .command('init [string]')
34
32
  .description('init dapp project with lumos')
35
- .argument('<string>', 'name of the dapp')
36
- .action((str) => {
37
- const name = str !== null && str !== void 0 ? str : 'offckb-dapp';
38
- return (0, init_1.init)(name);
39
- });
33
+ .action((str) => __awaiter(void 0, void 0, void 0, function* () {
34
+ const name = str !== null && str !== void 0 ? str : 'my-awesome-ckb-dapp';
35
+ const template = yield (0, select_1.selectTemplate)();
36
+ return (0, init_1.init)(name, template);
37
+ }));
38
+ program.command('node').description('Use the CKB to start devnet').action(node_1.node);
39
+ program.command('clean').description('Clean the devnet data, need to stop running the chain first').action(clean_1.clean);
40
+ program.command('accounts').description('print account list info').action(accounts_1.accounts);
41
+ program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(list_hashes_1.listHashes);
42
+ // Add commands meant for developers
43
+ if (process.env.NODE_ENV === 'development') {
44
+ // Define the CLI commands and options
45
+ program.command('install').description('Install the ckb dependency binary').action(install_1.installDependency);
46
+ program.command('genkey').description('generate 20 accounts').action(genkey_1.genkey);
47
+ program.command('init-chain').description('Use the CKB to init devnet').action(init_chain_1.initChainIfNeeded);
48
+ program
49
+ .command('build-lumos-config')
50
+ .description('Use the CKB to generate lumos config.json')
51
+ .action(build_lumos_config_1.buildLumosConfig);
52
+ program.command('build-accounts').description('generate accounts with prefunded CKB tokens').action(genkey_1.buildAccounts);
53
+ program
54
+ .command('print-account-issue-info')
55
+ .description('print account issue cells config toml sections')
56
+ .action(genkey_1.printIssueSectionForToml);
57
+ }
40
58
  // Parse command-line arguments
41
59
  program.parse(process.argv);
42
60
  // If no command is specified, display help
@@ -1,4 +1,4 @@
1
- export declare const devnetConfig: {
1
+ export declare function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock: string, secondTxHashInGenesisBlock: string): {
2
2
  PREFIX: string;
3
3
  SCRIPTS: {
4
4
  SECP256K1_BLAKE160: {
@@ -61,4 +61,4 @@ export declare const devnetConfig: {
61
61
  };
62
62
  };
63
63
  };
64
- export declare function buildLumosConfig(): void;
64
+ export declare function buildLumosConfig(): Promise<void>;
@@ -1,82 +1,105 @@
1
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
+ };
2
11
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
12
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
13
  };
5
14
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.buildLumosConfig = exports.devnetConfig = void 0;
15
+ exports.buildLumosConfig = exports.devnetLumosConfigTemplate = void 0;
7
16
  const fs_1 = __importDefault(require("fs"));
8
17
  const path_1 = __importDefault(require("path"));
9
18
  const const_1 = require("../cfg/const");
10
- const genesisTxHash = '0x920bb4250dc6216c08ee0713f86b3fcb01bf444027b08b7d92db0ed1c0fb9214';
11
- const depGroupTxHash = '0x37f2b7799b199491f4732c572c086afdace0bf92992faf0b90bae44cdd119f9e';
12
- exports.devnetConfig = {
13
- PREFIX: 'ckt',
14
- SCRIPTS: {
15
- SECP256K1_BLAKE160: {
16
- CODE_HASH: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
17
- HASH_TYPE: 'type',
18
- TX_HASH: depGroupTxHash,
19
- INDEX: '0x0',
20
- DEP_TYPE: 'depGroup',
21
- SHORT_ID: 1,
22
- },
23
- SECP256K1_BLAKE160_MULTISIG: {
24
- CODE_HASH: '0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8',
25
- HASH_TYPE: 'type',
26
- TX_HASH: depGroupTxHash,
27
- INDEX: '0x1',
28
- DEP_TYPE: 'depGroup',
29
- },
30
- DAO: {
31
- CODE_HASH: '0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e',
32
- HASH_TYPE: 'type',
33
- TX_HASH: genesisTxHash,
34
- INDEX: '0x2',
35
- DEP_TYPE: 'code',
36
- SHORT_ID: 2,
37
- },
38
- SUDT: {
39
- CODE_HASH: '0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd',
40
- HASH_TYPE: 'type',
41
- TX_HASH: genesisTxHash,
42
- INDEX: '0x5',
43
- DEP_TYPE: 'code',
44
- },
45
- XUDT: {
46
- CODE_HASH: '0x1a1e4fef34f5982906f745b048fe7b1089647e82346074e0f32c2ece26cf6b1e',
47
- HASH_TYPE: 'type',
48
- TX_HASH: genesisTxHash,
49
- INDEX: '0x6',
50
- DEP_TYPE: 'code',
19
+ const lumos_1 = require("@ckb-lumos/lumos");
20
+ function devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInGenesisBlock) {
21
+ const devnetConfig = {
22
+ PREFIX: 'ckt',
23
+ SCRIPTS: {
24
+ SECP256K1_BLAKE160: {
25
+ CODE_HASH: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
26
+ HASH_TYPE: 'type',
27
+ TX_HASH: secondTxHashInGenesisBlock,
28
+ INDEX: '0x0',
29
+ DEP_TYPE: 'depGroup',
30
+ SHORT_ID: 1,
31
+ },
32
+ SECP256K1_BLAKE160_MULTISIG: {
33
+ CODE_HASH: '0x5c5069eb0857efc65e1bca0c07df34c31663b3622fd3876c876320fc9634e2a8',
34
+ HASH_TYPE: 'type',
35
+ TX_HASH: secondTxHashInGenesisBlock,
36
+ INDEX: '0x1',
37
+ DEP_TYPE: 'depGroup',
38
+ },
39
+ DAO: {
40
+ CODE_HASH: '0x82d76d1b75fe2fd9a27dfbaa65a039221a380d76c926f378d3f81cf3e7e13f2e',
41
+ HASH_TYPE: 'type',
42
+ TX_HASH: cellBaseTxHashInGenesisBlock,
43
+ INDEX: '0x2',
44
+ DEP_TYPE: 'code',
45
+ SHORT_ID: 2,
46
+ },
47
+ SUDT: {
48
+ CODE_HASH: '0x6283a479a3cf5d4276cd93594de9f1827ab9b55c7b05b3d28e4c2e0a696cfefd',
49
+ HASH_TYPE: 'type',
50
+ TX_HASH: cellBaseTxHashInGenesisBlock,
51
+ INDEX: '0x5',
52
+ DEP_TYPE: 'code',
53
+ },
54
+ XUDT: {
55
+ CODE_HASH: '0x1a1e4fef34f5982906f745b048fe7b1089647e82346074e0f32c2ece26cf6b1e',
56
+ HASH_TYPE: 'type',
57
+ TX_HASH: cellBaseTxHashInGenesisBlock,
58
+ INDEX: '0x6',
59
+ DEP_TYPE: 'code',
60
+ },
61
+ OMNILOCK: {
62
+ CODE_HASH: '0x9c6933d977360f115a3e9cd5a2e0e475853681b80d775d93ad0f8969da343e56',
63
+ HASH_TYPE: 'type',
64
+ TX_HASH: cellBaseTxHashInGenesisBlock,
65
+ INDEX: '0x7',
66
+ DEP_TYPE: 'code',
67
+ },
68
+ ANYONE_CAN_PAY: {
69
+ CODE_HASH: '0xe09352af0066f3162287763ce4ddba9af6bfaeab198dc7ab37f8c71c9e68bb5b',
70
+ HASH_TYPE: 'type',
71
+ TX_HASH: cellBaseTxHashInGenesisBlock,
72
+ INDEX: '0x8',
73
+ DEP_TYPE: 'code',
74
+ },
75
+ ALWAYS_SUCCESS: {
76
+ CODE_HASH: '0xbb4469004225b39e983929db71fe2253cba1d49a76223e9e1d212cdca1f79f28',
77
+ HASH_TYPE: 'type',
78
+ TX_HASH: cellBaseTxHashInGenesisBlock,
79
+ INDEX: '0x9',
80
+ DEP_TYPE: 'code',
81
+ },
51
82
  },
52
- OMNILOCK: {
53
- CODE_HASH: '0x9c6933d977360f115a3e9cd5a2e0e475853681b80d775d93ad0f8969da343e56',
54
- HASH_TYPE: 'type',
55
- TX_HASH: genesisTxHash,
56
- INDEX: '0x7',
57
- DEP_TYPE: 'code',
58
- },
59
- ANYONE_CAN_PAY: {
60
- CODE_HASH: '0xe09352af0066f3162287763ce4ddba9af6bfaeab198dc7ab37f8c71c9e68bb5b',
61
- HASH_TYPE: 'type',
62
- TX_HASH: genesisTxHash,
63
- INDEX: '0x8',
64
- DEP_TYPE: 'code',
65
- },
66
- ALWAYS_SUCCESS: {
67
- CODE_HASH: '0xbb4469004225b39e983929db71fe2253cba1d49a76223e9e1d212cdca1f79f28',
68
- HASH_TYPE: 'type',
69
- TX_HASH: genesisTxHash,
70
- INDEX: '0x9',
71
- DEP_TYPE: 'code',
72
- },
73
- },
74
- };
83
+ };
84
+ return devnetConfig;
85
+ }
86
+ exports.devnetLumosConfigTemplate = devnetLumosConfigTemplate;
75
87
  function buildLumosConfig() {
76
- const filePath = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
77
- fs_1.default.writeFile(filePath, JSON.stringify(exports.devnetConfig, null, 2), 'utf8', (err) => {
78
- if (err) {
79
- return console.error('Error writing file:', err);
88
+ return __awaiter(this, void 0, void 0, function* () {
89
+ const rpcUrl = 'http://127.0.0.1:8114';
90
+ const rpc = new lumos_1.RPC(rpcUrl);
91
+ const chainInfo = yield rpc.getBlockchainInfo();
92
+ const genesisBlock = yield rpc.getBlockByNumber('0x0');
93
+ const cellBaseTxHashInGenesisBlock = genesisBlock.transactions[0].hash;
94
+ const secondTxHashInGenesisBlock = genesisBlock.transactions[1].hash;
95
+ if (chainInfo.chain === 'offckb') {
96
+ const config = devnetLumosConfigTemplate(cellBaseTxHashInGenesisBlock, secondTxHashInGenesisBlock);
97
+ const filePath = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
98
+ fs_1.default.writeFile(filePath, JSON.stringify(config, null, 2), 'utf8', (err) => {
99
+ if (err) {
100
+ return console.error('Error writing file:', err);
101
+ }
102
+ });
80
103
  }
81
104
  });
82
105
  }
@@ -0,0 +1 @@
1
+ export declare function clean(): void;
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.clean = void 0;
4
+ const const_1 = require("../cfg/const");
5
+ const util_1 = require("../util");
6
+ function clean() {
7
+ if ((0, util_1.isFolderExists)(const_1.devnetDataPath)) {
8
+ try {
9
+ (0, util_1.removeFolderSync)(const_1.devnetDataPath);
10
+ console.log(`Chain data cleaned.`);
11
+ }
12
+ catch (error) {
13
+ console.log(`Did you stop running the chain first?`);
14
+ console.log(error.message);
15
+ }
16
+ }
17
+ else {
18
+ console.log(`${const_1.devnetDataPath} not found, unable to clean it.`);
19
+ }
20
+ }
21
+ exports.clean = clean;
@@ -45,7 +45,6 @@ const path = __importStar(require("path"));
45
45
  const const_1 = require("../cfg/const");
46
46
  const lumos_1 = require("@ckb-lumos/lumos");
47
47
  const readline = __importStar(require("readline"));
48
- const build_lumos_config_1 = require("./build-lumos-config");
49
48
  function genkey() {
50
49
  const numKeys = 20; // Number of keys to generate
51
50
  const keyLength = 64; // Length of each key
@@ -112,15 +111,12 @@ exports.buildAccounts = buildAccounts;
112
111
  function genAccount(privkey) {
113
112
  const pubkey = lumos_1.hd.key.privateToPublic(privkey);
114
113
  const args = lumos_1.hd.key.publicKeyToBlake160(pubkey);
115
- const template = build_lumos_config_1.devnetConfig.SCRIPTS['SECP256K1_BLAKE160'];
116
114
  const lockScript = {
117
- codeHash: template.CODE_HASH,
118
- hashType: template.HASH_TYPE,
115
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
116
+ hashType: 'type',
119
117
  args: args,
120
118
  };
121
- const address = lumos_1.helpers.encodeToAddress(lockScript, {
122
- config: build_lumos_config_1.devnetConfig,
123
- });
119
+ const address = lumos_1.helpers.encodeToAddress(lockScript);
124
120
  return {
125
121
  privkey,
126
122
  pubkey,
@@ -50,7 +50,7 @@ function initChainIfNeeded() {
50
50
  exports.initChainIfNeeded = initChainIfNeeded;
51
51
  function doInitChain() {
52
52
  return __awaiter(this, void 0, void 0, function* () {
53
- yield copyFilesWithExclusion(const_1.devnetSourcePath, const_1.devnetPath, ['data']);
53
+ yield (0, util_1.copyFilesWithExclusion)(const_1.devnetSourcePath, const_1.devnetPath, ['data']);
54
54
  console.debug(`init devnet config folder: ${const_1.devnetPath}`);
55
55
  copyAndEditMinerToml();
56
56
  });
@@ -74,45 +74,3 @@ function copyAndEditMinerToml() {
74
74
  });
75
75
  });
76
76
  }
77
- function copyFilesWithExclusion(sourceDir, destinationDir, excludedFolders) {
78
- return __awaiter(this, void 0, void 0, function* () {
79
- try {
80
- // Ensure the destination directory exists
81
- yield fs.promises.mkdir(destinationDir, { recursive: true });
82
- // Start copying recursively from the source directory
83
- yield copyRecursive(sourceDir, destinationDir, excludedFolders);
84
- }
85
- catch (error) {
86
- console.error('An error occurred during copying files:', error);
87
- }
88
- });
89
- }
90
- // Function to recursively copy files and directories
91
- function copyRecursive(source, destination, excludedFolders) {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- // Get a list of all files and directories in the source directory
94
- const files = yield fs.promises.readdir(source);
95
- // Iterate through each file or directory
96
- for (const file of files) {
97
- const sourcePath = path_1.default.join(source, file);
98
- const destPath = path_1.default.join(destination, file);
99
- // Get the file's stats
100
- const stats = yield fs.promises.stat(sourcePath);
101
- // If it's a directory, recursively copy it (unless it's excluded)
102
- if (stats.isDirectory()) {
103
- if (excludedFolders.includes(file)) {
104
- // Skipping directory: ${sourcePath}
105
- }
106
- else {
107
- // Ensure destination directory exists before copying
108
- yield fs.promises.mkdir(destPath, { recursive: true });
109
- yield copyRecursive(sourcePath, destPath, excludedFolders);
110
- }
111
- }
112
- else {
113
- // Otherwise, copy the file
114
- yield fs.promises.copyFile(sourcePath, destPath);
115
- }
116
- }
117
- });
118
- }
@@ -1 +1 @@
1
- export declare function init(name: string): void;
1
+ export declare function init(name: string, template: string): void;
package/dist/cmd/init.js CHANGED
@@ -4,12 +4,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = void 0;
7
- const child_process_1 = require("child_process");
8
7
  const const_1 = require("../cfg/const");
9
8
  const path_1 = __importDefault(require("path"));
10
- function init(name) {
9
+ const util_1 = require("../util");
10
+ function init(name, template) {
11
11
  const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
12
- (0, child_process_1.execSync)(`cp -r ${const_1.dappTemplatePath} ${targetPath}`);
13
- console.log(`init CKB dapp project with lumos: ${targetPath}`);
12
+ const sourcePath = path_1.default.resolve(const_1.dappTemplatePath, template);
13
+ (0, util_1.copyFolderSync)(sourcePath, targetPath);
14
+ // add some common code files
15
+ const ckbDotTs = path_1.default.resolve(const_1.dappTemplatePath, 'ckb.ts');
16
+ const configJson = path_1.default.resolve(const_1.dappTemplatePath, 'config.json');
17
+ (0, util_1.copyFileSync)(ckbDotTs, targetPath);
18
+ (0, util_1.copyFileSync)(configJson, targetPath);
19
+ console.log(`init CKB dapp project: ${targetPath}`);
14
20
  }
15
21
  exports.init = init;
package/dist/util.d.ts CHANGED
@@ -1 +1,6 @@
1
1
  export declare function isFolderExists(folderPath: string): boolean;
2
+ export declare function copyFolderSync(source: string, destination: string): void;
3
+ export declare function copyFileSync(source: string, target: string): void;
4
+ export declare function copyFilesWithExclusion(sourceDir: string, destinationDir: string, excludedFolders: string[]): Promise<void>;
5
+ export declare function copyRecursive(source: string, destination: string, excludedFolders: string[]): Promise<void>;
6
+ export declare function removeFolderSync(folderPath: string): void;