@offckb/cli 0.3.0-rc5 → 0.3.0-rc6

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.
package/README.md CHANGED
@@ -365,7 +365,7 @@ detail informations about each account are recorded in the `account/account.json
365
365
 
366
366
  ## About CCC
367
367
 
368
- `offckb` uses [CCC](https://github.com/ckb-ecofund/ccc) as the development framework to build the CKB dApp template projects.
368
+ `offckb` uses [CCC](https://github.com/ckb-devrel/ccc) as the development framework to build the CKB dApp template projects.
369
369
 
370
370
  ## FAQ
371
371
 
@@ -72,8 +72,8 @@ exports.defaultSettings = {
72
72
  contractsPath: path.resolve(exports.dataPath, 'mainnet/contracts'),
73
73
  },
74
74
  dappTemplate: {
75
- gitRepoUrl: `https://github.com/ckb-ecofund/offckb`,
76
- gitBranch: 'v0.3.x',
75
+ gitRepoUrl: `https://github.com/ckb-devrel/offckb`,
76
+ gitBranch: 'master',
77
77
  gitFolder: 'templates/v3',
78
78
  downloadPath: path.resolve(exports.cachePath, 'download', 'dapp-template'),
79
79
  },
package/dist/cli.js CHANGED
@@ -101,6 +101,7 @@ program
101
101
  .command('deposit [toAddress] [amountInCKB]')
102
102
  .description('Deposit CKB tokens to address, only devnet and testnet')
103
103
  .option('--network <network>', 'Specify the network to deposit to', 'devnet')
104
+ .option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
104
105
  .action((toAddress, amountInCKB, options) => __awaiter(void 0, void 0, void 0, function* () {
105
106
  return (0, deposit_1.deposit)(toAddress, amountInCKB, options);
106
107
  }));
@@ -108,7 +109,8 @@ program
108
109
  .command('transfer [toAddress] [amountInCKB]')
109
110
  .description('Transfer CKB tokens to address, only devnet and testnet')
110
111
  .option('--network <network>', 'Specify the network to transfer to', 'devnet')
111
- .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
112
+ .option('--privkey <privkey>', 'Specify the private key to transfer CKB')
113
+ .option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
112
114
  .action((toAddress, amountInCKB, options) => __awaiter(void 0, void 0, void 0, function* () {
113
115
  return (0, transfer_1.transfer)(toAddress, amountInCKB, options);
114
116
  }));
@@ -117,6 +119,7 @@ program
117
119
  .description('Transfer All CKB tokens to address, only devnet and testnet')
118
120
  .option('--network <network>', 'Specify the network to transfer to', 'devnet')
119
121
  .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
122
+ .option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
120
123
  .action((toAddress, options) => __awaiter(void 0, void 0, void 0, function* () {
121
124
  return (0, transfer_all_1.transferAll)(toAddress, options);
122
125
  }));
@@ -134,6 +137,7 @@ program
134
137
  .option('--target <target>', 'Specify the relative bin target folder to deploy to')
135
138
  .option('-t, --type-id', 'Specify if use upgradable type id to deploy the script')
136
139
  .option('--privkey <privkey>', 'Specify the private key to deploy scripts')
140
+ .option('-r, --proxy-rpc', 'Use Proxy RPC to connect to blockchain')
137
141
  .action((options) => (0, deploy_1.deploy)(options));
138
142
  program
139
143
  .command('my-scripts')
@@ -3,5 +3,6 @@ export interface DeployOptions extends NetworkOption {
3
3
  target: string | null | undefined;
4
4
  privkey?: string | null;
5
5
  typeId?: boolean;
6
+ proxyRpc?: boolean;
6
7
  }
7
8
  export declare function deploy(opt?: DeployOptions): Promise<void>;
@@ -20,12 +20,13 @@ const fs_1 = require("../util/fs");
20
20
  const validator_1 = require("../util/validator");
21
21
  const deploy_1 = require("../deploy");
22
22
  const ckb_1 = require("../sdk/ckb");
23
- function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: null }) {
23
+ function deploy(opt = { network: base_1.Network.devnet, typeId: false, target: null, proxyRpc: false }) {
24
24
  var _a;
25
25
  return __awaiter(this, void 0, void 0, function* () {
26
26
  const network = opt.network;
27
27
  (0, validator_1.validateNetworkOpt)(network);
28
- const ckb = new ckb_1.CKB({ network });
28
+ const isEnableProxyRpc = opt.proxyRpc;
29
+ const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
29
30
  // we use deployerAccount to deploy contract by default
30
31
  const privateKey = opt.privkey || account_1.deployerAccount.privkey;
31
32
  const enableTypeId = (_a = opt.typeId) !== null && _a !== void 0 ? _a : false;
@@ -1,4 +1,5 @@
1
1
  import { NetworkOption } from '../type/base';
2
2
  export interface DepositOptions extends NetworkOption {
3
+ proxyRpc?: boolean;
3
4
  }
4
5
  export declare function deposit(toAddress: string, amountInCKB: string, opt?: DepositOptions): Promise<void>;
@@ -16,11 +16,12 @@ const base_1 = require("../type/base");
16
16
  const link_1 = require("../util/link");
17
17
  const validator_1 = require("../util/validator");
18
18
  const request_1 = require("../util/request");
19
- function deposit(toAddress, amountInCKB, opt = { network: base_1.Network.devnet }) {
19
+ function deposit(toAddress, amountInCKB, opt = { network: base_1.Network.devnet, proxyRpc: false }) {
20
20
  return __awaiter(this, void 0, void 0, function* () {
21
21
  const network = opt.network;
22
22
  (0, validator_1.validateNetworkOpt)(network);
23
- const ckb = new ckb_1.CKB({ network });
23
+ const isEnableProxyRpc = opt.proxyRpc;
24
+ const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
24
25
  if (network === 'testnet') {
25
26
  return yield depositFromTestnetFaucet(toAddress, ckb);
26
27
  }
@@ -1,5 +1,6 @@
1
1
  import { NetworkOption } from '../type/base';
2
2
  export interface TransferAllOptions extends NetworkOption {
3
3
  privkey?: string | null;
4
+ proxyRpc?: boolean;
4
5
  }
5
6
  export declare function transferAll(toAddress: string, opt?: TransferAllOptions): Promise<void>;
@@ -14,15 +14,16 @@ const ckb_1 = require("../sdk/ckb");
14
14
  const base_1 = require("../type/base");
15
15
  const link_1 = require("../util/link");
16
16
  const validator_1 = require("../util/validator");
17
- function transferAll(toAddress, opt = { network: base_1.Network.devnet }) {
17
+ function transferAll(toAddress, opt = { network: base_1.Network.devnet, proxyRpc: false }) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  const network = opt.network;
20
20
  (0, validator_1.validateNetworkOpt)(network);
21
21
  if (opt.privkey == null) {
22
22
  throw new Error('--privkey is required!');
23
23
  }
24
+ const isEnableProxyRpc = opt.proxyRpc;
24
25
  const privateKey = opt.privkey;
25
- const ckb = new ckb_1.CKB({ network });
26
+ const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
26
27
  const txHash = yield ckb.transferAll({
27
28
  toAddress,
28
29
  privateKey,
@@ -1,5 +1,6 @@
1
1
  import { NetworkOption } from '../type/base';
2
2
  export interface TransferOptions extends NetworkOption {
3
3
  privkey?: string | null;
4
+ proxyRpc?: boolean;
4
5
  }
5
6
  export declare function transfer(toAddress: string, amountInCKB: string, opt?: TransferOptions): Promise<void>;
@@ -14,15 +14,16 @@ const ckb_1 = require("../sdk/ckb");
14
14
  const base_1 = require("../type/base");
15
15
  const link_1 = require("../util/link");
16
16
  const validator_1 = require("../util/validator");
17
- function transfer(toAddress, amountInCKB, opt = { network: base_1.Network.devnet }) {
17
+ function transfer(toAddress, amountInCKB, opt = { network: base_1.Network.devnet, proxyRpc: false }) {
18
18
  return __awaiter(this, void 0, void 0, function* () {
19
19
  const network = opt.network;
20
20
  (0, validator_1.validateNetworkOpt)(network);
21
21
  if (opt.privkey == null) {
22
22
  throw new Error('--privkey is required!');
23
23
  }
24
+ const isEnableProxyRpc = opt.proxyRpc;
24
25
  const privateKey = opt.privkey;
25
- const ckb = new ckb_1.CKB({ network });
26
+ const ckb = new ckb_1.CKB({ network, isEnableProxyRpc });
26
27
  const txHash = yield ckb.transfer({
27
28
  toAddress,
28
29
  amountInCKB,
@@ -1,11 +1,23 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.loadBareTemplateOpts = void 0;
7
- const option_json_1 = __importDefault(require("./option.json"));
4
+ const templates = [
5
+ {
6
+ name: 'Remix-Vite Bare Templates',
7
+ value: 'remix-vite-template',
8
+ description: 'A full-stack template with Remix-vite and ckb-script-templates',
9
+ tag: ['remix', 'vite', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
10
+ author: 'retric@cryptape.com',
11
+ },
12
+ {
13
+ name: 'Next.js Bare Templates',
14
+ value: 'next-js-template',
15
+ description: 'A full-stack template with Next.js framework and ckb-script-templates',
16
+ tag: ['next.js', 'tailwindcss', 'ckb-script-templates', 'typescript', 'rust'],
17
+ author: 'retric@cryptape.com',
18
+ },
19
+ ];
8
20
  function loadBareTemplateOpts() {
9
- return option_json_1.default;
21
+ return templates;
10
22
  }
11
23
  exports.loadBareTemplateOpts = loadBareTemplateOpts;
@@ -2,7 +2,6 @@
2
2
  import http from 'http';
3
3
  import { Network } from '../type/base';
4
4
  export declare function createRPCProxy(network: Network, targetRpcUrl: string, port: number): {
5
- server: http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
6
5
  network: Network;
7
6
  start: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
8
7
  stop: () => http.Server<typeof http.IncomingMessage, typeof http.ServerResponse>;
@@ -16,6 +16,37 @@ function createRPCProxy(network, targetRpcUrl, port) {
16
16
  const proxy = http_proxy_1.default.createProxyServer({
17
17
  target: targetRpcUrl, // Target RPC server
18
18
  });
19
+ proxy.on('proxyReq', (_, req) => {
20
+ let reqData = '';
21
+ req.on('data', (chunk) => {
22
+ reqData += chunk;
23
+ });
24
+ req.on('end', () => {
25
+ try {
26
+ const jsonRpcContent = JSON.parse(reqData);
27
+ const method = jsonRpcContent.method;
28
+ const params = jsonRpcContent.params;
29
+ console.debug('RPC Req: ', method);
30
+ if (method === 'send_transaction') {
31
+ const tx = params[0];
32
+ // todo: record tx
33
+ if (network === base_1.Network.devnet) {
34
+ const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
35
+ const txHash = cccTx.hash();
36
+ const settings = (0, setting_1.readSettings)();
37
+ if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
38
+ fs_1.default.mkdirSync(settings.devnet.transactionsPath);
39
+ }
40
+ const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
41
+ fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
42
+ }
43
+ }
44
+ }
45
+ catch (err) {
46
+ console.error('Error parsing JSON-RPC content:', err);
47
+ }
48
+ });
49
+ });
19
50
  const server = http_1.default.createServer((req, res) => {
20
51
  proxy.web(req, res, {}, (err) => {
21
52
  if (err) {
@@ -24,52 +55,8 @@ function createRPCProxy(network, targetRpcUrl, port) {
24
55
  res.end('Proxy error');
25
56
  }
26
57
  });
27
- proxy.on('proxyReq', (_, req) => {
28
- let reqData = '';
29
- req.on('data', (chunk) => {
30
- reqData += chunk;
31
- });
32
- req.on('end', () => {
33
- try {
34
- const jsonRpcContent = JSON.parse(reqData);
35
- console.debug('Incoming Request: ', jsonRpcContent);
36
- const method = jsonRpcContent.method;
37
- const params = jsonRpcContent.params;
38
- if (method === 'send_transaction') {
39
- const tx = params[0];
40
- // todo: record tx
41
- if (network === base_1.Network.devnet) {
42
- const cccTx = cccA.JsonRpcTransformers.transactionTo(tx);
43
- const txHash = cccTx.hash();
44
- const settings = (0, setting_1.readSettings)();
45
- console.log('txHash: ', txHash, settings, settings.devnet.transactionsPath);
46
- if (!fs_1.default.existsSync(settings.devnet.transactionsPath)) {
47
- fs_1.default.mkdirSync(settings.devnet.transactionsPath);
48
- }
49
- const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
50
- fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
51
- }
52
- }
53
- }
54
- catch (err) {
55
- console.error('Error parsing JSON-RPC content:', err);
56
- }
57
- });
58
- });
59
- // Capture the content from the response (or request)
60
- proxy.on('proxyRes', (proxyRes) => {
61
- let data = '';
62
- proxyRes.on('data', (chunk) => {
63
- data += chunk;
64
- });
65
- proxyRes.on('end', () => {
66
- console.log('Captured content:', data);
67
- // Do something with the captured content
68
- });
69
- });
70
58
  });
71
59
  return {
72
- server,
73
60
  network,
74
61
  start: () => {
75
62
  return server.listen(port, () => {
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-rc5",
3
+ "version": "0.3.0-rc6",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",
7
7
  "repository": {
8
8
  "type": "git",
9
- "url": "git+https://github.com/ckb-ecofund/offckb.git"
9
+ "url": "git+https://github.com/ckb-devrel/offckb.git"
10
10
  },
11
11
  "main": "dist/cli.js",
12
12
  "bin": {
@@ -1,16 +0,0 @@
1
- [
2
- {
3
- "name": "Remix-Vite Bare Templates",
4
- "value": "remix-vite-template",
5
- "description": "A full-stack template with Remix-vite and ckb-script-templates",
6
- "tag": ["remix", "vite", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
7
- "author": "retric@cryptape.com"
8
- },
9
- {
10
- "name": "Next.js Bare Templates",
11
- "value": "next-js-template",
12
- "description": "A full-stack template with Next.js framework and ckb-script-templates",
13
- "tag": ["next.js", "tailwindcss", "ckb-script-templates", "typescript", "rust"],
14
- "author": "retric@cryptape.com"
15
- }
16
- ]