Created
November 16, 2020 13:03
-
-
Save josh-richardson/01f115f4084c861d7d78a92217bfe2b9 to your computer and use it in GitHub Desktop.
Horrible hack to intercept Web3js requests in node. Probably extremely fragile.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Web3RequestLogger(httpProvider) { | |
let handler = { | |
get(target, propKey, receiver) { | |
const origMethod = Reflect.get(target, propKey, receiver); | |
if (propKey === "send") { | |
return function (...args) { | |
console.log(`Sent JSONRPC Request: ${JSON.stringify(args[0])}`); | |
let responseCallback = function(err, result) { | |
console.log(`Received JSONRPC Response: ${JSON.stringify(result)}`) | |
args[1](err, result) | |
}; | |
return origMethod.apply(this, [args[0], responseCallback]); | |
}; | |
} | |
return origMethod; | |
} | |
}; | |
return new Proxy(httpProvider, handler); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Similar functionality can be achieved using web3-provider-engine, however I think it only supports HTTP rather than websockets.