0

I have a function that fires an event at the end, I have more than one that works like this to create some kind of lifecycle through events.

I get the full event history for every event as excpected, except for one.

Right after calling the function to contribute events will be recollected and the event will show up , but when the page is refreshed and the call to collect events is sent again the event will have disappeared.

I am 100% certain the events get fired as they show up initially and I can retrieve the data that the function put there.

This is the function in solidity:

  function contribute(BountyInterface.Bounty storage _bounty, uint _amount) external {
    //For now accept only contributions in the token that the bounty is in
    require(_bounty.status == BountyInterface.statusOptions.ACTIVE);
    BountyInterface.Contribution memory newContribution;
    newContribution.contributer = msg.sender;
    newContribution.token = _bounty.token;
    newContribution.amount = _amount;
    newContribution.timestamp = now;
    _bounty.contributions.push(newContribution);
    _bounty.totalContributions += _amount; //SAFEMATH THIS
    if (!ERC20(_bounty.token).transferFrom(msg.sender, _bounty.self, _amount)) revert();
    emit logContribute(msg.sender, _bounty.self, _amount, now);
  }

This is the function that calls the events, as you can see the calls work identical (yes I should refactor this to be DRY), yet one doesn't work as its supposed to

export async function bountyActivityFeed(address) {
  try {
    //We can get created from the timestamp
    //startWork
    let event = (new Interface(BountyLib.abi)).events.logStartWork
    console.log(event.topics)
    let topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
    let startWorkLogs = await this.provider.getLogs({
      fromBlock: 1,
      toBlock: 'latest',
      topics: topics
    })
    startWorkLogs = startWorkLogs.map(log => {
      let ev = event.parse(log.topics, log.data)
      return {
        by: ev._by,
        timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
        type: 'startWork',
        extraData: null
      }
    })
    //Commits
    event = (new Interface(BountyLib.abi)).events.logSubmission
    topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
    let submissionLogs = await this.provider.getLogs({
      fromBlock: 1,
      toBlock: 'latest',
      topics: topics
    })
    submissionLogs = submissionLogs.map(log => {
      let ev = event.parse(log.topics, log.data)
      return {
        by: ev._by,
        timestamp:moment((ev._timestamp.toString(10) * 1000), "x"),
        type: 'commit',
        extraData: ev._id
      }
    })
    //contributions
    event = (new Interface(BountyLib.abi)).events.logContribute
    topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
    let contributionLogs = await this.provider.getLogs({
      fromblock: 1,
      toBlock: 'latest',
      topics: topics
    })
    contributionLogs = contributionLogs.map(log => {
      console.log(log)
      let ev = event.parse(log.topics, log.data)
      return {
        by: ev._by,
        timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
        type: 'contribute',
        extraData: parseFloat(formatEther(ev._amount)).toFixed(2)
      }
    })
    //Acceptance
    event = (new Interface(BountyLib.abi)).events.logAccepted
    topics = [event.topics[0], null, hexlify(padZeros(arrayify(address), 32))]
    let acceptedLog = await this.provider.getLogs({
      fromBlock: 1,
      toBlock: 'latest',
      topics: topics
    })
    acceptedLog = acceptedLog.map(log => {
      let ev = event.parse(log.topics, log.data)
      return {
        by: ev._winner,
        timestamp: moment((ev._timestamp.toString(10) * 1000), "x"),
        type: 'accepted'
      }
    })
    let activityLog = [...startWorkLogs, ...submissionLogs, ...contributionLogs, ...acceptedLog]
    activityLog = activityLog.sort((a, b) => {
      if (a.timestamp.isBefore(b.timestamp)) {
        return -1
      } else {
        return 1
      }
    })
    return activityLog
  } catch (err) {
    console.log(err)
  }
}

I also have a function to get the data that was posted by the contribute() function. When I look for the events and the data I get an empty array for the events, whereas the getter gives me the right data.

*getContribution()*
Array(3) [ {…}, {…}, {…} ]

*logContribute*
ContributionLogs 
[],
length: 0

I'm using a private chain for this one, I have a blockchain explorer running for it too and can confirm the transactions get executed and the log is there.

Additionally I'm using ethers.js 3.0.0

Any ideas?

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.