@offckb/cli 0.1.1 → 0.1.2-canary-a369f24.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 (58) hide show
  1. package/account/ckb-miner-and-faucet.key +1 -0
  2. package/ckb/devnet/ckb.toml +3 -0
  3. package/dist/cfg/account.d.ts +55 -0
  4. package/dist/cfg/account.js +66 -0
  5. package/dist/cfg/const.d.ts +6 -1
  6. package/dist/cfg/const.js +7 -2
  7. package/dist/cli.js +69 -21
  8. package/dist/cmd/balance.d.ts +4 -0
  9. package/dist/cmd/balance.js +28 -0
  10. package/dist/cmd/clean.js +3 -2
  11. package/dist/cmd/create.d.ts +3 -0
  12. package/dist/cmd/create.js +56 -0
  13. package/dist/cmd/deploy.d.ts +6 -0
  14. package/dist/cmd/deploy.js +137 -0
  15. package/dist/cmd/deposit.d.ts +4 -0
  16. package/dist/cmd/deposit.js +95 -0
  17. package/dist/cmd/develop/build-account.d.ts +1 -0
  18. package/dist/cmd/develop/build-account.js +9 -0
  19. package/dist/cmd/{genkey.d.ts → develop/genkey.d.ts} +1 -0
  20. package/dist/cmd/{genkey.js → develop/genkey.js} +3 -2
  21. package/dist/cmd/{init-chain.js → develop/init-chain.js} +4 -4
  22. package/dist/cmd/{install.js → develop/install.js} +1 -1
  23. package/dist/cmd/develop/lumos-config.d.ts +4 -0
  24. package/dist/cmd/{build-lumos-config.js → develop/lumos-config.js} +25 -13
  25. package/dist/cmd/init.d.ts +3 -2
  26. package/dist/cmd/init.js +17 -10
  27. package/dist/cmd/inject-config.d.ts +4 -0
  28. package/dist/cmd/inject-config.js +99 -0
  29. package/dist/cmd/list-hashes.js +2 -2
  30. package/dist/cmd/node.js +2 -2
  31. package/dist/cmd/transfer.d.ts +5 -0
  32. package/dist/cmd/transfer.js +41 -0
  33. package/dist/cmd/update-config.d.ts +1 -0
  34. package/dist/cmd/update-config.js +19 -0
  35. package/dist/util/ckb.d.ts +77 -0
  36. package/dist/util/ckb.js +299 -0
  37. package/dist/util/config.d.ts +8 -0
  38. package/dist/util/config.js +127 -0
  39. package/dist/util/fs.d.ts +12 -0
  40. package/dist/{util.js → util/fs.js} +86 -65
  41. package/dist/util/git.d.ts +2 -0
  42. package/dist/util/git.js +85 -0
  43. package/dist/util/link.d.ts +1 -0
  44. package/dist/util/link.js +7 -0
  45. package/dist/util/template.d.ts +14 -0
  46. package/dist/util/template.js +43 -0
  47. package/dist/util/type.d.ts +8 -0
  48. package/dist/util/type.js +10 -0
  49. package/dist/util/validator.d.ts +4 -0
  50. package/dist/util/validator.js +59 -0
  51. package/package.json +1 -1
  52. package/templates/offckb.config.ts +193 -0
  53. package/dist/cmd/build-lumos-config.d.ts +0 -99
  54. package/dist/util.d.ts +0 -13
  55. /package/dist/cmd/{init-chain.d.ts → develop/init-chain.d.ts} +0 -0
  56. /package/dist/cmd/{install.d.ts → develop/install.d.ts} +0 -0
  57. /package/dist/{encoding.d.ts → util/encoding.d.ts} +0 -0
  58. /package/dist/{encoding.js → util/encoding.js} +0 -0
@@ -0,0 +1 @@
1
+ 650e256211f5e0beee9084596aa2cb84d11eb033cced5e2d5b191593a9f9f1d4
@@ -168,6 +168,9 @@ block_uncles_cache_size = 30
168
168
  # # Indexing the pending txs in the ckb tx-pool
169
169
  # index_tx_pool = false
170
170
 
171
+ # ckb miner / ckb faucet
172
+ # private key: 0x650e256211f5e0beee9084596aa2cb84d11eb033cced5e2d5b191593a9f9f1d4
173
+ # private key path: accounts/ckb-miner-and-faucet.key
171
174
  [block_assembler]
172
175
  code_hash = "0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8"
173
176
  args = "0xa1db2eef3f29f3ef6f86c8d2a0772c705c449f4a"
@@ -0,0 +1,55 @@
1
+ export declare const ckbDevnetMinerAccount: {
2
+ privkey: string;
3
+ pubkey: string;
4
+ lockScript: {
5
+ codeHash: string;
6
+ hashType: string;
7
+ args: string;
8
+ };
9
+ address: string;
10
+ args: string;
11
+ };
12
+ export declare const AliceAccount: {
13
+ privkey: string;
14
+ pubkey: string;
15
+ lockScript: {
16
+ codeHash: string;
17
+ hashType: string;
18
+ args: string;
19
+ };
20
+ address: string;
21
+ args: string;
22
+ };
23
+ export declare const BobAccount: {
24
+ privkey: string;
25
+ pubkey: string;
26
+ lockScript: {
27
+ codeHash: string;
28
+ hashType: string;
29
+ args: string;
30
+ };
31
+ address: string;
32
+ args: string;
33
+ };
34
+ export declare const CarolAccount: {
35
+ privkey: string;
36
+ pubkey: string;
37
+ lockScript: {
38
+ codeHash: string;
39
+ hashType: string;
40
+ args: string;
41
+ };
42
+ address: string;
43
+ args: string;
44
+ };
45
+ export declare const deployerAccount: {
46
+ privkey: string;
47
+ pubkey: string;
48
+ lockScript: {
49
+ codeHash: string;
50
+ hashType: string;
51
+ args: string;
52
+ };
53
+ address: string;
54
+ args: string;
55
+ };
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ //!note: do not use any accounts from OffCKB for real money!
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.deployerAccount = exports.CarolAccount = exports.BobAccount = exports.AliceAccount = exports.ckbDevnetMinerAccount = void 0;
5
+ // ckb devnet miner and faucet from accounts/ckb-miner-and-faucet.key
6
+ exports.ckbDevnetMinerAccount = {
7
+ privkey: '0x650e256211f5e0beee9084596aa2cb84d11eb033cced5e2d5b191593a9f9f1d4',
8
+ pubkey: '0x0201e68f3db9f4883861a69bc42484378e6d70a0de385e6420448e2c5e7e53d49d',
9
+ lockScript: {
10
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
11
+ hashType: 'type',
12
+ args: '0xa1db2eef3f29f3ef6f86c8d2a0772c705c449f4a',
13
+ },
14
+ address: 'ckb1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqdpmvhw70ef70hklpkg62s8wtrst3zf7jshsjzqx',
15
+ args: '0xa1db2eef3f29f3ef6f86c8d2a0772c705c449f4a',
16
+ };
17
+ // we should keep alice, bob and carol with some testnet balance.
18
+ // first account from account/account.json
19
+ exports.AliceAccount = {
20
+ privkey: '0x6109170b275a09ad54877b82f7d9930f88cab5717d484fb4741ae9d1dd078cd6',
21
+ pubkey: '0x02025fa7b61b2365aa459807b84df065f1949d58c0ae590ff22dd2595157bffefa',
22
+ lockScript: {
23
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
24
+ hashType: 'type',
25
+ args: '0x8e42b1999f265a0078503c4acec4d5e134534297',
26
+ },
27
+ address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvwg2cen8extgq8s5puft8vf40px3f599cytcyd8',
28
+ args: '0x8e42b1999f265a0078503c4acec4d5e134534297',
29
+ };
30
+ // second account from account/account.json
31
+ exports.BobAccount = {
32
+ privkey: '0x9f315d5a9618a39fdc487c7a67a8581d40b045bd7a42d83648ca80ef3b2cb4a1',
33
+ pubkey: '0x026efa0579f09cc7c1129b78544f70098c90b2ab155c10746316f945829c034a2d',
34
+ lockScript: {
35
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
36
+ hashType: 'type',
37
+ args: '0x758d311c8483e0602dfad7b69d9053e3f917457d',
38
+ },
39
+ address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqt435c3epyrupszm7khk6weq5lrlyt52lg48ucew',
40
+ args: '0x758d311c8483e0602dfad7b69d9053e3f917457d',
41
+ };
42
+ // third account from account/account.json
43
+ exports.CarolAccount = {
44
+ privkey: '0x59ddda57ba06d6e9c5fa9040bdb98b4b098c2fce6520d39f51bc5e825364697a',
45
+ pubkey: '0x02f1ec8d18e8ff13ecf7b3ab8f683d0c3a6d63478a7f7d14ca0fdfe8fea331e863',
46
+ lockScript: {
47
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
48
+ hashType: 'type',
49
+ args: '0x9d1edebedf8f026c0d597c4c5cd3f45dec1f7557',
50
+ },
51
+ address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsqvarm0tahu0qfkq6ktuf3wd8azaas0h24c9myfz6',
52
+ args: '0x9d1edebedf8f026c0d597c4c5cd3f45dec1f7557',
53
+ };
54
+ // we should keep deployerAccount with some testnet balance.
55
+ // last account from account/account.json
56
+ exports.deployerAccount = {
57
+ privkey: '0xace08599f3174f4376ae51fdc30950d4f2d731440382bb0aa1b6b0bd3a9728cd',
58
+ pubkey: '0x0216bc7b5b0a30fb910c372062a7f8cfa89f3a231f5d4a975e60a787ea828aa49e',
59
+ lockScript: {
60
+ codeHash: '0x9bd7e06f3ecf4be0f2fcd2188b23f1b9fcc88e5d4b65a8637b17723bbda3cce8',
61
+ hashType: 'type',
62
+ args: '0x4118c8c16749bf126b22468d030bf9de7da3717b',
63
+ },
64
+ address: 'ckt1qzda0cr08m85hc8jlnfp3zer7xulejywt49kt2rr0vthywaa50xwsq2prryvze6fhufxkgjx35psh7w70k3hz7c3mtl4d',
65
+ args: '0x4118c8c16749bf126b22468d030bf9de7da3717b',
66
+ };
@@ -3,15 +3,20 @@ export declare const packageSrcPath: string;
3
3
  export declare const packageRootPath: string;
4
4
  export declare const dappTemplatePath: string;
5
5
  export declare const targetEnvironmentPath: string;
6
+ export declare const predefinedOffCKBConfigTsPath: string;
7
+ export declare const userOffCKBConfigPath: string;
6
8
  export declare const devnetSourcePath: string;
7
9
  export declare const devnetPath: string;
8
10
  export declare const devnetDataPath: string;
9
11
  export declare const ckbFolderPath: string;
10
12
  export declare const ckbBinPath: string;
13
+ export declare const deployedContractInfoFolderPath: string;
11
14
  export declare const accountTargetDir: string;
12
15
  export declare const minimalRequiredCKBVersion = "0.113.1";
16
+ export declare const defaultLumosVersion = "0.21.0";
13
17
  export declare const dappTemplateGitRepoUserAndName = "nervosnetwork/docs.nervos.org";
14
18
  export declare const dappTemplateGitUrl = "https://github.com/nervosnetwork/docs.nervos.org";
15
- export declare const dappTemplateGitBranch = "develop-v2";
19
+ export declare const dappTemplateGitBranch = "v2";
16
20
  export declare const dappTemplateGitFolder = "examples";
17
21
  export declare const dappTemplateGitSelectOptionFile = "options.json";
22
+ export declare const bareTemplateGitSelectOptionFile = "template.json";
package/dist/cfg/const.js CHANGED
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
23
23
  return result;
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
- exports.dappTemplateGitSelectOptionFile = exports.dappTemplateGitFolder = exports.dappTemplateGitBranch = exports.dappTemplateGitUrl = exports.dappTemplateGitRepoUserAndName = 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;
26
+ exports.bareTemplateGitSelectOptionFile = exports.dappTemplateGitSelectOptionFile = 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
27
  const path = __importStar(require("path"));
28
28
  // path
29
29
  exports.currentExecPath = process.cwd();
@@ -31,17 +31,22 @@ exports.packageSrcPath = path.dirname(require.main.filename);
31
31
  exports.packageRootPath = path.resolve(exports.packageSrcPath, '../');
32
32
  exports.dappTemplatePath = path.resolve(exports.packageRootPath, './templates');
33
33
  exports.targetEnvironmentPath = path.resolve(exports.packageRootPath, './target');
34
+ exports.predefinedOffCKBConfigTsPath = path.resolve(exports.dappTemplatePath, 'offckb.config.ts');
35
+ exports.userOffCKBConfigPath = path.resolve(exports.currentExecPath, 'offckb.config.ts');
34
36
  exports.devnetSourcePath = path.resolve(exports.packageRootPath, './ckb/devnet');
35
37
  exports.devnetPath = path.resolve(exports.targetEnvironmentPath, `devnet`);
36
38
  exports.devnetDataPath = path.resolve(exports.devnetPath, `data`);
37
39
  exports.ckbFolderPath = path.resolve(exports.targetEnvironmentPath, 'ckb');
38
40
  exports.ckbBinPath = path.resolve(exports.ckbFolderPath, 'ckb');
41
+ exports.deployedContractInfoFolderPath = path.resolve(exports.targetEnvironmentPath, 'contracts');
39
42
  exports.accountTargetDir = path.join(exports.packageRootPath, `account`);
40
43
  // Version
41
44
  exports.minimalRequiredCKBVersion = '0.113.1';
45
+ exports.defaultLumosVersion = '0.21.0';
42
46
  // url
43
47
  exports.dappTemplateGitRepoUserAndName = 'nervosnetwork/docs.nervos.org';
44
48
  exports.dappTemplateGitUrl = `https://github.com/${exports.dappTemplateGitRepoUserAndName}`;
45
- exports.dappTemplateGitBranch = 'develop-v2';
49
+ exports.dappTemplateGitBranch = 'v2';
46
50
  exports.dappTemplateGitFolder = 'examples';
47
51
  exports.dappTemplateGitSelectOptionFile = 'options.json';
52
+ exports.bareTemplateGitSelectOptionFile = 'template.json';
package/dist/cli.js CHANGED
@@ -11,53 +11,101 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  const commander_1 = require("commander");
14
- const install_1 = require("./cmd/install");
15
- const genkey_1 = require("./cmd/genkey");
14
+ const install_1 = require("./cmd/develop/install");
15
+ const genkey_1 = require("./cmd/develop/genkey");
16
16
  const list_hashes_1 = require("./cmd/list-hashes");
17
17
  const node_1 = require("./cmd/node");
18
- const init_chain_1 = require("./cmd/init-chain");
19
- const build_lumos_config_1 = require("./cmd/build-lumos-config");
18
+ const init_chain_1 = require("./cmd/develop/init-chain");
19
+ const lumos_config_1 = require("./cmd/develop/lumos-config");
20
20
  const init_1 = require("./cmd/init");
21
21
  const accounts_1 = require("./cmd/accounts");
22
22
  const clean_1 = require("./cmd/clean");
23
- const encoding_1 = require("./encoding");
23
+ const encoding_1 = require("./util/encoding");
24
+ const inject_config_1 = require("./cmd/inject-config");
25
+ const deposit_1 = require("./cmd/deposit");
26
+ const deploy_1 = require("./cmd/deploy");
27
+ const update_config_1 = require("./cmd/update-config");
28
+ const transfer_1 = require("./cmd/transfer");
29
+ const balance_1 = require("./cmd/balance");
30
+ const build_account_1 = require("./cmd/develop/build-account");
31
+ const create_1 = require("./cmd/create");
24
32
  const version = require('../package.json').version;
33
+ const description = require('../package.json').description;
25
34
  // fix windows terminal encoding of simplified chinese text
26
35
  (0, encoding_1.setUTF8EncodingForWindows)();
27
36
  const program = new commander_1.Command();
37
+ program.name('offckb').description(description).version(version);
28
38
  program
29
- .name('offckb')
30
- .description('CLI to provide full ckb development environment for professionals')
31
- .version(version);
32
- program
33
- .command('init [string]')
34
- .description('init dapp project with lumos')
35
- .action((str) => __awaiter(void 0, void 0, void 0, function* () {
36
- const name = str !== null && str !== void 0 ? str : 'my-awesome-ckb-dapp';
39
+ .command('init [your-project-name]')
40
+ .description('Init a example dApp to learn and run')
41
+ .action((projectName) => __awaiter(void 0, void 0, void 0, function* () {
42
+ const name = projectName !== null && projectName !== void 0 ? projectName : 'my-awesome-ckb-dapp';
37
43
  const template = yield (0, init_1.selectTemplate)();
38
44
  return (0, init_1.init)(name, template);
39
45
  }));
46
+ program
47
+ .command('create [your-project-name]')
48
+ .description('Create a new dApp from bare templates')
49
+ .action((projectName) => __awaiter(void 0, void 0, void 0, function* () {
50
+ const name = projectName !== null && projectName !== void 0 ? projectName : 'my-first-ckb-project';
51
+ const template = yield (0, create_1.selectBareTemplate)();
52
+ return (0, create_1.create)(name, template);
53
+ }));
40
54
  program.command('node').description('Use the CKB to start devnet').action(node_1.node);
41
55
  program.command('clean').description('Clean the devnet data, need to stop running the chain first').action(clean_1.clean);
42
- program.command('accounts').description('print account list info').action(accounts_1.accounts);
56
+ program.command('accounts').description('Print account list info').action(accounts_1.accounts);
43
57
  program.command('list-hashes').description('Use the CKB to list blockchain scripts hashes').action(list_hashes_1.listHashes);
58
+ program.command('inject-config').description('Add offckb.config.ts to your workspace').action(inject_config_1.injectConfig);
59
+ program.command('update-config').description('Update offckb.config.ts in your workspace').action(update_config_1.updateConfig);
60
+ program
61
+ .command('deposit [toAddress] [amountInShannon]')
62
+ .description('Deposit CKB tokens to address, only devnet and testnet')
63
+ .option('--network <network>', 'Specify the network to deposit to', 'devnet')
64
+ .action((toAddress, amount, options) => __awaiter(void 0, void 0, void 0, function* () {
65
+ return (0, deposit_1.deposit)(toAddress, amount, options);
66
+ }));
67
+ program
68
+ .command('transfer [toAddress] [amountInShannon]')
69
+ .description('Transfer CKB tokens to address, only devnet and testnet')
70
+ .option('--network <network>', 'Specify the network to transfer to', 'devnet')
71
+ .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
72
+ .action((toAddress, amount, options) => __awaiter(void 0, void 0, void 0, function* () {
73
+ return (0, transfer_1.transfer)(toAddress, amount, options);
74
+ }));
75
+ program
76
+ .command('balance [toAddress]')
77
+ .description('Check account balance, only devnet and testnet')
78
+ .option('--network <network>', 'Specify the network to check', 'devnet')
79
+ .action((toAddress, options) => __awaiter(void 0, void 0, void 0, function* () {
80
+ return (0, balance_1.balanceOf)(toAddress, options);
81
+ }));
82
+ program
83
+ .command('deploy')
84
+ .description('Deploy contracts to different networks, only supports devnet and testnet')
85
+ .option('--network <network>', 'Specify the network to deploy to', 'devnet')
86
+ .option('--target <target>', 'Specify the relative bin target folder to deploy to')
87
+ .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
88
+ .action((options) => (0, deploy_1.deploy)(options));
44
89
  // Add commands meant for developers
45
90
  if (process.env.NODE_ENV === 'development') {
46
91
  // Define the CLI commands and options
47
92
  program.command('install').description('Install the ckb dependency binary').action(install_1.installDependency);
48
- program.command('genkey').description('generate 20 accounts').action(genkey_1.genkey);
93
+ program.command('genkey').description('Generate 20 accounts').action(genkey_1.genkey);
49
94
  program.command('init-chain').description('Use the CKB to init devnet').action(init_chain_1.initChainIfNeeded);
50
95
  program
51
- .command('build-lumos-config')
52
- .description('Use the CKB to generate lumos config.json')
53
- .action(build_lumos_config_1.buildLumosConfig);
54
- program.command('build-accounts').description('generate accounts with prefunded CKB tokens').action(genkey_1.buildAccounts);
96
+ .command('build-devnet-lumos-config')
97
+ .description('Use the CKB to generate predefined devnet lumos config.json')
98
+ .action(lumos_config_1.writePredefinedDevnetLumosConfig);
99
+ program.command('build-accounts').description('Generate accounts with prefunded CKB tokens').action(genkey_1.buildAccounts);
55
100
  program
56
101
  .command('print-account-issue-info')
57
- .description('print account issue cells config toml sections')
102
+ .description('Print account issue cells config toml sections')
58
103
  .action(genkey_1.printIssueSectionForToml);
104
+ program
105
+ .command('build-account [privateKey]')
106
+ .description('Print standard account info from a privatekey')
107
+ .action(build_account_1.buildAccount);
59
108
  }
60
- // Parse command-line arguments
61
109
  program.parse(process.argv);
62
110
  // If no command is specified, display help
63
111
  if (!process.argv.slice(2).length) {
@@ -0,0 +1,4 @@
1
+ import { NetworkOption } from '../util/type';
2
+ export interface BalanceOption extends NetworkOption {
3
+ }
4
+ export declare function balanceOf(address: string, opt?: BalanceOption): Promise<void>;
@@ -0,0 +1,28 @@
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.balanceOf = void 0;
13
+ const lumos_1 = require("@ckb-lumos/lumos");
14
+ const ckb_1 = require("../util/ckb");
15
+ const validator_1 = require("../util/validator");
16
+ const type_1 = require("../util/type");
17
+ function balanceOf(address, opt = { network: type_1.Network.devnet }) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ const network = opt.network;
20
+ (0, validator_1.validateNetworkOpt)(network);
21
+ const ckb = new ckb_1.CKB(network);
22
+ const lumosConfig = ckb.getLumosConfig();
23
+ const balance = yield ckb.capacityOf(address, lumosConfig);
24
+ const balanceInCKB = balance.div(lumos_1.BI.from('100000000'));
25
+ console.log(`Balance: ${balanceInCKB} CKB`);
26
+ });
27
+ }
28
+ exports.balanceOf = balanceOf;
package/dist/cmd/clean.js CHANGED
@@ -5,13 +5,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.clean = void 0;
7
7
  const const_1 = require("../cfg/const");
8
- const util_1 = require("../util");
9
8
  const fs_1 = __importDefault(require("fs"));
9
+ const fs_2 = require("../util/fs");
10
10
  function clean() {
11
- if ((0, util_1.isFolderExists)(const_1.devnetDataPath)) {
11
+ if ((0, fs_2.isFolderExists)(const_1.devnetDataPath)) {
12
12
  try {
13
13
  fs_1.default.rmSync(const_1.devnetDataPath, { recursive: true });
14
14
  console.log(`Chain data cleaned.`);
15
+ // todo: rm deploy info too
15
16
  }
16
17
  catch (error) {
17
18
  console.log(`Did you stop running the chain first?`);
@@ -0,0 +1,3 @@
1
+ import { BareTemplateOption } from '../util/template';
2
+ export declare function create(name: string, template: BareTemplateOption): Promise<void>;
3
+ export declare function selectBareTemplate(): Promise<BareTemplateOption>;
@@ -0,0 +1,56 @@
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.selectBareTemplate = exports.create = void 0;
16
+ const path_1 = __importDefault(require("path"));
17
+ const const_1 = require("../cfg/const");
18
+ const fs_1 = require("../util/fs");
19
+ const template_1 = require("../util/template");
20
+ const git_1 = require("../util/git");
21
+ const prompts_1 = require("@inquirer/prompts");
22
+ const version = require('../../package.json').version;
23
+ function create(name, template) {
24
+ return __awaiter(this, void 0, void 0, function* () {
25
+ const targetPath = path_1.default.resolve(const_1.currentExecPath, name);
26
+ const dappTemplateFolderPath = `${const_1.dappTemplateGitFolder}/${template.value}`;
27
+ (0, git_1.gitCloneAndDownloadFolderSync)(const_1.dappTemplateGitUrl, const_1.dappTemplateGitBranch, dappTemplateFolderPath, targetPath);
28
+ // update the version
29
+ const projectFolder = path_1.default.resolve(const_1.currentExecPath, name);
30
+ const targetConfigPath = (0, fs_1.findFileInFolder)(projectFolder, 'offckb.config.ts');
31
+ if (targetConfigPath) {
32
+ (0, fs_1.updateVersionInTSFile)(version, targetConfigPath);
33
+ }
34
+ else {
35
+ console.log("Couldn't find the offckb config file in project. abort.");
36
+ }
37
+ });
38
+ }
39
+ exports.create = create;
40
+ function selectBareTemplate() {
41
+ return __awaiter(this, void 0, void 0, function* () {
42
+ const opts = yield (0, template_1.loadBareTemplateOpts)();
43
+ const answer = yield (0, prompts_1.select)({
44
+ message: 'Select a bare template',
45
+ choices: opts.map((opt) => {
46
+ return {
47
+ name: opt.name,
48
+ value: opt.value,
49
+ description: `${opt.description}, \n[${opt.tag.toString()}]`,
50
+ };
51
+ }),
52
+ });
53
+ return opts.find((opt) => opt.value === answer);
54
+ });
55
+ }
56
+ exports.selectBareTemplate = selectBareTemplate;
@@ -0,0 +1,6 @@
1
+ import { NetworkOption } from '../util/type';
2
+ export interface DeployOptions extends NetworkOption {
3
+ target: string | null | undefined;
4
+ privkey?: string | null;
5
+ }
6
+ export declare function deploy(opt?: DeployOptions): Promise<void>;
@@ -0,0 +1,137 @@
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.deploy = void 0;
16
+ const lumos_1 = require("@ckb-lumos/lumos");
17
+ const fs_1 = __importDefault(require("fs"));
18
+ const const_1 = require("../cfg/const");
19
+ const type_1 = require("../util/type");
20
+ const path_1 = __importDefault(require("path"));
21
+ const ckb_1 = require("../util/ckb");
22
+ const account_1 = require("../cfg/account");
23
+ const config_1 = require("../util/config");
24
+ const fs_2 = require("../util/fs");
25
+ const validator_1 = require("../util/validator");
26
+ function deploy(opt = { network: type_1.Network.devnet, target: null }) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ const network = opt.network;
29
+ (0, validator_1.validateNetworkOpt)(network);
30
+ const ckb = new ckb_1.CKB(network);
31
+ // we use deployerAccount to deploy contract by default
32
+ const privateKey = opt.privkey || account_1.deployerAccount.privkey;
33
+ const lumosConfig = ckb.getLumosConfig();
34
+ const from = ckb_1.CKB.generateAccountFromPrivateKey(privateKey, lumosConfig);
35
+ const targetFolder = opt.target;
36
+ if (targetFolder) {
37
+ const binFolder = (0, fs_2.isAbsolutePath)(targetFolder) ? targetFolder : path_1.default.resolve(const_1.currentExecPath, targetFolder);
38
+ const bins = (0, fs_2.listBinaryFilesInFolder)(binFolder);
39
+ const binPaths = bins.map((bin) => path_1.default.resolve(binFolder, bin));
40
+ const results = yield deployBinaries(binPaths, from, ckb);
41
+ // 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
43
+ return;
44
+ }
45
+ // check if target workspace is valid
46
+ try {
47
+ (0, validator_1.validateExecDappEnvironment)();
48
+ }
49
+ catch (error) {
50
+ return console.debug('Not a valid offCKB dapp workspace.');
51
+ }
52
+ // read contract bin folder
53
+ const bins = getToDeployBinsPath();
54
+ const results = yield deployBinaries(bins, from, ckb);
55
+ // record the deployed contract infos
56
+ recordDeployResult(results, network);
57
+ });
58
+ }
59
+ exports.deploy = deploy;
60
+ function getToDeployBinsPath() {
61
+ const fileContent = fs_1.default.readFileSync(const_1.userOffCKBConfigPath, 'utf-8');
62
+ const match = fileContent.match(/contractBinFolder:\s*['"]([^'"]+)['"]/);
63
+ if (match && match[1]) {
64
+ const contractBinFolderValue = match[1];
65
+ const binFolderPath = (0, fs_2.isAbsolutePath)(contractBinFolderValue)
66
+ ? contractBinFolderValue
67
+ : path_1.default.resolve(const_1.currentExecPath, contractBinFolderValue);
68
+ const bins = (0, fs_2.listBinaryFilesInFolder)(binFolderPath);
69
+ return bins.map((bin) => path_1.default.resolve(binFolderPath, bin));
70
+ }
71
+ else {
72
+ console.log('contractBinFolder value not found in offckb.config.ts');
73
+ return [];
74
+ }
75
+ }
76
+ function recordDeployResult(results, network, updateOffCKBConfig = true) {
77
+ return __awaiter(this, void 0, void 0, function* () {
78
+ if (results.length === 0) {
79
+ return;
80
+ }
81
+ 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);
90
+ }
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);
95
+ }
96
+ console.log('done.');
97
+ });
98
+ }
99
+ function deployBinaries(binPaths, from, ckb) {
100
+ return __awaiter(this, void 0, void 0, function* () {
101
+ if (binPaths.length === 0) {
102
+ console.log('No binary to deploy.');
103
+ }
104
+ const results = [];
105
+ for (const bin of binPaths) {
106
+ const result = yield deployBinary(bin, from, ckb);
107
+ results.push(result);
108
+ }
109
+ return results;
110
+ });
111
+ }
112
+ function deployBinary(binPath, from, ckb) {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ const bin = yield (0, fs_2.readFileToUint8Array)(binPath);
115
+ const contractName = (0, fs_2.convertFilenameToUppercase)(binPath);
116
+ const result = yield lumos_1.commons.deploy.generateDeployWithDataTx({
117
+ cellProvider: ckb.indexer,
118
+ fromInfo: from.address,
119
+ scriptBinary: bin,
120
+ config: ckb.getLumosConfig(),
121
+ });
122
+ // send deploy tx
123
+ let txSkeleton = result.txSkeleton;
124
+ txSkeleton = lumos_1.commons.common.prepareSigningEntries(txSkeleton);
125
+ const message = txSkeleton.get('signingEntries').get(0).message;
126
+ const Sig = lumos_1.hd.key.signRecoverable(message, from.privKey);
127
+ const tx = lumos_1.helpers.sealTransaction(txSkeleton, [Sig]);
128
+ const res = yield ckb.rpc.sendTransaction(tx, 'passthrough');
129
+ 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
+ console.log('wait 4 blocks..');
134
+ yield ckb.indexer.waitForSync(-4);
135
+ return Object.assign({ contractName }, result);
136
+ });
137
+ }
@@ -0,0 +1,4 @@
1
+ import { NetworkOption } from '../util/type';
2
+ export interface DepositOptions extends NetworkOption {
3
+ }
4
+ export declare function deposit(toAddress: string, amount: string, opt?: DepositOptions): Promise<void>;