Merge pull request #46 from status-im/feat/trackLogs-decode

feat: allows trackLogs to decode ABIs if inputs are included in the func call
This commit is contained in:
Iuri Matias 2019-10-03 16:00:43 -04:00 committed by GitHub
commit a12f00f465
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 4 deletions

View File

@ -10,7 +10,7 @@ class LogSyncer {
this.subscriptions = [];
}
track(options, gteBlockNum){
track(options, inputsABI, gteBlockNum){
const eventKey = 'logs-' + hash(options || {});
const filterConditions = Object.assign({fromBlock: 0, toBlock: "latest"}, options || {});
@ -34,9 +34,16 @@ class LogSyncer {
removed: e.removed
}
const obsData = {blockNumber: e.blockNumber, data: e.data, address: e.address, topics: e.topics};
if(inputsABI){
eventData.returnValues = web3.eth.abi.decodeLog(inputsABI, e.data, e.topics.slice(1));
obsData.returnValues = eventData.returnValues;
}
// TODO: test reorgs
sub.next({blockNumber: e.blockNumber, data: e.data, address: e.address, topics: e.topics});
sub.next(obsData);
if(e.removed){
this.db.deleteEvent(eventKey, id);

View File

@ -111,8 +111,8 @@ export default class Subspace {
}
}
trackLogs(options) {
return this.logSyncer.track(options);
trackLogs(options, inputsABI) {
return this.logSyncer.track(options, inputsABI, this.latestBlockNumber - this.options.refreshLastNBlocks);
}
_initNewBlocksSubscription() {