Skip to content

Instantly share code, notes, and snippets.

@Sowmayjain
Created July 1, 2019 09:27
Show Gist options
  • Save Sowmayjain/24838b6a8f19ab220cca7f97b9d2a913 to your computer and use it in GitHub Desktop.
Save Sowmayjain/24838b6a8f19ab220cca7f97b9d2a913 to your computer and use it in GitHub Desktop.
const { web3 } = require("./config");
const BN = require('bignumber.js');
const ABI = [{
"anonymous": false,
"inputs": [
{
"indexed": false,
"name": "cdpNum",
"type": "uint256"
},
{
"indexed": false,
"name": "owner",
"type": "address"
}
],
"name": "LogOpen",
"type": "event"
}];
function getTopicsAndData(logArr) {
for (let i = 0; i < logArr.length; i++) {
if (logArr[i].address == "0x0bFf4468bD9f6046b98bbbe8479C6B939397a6E2") {
if (web3.utils.keccak256('LogOpen(uint256,address)') == logArr[i].topics[0]) {
var inObj = {
data: logArr[i].data,
topics: logArr[i].topics
};
return inObj;
}
}
}
}
async function getTransactionLogs(txHash) {
try {
return await web3.eth.getTransactionReceipt(txHash);
} catch (err) {
return err;
}
}
async function decodeLogs(txHash) {
const logArr = (await getTransactionLogs(txHash)).logs;
const tdObj = getTopicsAndData(logArr); // Topic & Data Array
try {
var log = web3.eth.abi.decodeLog(ABI[0].inputs, tdObj.data, tdObj.topics);
log.cdpNum = new BN(log.cdpNum._hex).toString();
console.log(log);
} catch (err) {
console.log(err);
}
}
decodeLogs("0x6be145dbdf14a5f493f199efa694287a705b9a825c44fde8547cd2453c4e8d04");
// get new block
// loop through txn to check for registry contract
// save build() contract address in UserWallet db collection
// check for UserWallet
// check for logic proxy address - LogExecute()
// check for the internal events via logicProxy as per the logic proxy address (kyber, maker etc)
// match them with ABI and all events encoded
// save in decoded logs in db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment