@offckb/cli 0.1.0-rc3 → 0.1.0-rc5

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 (48) hide show
  1. package/README.md +87 -16
  2. package/{docker → ckb}/devnet/specs/dev.toml +16 -2
  3. package/ckb/devnet/specs/spore-scripts/cluster +0 -0
  4. package/ckb/devnet/specs/spore-scripts/cluster_agent +0 -0
  5. package/ckb/devnet/specs/spore-scripts/cluster_proxy +0 -0
  6. package/ckb/devnet/specs/spore-scripts/spore +0 -0
  7. package/ckb/devnet/specs/spore-scripts/spore_extension_lua +0 -0
  8. package/dist/cfg/const.d.ts +1 -0
  9. package/dist/cfg/const.js +4 -3
  10. package/dist/cfg/select.d.ts +1 -0
  11. package/dist/cfg/select.js +51 -0
  12. package/dist/cli.js +34 -16
  13. package/dist/cmd/build-lumos-config.d.ts +2 -2
  14. package/dist/cmd/build-lumos-config.js +92 -69
  15. package/dist/cmd/clean.d.ts +1 -0
  16. package/dist/cmd/clean.js +21 -0
  17. package/dist/cmd/genkey.js +3 -7
  18. package/dist/cmd/init-chain.js +1 -43
  19. package/dist/cmd/init.d.ts +1 -1
  20. package/dist/cmd/init.js +10 -4
  21. package/dist/util.d.ts +5 -0
  22. package/dist/util.js +101 -1
  23. package/package.json +9 -9
  24. package/{template → templates}/config.json +8 -8
  25. package/templates/transfer/index.html +13 -0
  26. package/{template → templates/transfer}/index.tsx +38 -4
  27. package/{template → templates/xudt}/index.html +1 -1
  28. package/templates/xudt/index.tsx +106 -0
  29. package/templates/xudt/lib.ts +179 -0
  30. package/templates/xudt/package.json +29 -0
  31. package/templates/xudt/scheme.ts +27 -0
  32. package/templates/xudt/tsconfig.json +10 -0
  33. package/templates/xudt/yarn.lock +2315 -0
  34. package/docker/docker-compose.yml +0 -37
  35. /package/{docker → ckb}/devnet/check-ckb-started-successfully.sh +0 -0
  36. /package/{docker → ckb}/devnet/ckb-miner.toml +0 -0
  37. /package/{docker → ckb}/devnet/ckb.toml +0 -0
  38. /package/{docker → ckb}/devnet/default.db-options +0 -0
  39. /package/{docker → ckb}/devnet/specs/always_success +0 -0
  40. /package/{docker → ckb}/devnet/specs/anyone_can_pay +0 -0
  41. /package/{docker → ckb}/devnet/specs/omni_lock +0 -0
  42. /package/{docker → ckb}/devnet/specs/sudt +0 -0
  43. /package/{docker → ckb}/devnet/specs/xudt_rce +0 -0
  44. /package/{template → templates}/ckb.ts +0 -0
  45. /package/{template → templates/transfer}/lib.ts +0 -0
  46. /package/{template → templates/transfer}/package.json +0 -0
  47. /package/{template → templates/transfer}/tsconfig.json +0 -0
  48. /package/{template → templates/transfer}/yarn.lock +0 -0
package/README.md CHANGED
@@ -1,6 +1,32 @@
1
1
  ## OffCKB
2
2
 
3
- ckb development environment for professionals
3
+ [![npm](https://img.shields.io/npm/v/@offckb/cli.svg?maxAge=1000)](https://www.npmjs.com/package/@offckb/cli)
4
+ [![CI](https://github.com/retricsu/offckb/actions/workflows/node.js.yml/badge.svg)](https://github.com/retricsu/offckb/actions/workflows/node.js.yml)
5
+ [![npm](https://img.shields.io/npm/dt/@offckb/cli.svg?maxAge=1000)](https://www.npmjs.com/package/@offckb/cli)
6
+ [![npm](https://img.shields.io/npm/l/@offckb/cli.svg?maxAge=1000)](https://github.com/jeffijoe/@offckb/cli/blob/master/LICENSE.md)
7
+ [![node](https://img.shields.io/node/v/@offckb/cli.svg?maxAge=1000)](https://www.npmjs.com/package/@offckb/cli)
8
+
9
+ **CKB local development network for your first try.**
10
+
11
+ - One-line command to start a devnet
12
+ - no docker required
13
+ - pre-funded test accounts
14
+ - packed with the most useful scripts like Omnilock and Spore-contract
15
+ - multiple minimal Dapp templates to learn and get your hands dirty
16
+
17
+ Start building on Nervos blockchain, right now, right away!
18
+
19
+ ## Table of Contents
20
+
21
+ - [OffCKB](#offckb)
22
+ - [Table of Contents](#table-of-contents)
23
+ - [Install](#install)
24
+ - [Usage](#usage)
25
+ - [Get started](#get-started)
26
+ - [Built-in scripts](#built-in-scripts)
27
+ - [Accounts](#accounts)
28
+ - [About Lumos](#about-lumos)
29
+ - [Contributing](#contributing)
4
30
 
5
31
  ## Install
6
32
 
@@ -11,16 +37,29 @@ npm install -g @offckb/cli
11
37
  ## Usage
12
38
 
13
39
  ```sh
14
- offckb node // start the devnet of CKB
15
- offckb init <project-name> // init a typescript boilerplate with lumos to get started with to build CKB DAPP,think 'hardhat init'
16
- offckb accounts // list 20 accounts info with prefund CKB tokens
17
- offckb list-hashes // list scripts hashes, equals `ckb list-hashes`
40
+ offckb node # start the devnet of CKB, `ctrl-c` to stop running the chain
41
+ offckb clean # clean the devnet data, needs to stop running the chain first
42
+
43
+ offckb init <project-name> # init a CKB Dapp typescript boilerplate from multiple templates
44
+
45
+ offckb accounts # list 20 accounts info with prefund CKB tokens
46
+ offckb list-hashes # list built-in scripts hashes, equals `ckb list-hashes`
18
47
  ```
19
48
 
20
- ### Get started
49
+ ## Get started
21
50
 
22
51
  ```sh
23
52
  offckb init my-awesome-ckb-dapp
53
+
54
+ ## select the template for your boilerplate
55
+ ? Select a dapp template (Use arrow keys)
56
+ ❯ Transfer CKB
57
+ Issue Coin With XUDT scripts
58
+ a simple dapp to check CKB balance and transfer CKB from address to address
59
+ init CKB dapp project: /Users/ckb/Desktop/offckb/my-awesome-ckb-dapp
60
+ ✨ Done in 7.52s.
61
+
62
+ ## start running
24
63
  cd my-awesome-ckb-dapp
25
64
  yarn && yarn start
26
65
 
@@ -35,36 +74,68 @@ open another terminal and start the devnet:
35
74
 
36
75
  ```sh
37
76
  offckb node
77
+
78
+ # result
79
+ # ...
80
+ CKB-Miner: 2024-03-04 14:35:12.563 +00:00 client INFO ckb_miner::miner Found! #3181 0x3749481a320824fe21077eaa8ec9d024a7b62d031720c27c1ef1681e8ab349e8
81
+
82
+ CKB-Miner: 2024-03-04 14:35:17.567 +00:00 client INFO ckb_miner::miner Found! #3184 0xa612a9ea35f292a6473e23e88856283aea8b1bc6a607147bef5c06c94e964f2f
83
+ #...
38
84
  ```
39
85
 
40
86
  open another terminal and check the accounts to use:
41
87
 
42
88
  ```sh
43
89
  offckb accounts
90
+
91
+ # result
92
+ Print account list, each account is funded with 42_000_000_00000000 capacity in the genesis block.
93
+ [
94
+ {
95
+ privkey: '0x6109170b275a09ad54877b82f7d9930f88cab5717d484fb4741ae9d1dd078cd6',
96
+ pubkey: '0x02025fa7b61b2365aa459807b84df065f1949d58c0ae590ff22dd2595157bffefa',
97
+ lockScript: {
98
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
99
+ hashType: 'type',
100
+ args: '0x8e42b1999f265a0078503c4acec4d5e134534297'
101
+ },
102
+ address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvwg2cen8extgq8s5puft8vf40px3f599cytcyd8',
103
+ args: '0x8e42b1999f265a0078503c4acec4d5e134534297'
104
+ },
105
+ {
106
+ privkey: '0x9f315d5a9618a39fdc487c7a67a8581d40b045bd7a42d83648ca80ef3b2cb4a1',
107
+ pubkey: '0x026efa0579f09cc7c1129b78544f70098c90b2ab155c10746316f945829c034a2d',
108
+ lockScript: {
44
109
  ```
45
110
 
46
- Copy some private keys and visit http://localhost:1234 to play basic CKB transfer!
111
+ Copy some private keys and visit http://localhost:1234 to play your first CKB Dapp!
47
112
 
48
- ### Built-in scripts
113
+ ## Built-in scripts
49
114
 
50
115
  - [x] xUDT https://github.com/nervosnetwork/rfcs/pull/428
116
+ - commit id: 410b16c
51
117
  - [x] Omnilock https://github.com/cryptape/omnilock
118
+ - commit id: cd764d7
52
119
  - [x] AnyoneCanPay https://github.com/cryptape/anyone-can-pay
120
+ - commit id: b845b3b
53
121
  - [x] AlwaysSuccess https://github.com/nervosnetwork/ckb-production-scripts/blob/master/c/always_success.c
54
- - [ ] Spore https://github.com/sporeprotocol/spore-contract
122
+ - commit id: 410b16c
123
+ - [x] Spore https://github.com/sporeprotocol/spore-contract
124
+ - version: 0.2.2-beta.1
55
125
 
56
- ### Accounts
126
+ ## Accounts
57
127
 
58
128
  `offckb` comes with 20 accounts, each account is funded with 42_000_000_00000000 capacity in the genesis block.
59
129
 
60
130
  all the private keys are recorded in the `account/keys` file.
61
131
  detail informations about each account are recorded in the `account/account.json` file.
62
132
 
63
- ## Development
133
+ :warning: **DO NOT SEND REAL ASSETS INTO ALL THESE ACCOUNTS, YOU CAN LOOSE YOUR MONEY** :warning:
64
134
 
65
- update built-in scripts:
135
+ ## About Lumos
66
136
 
67
- update submodule inside `docker` and then run
68
- ```sh
69
- make all
70
- ```
137
+ `offckb` uses [Lumos](https://github.com/ckb-js/lumos) as the CKB Dapp framework to build the template projects.
138
+
139
+ ## Contributing
140
+
141
+ 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
@@ -49,7 +49,21 @@ create_type_id = true
49
49
  [[genesis.system_cells]]
50
50
  file = { file = "always_success" }
51
51
  create_type_id = true
52
-
52
+ [[genesis.system_cells]]
53
+ file = { file = "spore-scripts/spore" }
54
+ create_type_id = false
55
+ [[genesis.system_cells]]
56
+ file = { file = "spore-scripts/cluster" }
57
+ create_type_id = false
58
+ [[genesis.system_cells]]
59
+ file = { file = "spore-scripts/cluster_agent" }
60
+ create_type_id = false
61
+ [[genesis.system_cells]]
62
+ file = { file = "spore-scripts/cluster_proxy" }
63
+ create_type_id = false
64
+ [[genesis.system_cells]]
65
+ file = { file = "spore-scripts/spore_extension_lua" }
66
+ create_type_id = false
53
67
 
54
68
  [genesis.system_cells_lock]
55
69
  code_hash = "0x0000000000000000000000000000000000000000000000000000000000000000"
@@ -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,51 @@
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: 'View and Transfer Balance',
25
+ value: 'transfer',
26
+ description: 'a simple dapp to check CKB balance and transfer CKB',
27
+ },
28
+ {
29
+ name: 'Issue Token via XUDT scripts',
30
+ value: 'xudt',
31
+ description: 'a simple dapp to issue your own token via XUDT scripts',
32
+ },
33
+ new prompts_1.Separator(),
34
+ {
35
+ name: 'Issue Token With Max Supply Limit via Omnilock And XUDT scripts(coming)',
36
+ value: 'xudt',
37
+ description: 'a simple dapp to issue your own token with max supply limit via XUDT scripts',
38
+ disabled: true,
39
+ },
40
+ {
41
+ name: 'Create NFT With Spore scripts(coming)',
42
+ value: 'xudt',
43
+ description: 'a simple dapp to issue your own token with XUDT scripts',
44
+ disabled: true,
45
+ },
46
+ ],
47
+ });
48
+ return answer;
49
+ });
50
+ }
51
+ 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,6 +19,8 @@ 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
@@ -17,26 +28,33 @@ program
17
28
  .description('CLI to provide full ckb development environment for professionals')
18
29
  .version(version);
19
30
  program
20
- .command('init')
31
+ .command('init [string]')
21
32
  .description('init dapp project with lumos')
22
- .argument('<string>', 'name of the dapp')
23
- .action((str) => {
24
- const name = str !== null && str !== void 0 ? str : 'offckb-dapp';
25
- return (0, init_1.init)(name);
26
- });
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
+ }));
27
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);
28
40
  program.command('accounts').description('print account list info').action(accounts_1.accounts);
29
41
  program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(list_hashes_1.listHashes);
30
- // Define the CLI commands and options
31
- program.command('install').description('Install the ckb dependency binary').action(install_1.installDependency);
32
- program.command('genkey').description('generate 20 accounts').action(genkey_1.genkey);
33
- program.command('init-chain').description('Use the CKB to init devnet').action(init_chain_1.initChainIfNeeded);
34
- program.command('build-lumos-config').description('Use the CKB to generate lumos config.json').action(build_lumos_config_1.buildLumosConfig);
35
- program.command('build-accounts').description('generate accounts with prefunded CKB tokens').action(genkey_1.buildAccounts);
36
- program
37
- .command('print-account-issue-info')
38
- .description('print account issue cells config toml sections')
39
- .action(genkey_1.printIssueSectionForToml);
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;