ethjs/ethjs-filter

Crashing when receiving token Transfer event

danfinlay opened this issue · 4 comments

Reproduced in repository here.

The problem seems to be in this code:

function decodeEvent(eventObject, data, topics) {
  var useNumberedParams = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : true;

  var nonIndexed = eventObject.inputs.filter(function (input) {
    return !input.indexed;
  });
  var nonIndexedNames = utils.getKeys(nonIndexed, 'name', true);
  var nonIndexedTypes = utils.getKeys(nonIndexed, 'type');
  var event = decodeParams(nonIndexedNames, nonIndexedTypes, utils.hexOrBuffer(data), useNumberedParams);
  var topicOffset = eventObject.anonymous ? 0 : 1;
  eventObject.inputs.filter(function (input) {
    return input.indexed;
  }).map(function (input, i) {
    var topic = new Buffer(topics[i + topicOffset].slice(2), 'hex');
    var coder = getParamCoder(input.type);
    event[input.name] = coder.decode(topic, 0).value;
  });
  event._eventName = eventObject.name;
  return event;
}

The event is anonymous, but only has one topic, so nothing is at index 1. I don't fully get how to read this code, so I'm not sure how to fix it.

@danfinlay can you provide more info on the event data itself, name, args, some more code on your end etc?

@SilentCicero theres a whole repro repo

@kumavis I read through it, okay, it should be able to handle the anonymous portion:

var topicOffset = eventObject.anonymous ? 0 : 1;
  eventObject.inputs.filter(function (input) {
    return input.indexed;
  }).map(function (input, i) {
    var topic = new Buffer(topics[i + topicOffset].slice(2), 'hex');
    var coder = getParamCoder(input.type);
    event[input.name] = coder.decode(topic, 0).value;
  });

If the event is anonymous it sets the offset to zero. So that shouldn't be the problem. Are you getting a specific error or just no data? @danfinlay

@danfinlay you say the event is anonymous but there are no anonymous events in human-standard-token-abi thats used in the repo
https://github.com/danfinlay/human-standard-token-abi/blob/master/index.js