@offckb/cli 0.3.0-canary-ff28ab2.0 → 0.3.0-canary-ddcc6ce.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.
@@ -4,7 +4,7 @@ export interface ReplProp extends NetworkOption {
4
4
  proxyRpc?: boolean;
5
5
  }
6
6
  export declare function repl({ network, proxyRpc }: ReplProp): void;
7
- export declare function initGlobalClientBuilder(): {
7
+ export declare function initGlobalClientBuilder(proxyRpc: boolean): {
8
8
  new: (network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
9
9
  fromUrl: (rpcUrl: string, network: Network) => ccc.ClientPublicTestnet | ccc.ClientPublicMainnet;
10
10
  };
package/dist/cmd/repl.js CHANGED
@@ -27,17 +27,27 @@ function repl({ network = base_1.Network.devnet, proxyRpc = false }) {
27
27
  context.ccc = core_1.ccc;
28
28
  context.cccA = advanced_1.cccA;
29
29
  context.networks = network_1.networks;
30
- context.Client = initGlobalClientBuilder();
31
- context.client = initGlobalClientBuilder().new(network);
30
+ context.Client = initGlobalClientBuilder(proxyRpc);
31
+ context.client = initGlobalClientBuilder(proxyRpc).new(network);
32
32
  context.accounts = account_json_1.default;
33
33
  context.myScripts = buildMyScripts().new(network);
34
34
  context.systemScripts = buildSystemScripts().new(network);
35
35
  context.help = printHelpText;
36
36
  }
37
37
  exports.repl = repl;
38
- function initGlobalClientBuilder() {
38
+ function initGlobalClientBuilder(proxyRpc) {
39
39
  return {
40
40
  new: (network) => {
41
+ if (proxyRpc) {
42
+ return network === 'mainnet'
43
+ ? new core_1.ccc.ClientPublicMainnet({ url: network_1.networks.mainnet.proxy_rpc_url })
44
+ : network === 'testnet'
45
+ ? new core_1.ccc.ClientPublicTestnet({ url: network_1.networks.testnet.proxy_rpc_url })
46
+ : new core_1.ccc.ClientPublicTestnet({
47
+ url: network_1.networks.devnet.proxy_rpc_url,
48
+ scripts: (0, private_1.buildCCCDevnetKnownScripts)(),
49
+ });
50
+ }
41
51
  return network === 'mainnet'
42
52
  ? new core_1.ccc.ClientPublicMainnet()
43
53
  : network === 'testnet'
@@ -39,6 +39,7 @@ function createRPCProxy(network, targetRpcUrl, port) {
39
39
  }
40
40
  const txFile = path_1.default.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
41
41
  fs_1.default.writeFileSync(txFile, JSON.stringify(tx, null, 2));
42
+ console.debug(`RPC Req: store tx ${txHash}`);
42
43
  }
43
44
  }
44
45
  }
@@ -47,6 +48,25 @@ function createRPCProxy(network, targetRpcUrl, port) {
47
48
  }
48
49
  });
49
50
  });
51
+ proxy.on('proxyRes', function (proxyRes, _req, _res) {
52
+ const body = [];
53
+ proxyRes.on('data', function (chunk) {
54
+ body.push(chunk);
55
+ });
56
+ proxyRes.on('end', function () {
57
+ const res = Buffer.concat(body).toString();
58
+ try {
59
+ const jsonRpcResponse = JSON.parse(res);
60
+ const error = jsonRpcResponse.error;
61
+ if (error) {
62
+ console.debug('RPC Response: ', jsonRpcResponse);
63
+ }
64
+ }
65
+ catch (err) {
66
+ console.error('Error parsing JSON-RPC content:', err);
67
+ }
68
+ });
69
+ });
50
70
  const server = http_1.default.createServer((req, res) => {
51
71
  proxy.web(req, res, {}, (err) => {
52
72
  if (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-canary-ff28ab2.0",
3
+ "version": "0.3.0-canary-ddcc6ce.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",