Using checkpoints

I wanted to use the Checkpoints

Problem is that upperLookUp doesn't return the blockNumber that it found the record with. It only returns value. When user passes _blockNumber, upperLookUp searches so it finds the latest record that is less than _blockNumber, but I want to know what the block number for that record is(i know it's less than user's passed _blockNumber, but I still need to know what it is).

I have no idea why you guys haven't included to return also block number. Because of this, I'd need to write my own upperLookUp and if I write this, i really don't see much usecase to use this library at all.

Any idea how to get block number as well ?

Hi @novaknole,

The Checkpoints library is designed to store incremental values that are not necessarily indexed by their key. This is what enables storing the information in a single slot (e.g. 32 + 224).

From the use case you're describing, it seems to me that you require a mapping, which defeats the purpose of the library. I agree returning the found key would be useful, so a good middle ground would be adding the following function the Checkpoints library:

function upperLookup(Trace224 storage self, uint32 key) internal view returns (Checkpoint224) {
    uint256 len = self._checkpoints.length;
    uint256 pos = _upperBinaryLookup(self._checkpoints, key, 0, len);
    return pos == 0 ? Checkpoint224(0,0) : _unsafeAccess(self._checkpoints, pos - 1);
}