Skip to content

Commit ddcc6ce

Browse files
authored
chore(proxyRpc): log txHash and error response (#193)
1 parent f27b53d commit ddcc6ce

1 file changed

Lines changed: 20 additions & 0 deletions

File tree

src/tools/rpc-proxy.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ export function createRPCProxy(network: Network, targetRpcUrl: string, port: num
3737
}
3838
const txFile = path.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
3939
fs.writeFileSync(txFile, JSON.stringify(tx, null, 2));
40+
console.debug(`RPC Req: store tx ${txHash}`);
4041
}
4142
}
4243
} catch (err) {
@@ -45,6 +46,25 @@ export function createRPCProxy(network: Network, targetRpcUrl: string, port: num
4546
});
4647
});
4748

49+
proxy.on('proxyRes', function (proxyRes, _req, _res) {
50+
const body: Buffer[] = [];
51+
proxyRes.on('data', function (chunk) {
52+
body.push(chunk);
53+
});
54+
proxyRes.on('end', function () {
55+
const res = Buffer.concat(body).toString();
56+
try {
57+
const jsonRpcResponse = JSON.parse(res);
58+
const error = jsonRpcResponse.error;
59+
if (error) {
60+
console.debug('RPC Response: ', jsonRpcResponse);
61+
}
62+
} catch (err) {
63+
console.error('Error parsing JSON-RPC content:', err);
64+
}
65+
});
66+
});
67+
4868
const server = http.createServer((req, res) => {
4969
proxy.web(req, res, {}, (err) => {
5070
if (err) {

0 commit comments

Comments
 (0)