Last active
July 24, 2020 14:52
-
-
Save svetlanama/b8d59d281c7560837feea18e9659338a to your computer and use it in GitHub Desktop.
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
// Decode LogNote | |
// https://github.com/makerdao/dss/blob/6fa55812a5fcfcfa325ad4d9a4d0ca4033c38cab/src/lib.sol | |
// ethers@4 | |
const logNoteAbi = [ | |
{ | |
inputs: [ | |
{ indexed: true, name: 'sig', type: 'bytes4' }, | |
{ indexed: true, name: 'usr', type: 'address' }, | |
{ indexed: true, name: 'arg1', type: 'bytes32' }, | |
{ indexed: true, name: 'arg2', type: 'bytes32' }, | |
{ indexed: false, name: 'data', type: 'bytes' } | |
], | |
name: 'LogNote', | |
type: 'event', | |
}, | |
]; | |
const logNoteIface = new ethers.utils.Interface(logNoteAbi); | |
function parseLogNote(topics, data){ | |
try { | |
return logNoteIface.parseLog({ | |
data: data, | |
topics: [logNoteIface.events.LogNote.topic, ...topics], | |
}); | |
} catch (e) { | |
console.log(e) | |
return; | |
} | |
} | |
// Put all topics | |
// from https://etherscan.io/address/<contract_address>#events | |
let topics = [ | |
"0x65fae35e000000000000000000000000...", | |
"0x000000000000000000000000...", | |
"0x00000000000000000000000009...", | |
"0x0000000000000000000000000000000000..." | |
] | |
// Copy all 9 lines HEX data | |
// from https://etherscan.io/address/<contract_address>#events | |
let data = "0x0000000000000000000....3804d9382a48db0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000" | |
let resParseDsNote = parseLogNote(topics, data) | |
console.log("resParseDsNote: ", resParseDsNote) | |
/* Response: | |
_LogDescription { | |
decode: [Function], | |
name: 'LogNote', | |
signature: 'LogNote(bytes4,address,bytes32,bytes32,bytes)', | |
topic: '0xd3d8bec38a...', | |
values: Result { | |
'0': '0x65f..', | |
'1': '0xabcdedf....', | |
'2': '0x000000....', | |
'3': '0x0000000000....', | |
'4': '0x65fa....', | |
sig: '0x65f....', | |
usr: '0xabcd...', | |
arg1: '0x000000000....', | |
arg2: '0x000000000000000....', | |
data: '0x65f....', | |
length: 5 | |
} | |
} | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment