@offckb/cli 0.3.0-canary-ee0ab6a.0 → 0.3.0-canary-0ceb8cb.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.
@@ -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,6 +1,6 @@
1
1
  {
2
2
  "name": "@offckb/cli",
3
- "version": "0.3.0-canary-ee0ab6a.0",
3
+ "version": "0.3.0-canary-0ceb8cb.0",
4
4
  "description": "ckb development network for your first try",
5
5
  "author": "CKB EcoFund",
6
6
  "license": "MIT",