Skip to content

Commit

Permalink
chore(proxyRpc): log txHash and error response
Browse files Browse the repository at this point in the history
  • Loading branch information
RetricSu committed Nov 19, 2024
1 parent f27b53d commit a1bd020
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/tools/rpc-proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function createRPCProxy(network: Network, targetRpcUrl: string, port: num
}
const txFile = path.resolve(settings.devnet.transactionsPath, `${txHash}.json`);
fs.writeFileSync(txFile, JSON.stringify(tx, null, 2));
console.debug(`RPC Req: store tx ${txHash}`);
}
}
} catch (err) {
Expand All @@ -45,6 +46,25 @@ export function createRPCProxy(network: Network, targetRpcUrl: string, port: num
});
});

proxy.on('proxyRes', function (proxyRes, _req, _res) {
const body: Buffer[] = [];
proxyRes.on('data', function (chunk) {
body.push(chunk);
});
proxyRes.on('end', function () {
const res = Buffer.concat(body).toString();
try {
const jsonRpcResponse = JSON.parse(res);
const error = jsonRpcResponse.error;
if (error) {
console.debug('RPC Response: ', jsonRpcResponse);
}
} catch (err) {
console.error('Error parsing JSON-RPC content:', err);
}
});
});

const server = http.createServer((req, res) => {
proxy.web(req, res, {}, (err) => {
if (err) {
Expand Down

0 comments on commit a1bd020

Please sign in to comment.