Skip to main content
fix english
Source Link
Victory
  • 1.2k
  • 1
  • 8
  • 21

Unless you store the value in the contract then, you will have to loop over all events. That being said you would have to have a pretty full node to keep a log of all events ever (normally logs aare pruned from nodes when they get too old).

What might be a simpler solution (gas costs not withstanding) would be to store the max value in your contract. // store the max val uint maxVal = 0;

// store the max val
uint maxVal = 0;

// an event to notify that val has changed
event ValChange(uint _val);

function storeValue(uint _val) {
  // store biggest _val
  if (_val > maxVal) {
     maxVal = _val;
  }
  // trigger event
  ValChange(_val);
}

Unless you store the value in the contract then you will have to loop over all events. That being said you would have to have a pretty full node to keep a log of all events ever (normally logs a pruned from nodes when they get too old).

What might be a simpler solution (gas costs not withstanding) would be to store the max value in your contract. // store the max val uint maxVal = 0;

// an event to notify that val has changed
event ValChange(uint _val);

function storeValue(uint _val) {
  // store biggest _val
  if (_val > maxVal) {
     maxVal = _val;
  }
  // trigger event
  ValChange(_val);
}

Unless you store the value in the contract, you will have to loop over all events. That being said you would have to have a pretty full node to keep a log of all events ever (normally logs are pruned from nodes when they get too old).

What might be a simpler solution (gas costs not withstanding) would be to store the max value in your contract.

// store the max val
uint maxVal = 0;

// an event to notify that val has changed
event ValChange(uint _val);

function storeValue(uint _val) {
  // store biggest _val
  if (_val > maxVal) {
     maxVal = _val;
  }
  // trigger event
  ValChange(_val);
}
Source Link
Victory
  • 1.2k
  • 1
  • 8
  • 21

Unless you store the value in the contract then you will have to loop over all events. That being said you would have to have a pretty full node to keep a log of all events ever (normally logs a pruned from nodes when they get too old).

What might be a simpler solution (gas costs not withstanding) would be to store the max value in your contract. // store the max val uint maxVal = 0;

// an event to notify that val has changed
event ValChange(uint _val);

function storeValue(uint _val) {
  // store biggest _val
  if (_val > maxVal) {
     maxVal = _val;
  }
  // trigger event
  ValChange(_val);
}