_This library defines the Trace* struct, for checkpointing values as they change at different points in
time, and later looking up past values by block number. See {Votes} as an example.
To create a history of checkpoints define a variable type Checkpoints.Trace* in your contract, and store a new
checkpoint for the current transaction block using the {push} function._
struct Trace {
struct Checkpoints.Checkpoint[] _checkpoints;
}struct Point {
int128 bias;
int128 slope;
int128 permanent;
}struct Checkpoint {
uint48 _key;
struct Checkpoints.Point _value;
}error CheckpointUnorderedInsertions()A value was attempted to be inserted on a past checkpoint.
function push(struct Checkpoints.Trace self, uint48 key, struct Checkpoints.Point value) internal returns (struct Checkpoints.Point, struct Checkpoints.Point)_Pushes a (key, value) pair into a Trace so that it is stored as the checkpoint.
Returns previous value and new value.
IMPORTANT: Never accept key as a user input, since an arbitrary type(uint48).max key set will disable the
library._
function lowerLookup(struct Checkpoints.Trace self, uint48 key) internal view returns (struct Checkpoints.Point)Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
function upperLookup(struct Checkpoints.Trace self, uint48 key) internal view returns (bool exists, uint48 _key, struct Checkpoints.Point _value)Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
function upperLookupRecent(struct Checkpoints.Trace self, uint48 key) internal view returns (bool exists, uint48 _key, struct Checkpoints.Point _value)_Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys)._
function latest(struct Checkpoints.Trace self) internal view returns (struct Checkpoints.Point)Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
function latestCheckpoint(struct Checkpoints.Trace self) internal view returns (bool exists, uint48 _key, struct Checkpoints.Point _value)Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value in the most recent checkpoint.
function length(struct Checkpoints.Trace self) internal view returns (uint256)Returns the number of checkpoint.
function at(struct Checkpoints.Trace self, uint48 pos) internal view returns (struct Checkpoints.Checkpoint)Returns checkpoint at given position.
function blankPoint() internal pure returns (struct Checkpoints.Point)struct TraceAddress {
struct Checkpoints.CheckpointAddress[] _checkpoints;
}struct CheckpointAddress {
uint48 _key;
address _value;
}function push(struct Checkpoints.TraceAddress self, uint48 key, address value) internal returns (address, address)_Pushes a (key, value) pair into a TraceAddress so that it is stored as the checkpoint.
Returns previous value and new value.
IMPORTANT: Never accept key as a user input, since an arbitrary type(uint48).max key set will disable the
library._
function lowerLookup(struct Checkpoints.TraceAddress self, uint48 key) internal view returns (address)Returns the value in the first (oldest) checkpoint with key greater or equal than the search key, or zero if there is none.
function upperLookup(struct Checkpoints.TraceAddress self, uint48 key) internal view returns (address)Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
function upperLookupRecent(struct Checkpoints.TraceAddress self, uint48 key) internal view returns (address)_Returns the value in the last (most recent) checkpoint with key lower or equal than the search key, or zero if there is none.
NOTE: This is a variant of {upperLookup} that is optimised to find "recent" checkpoint (checkpoints with high keys)._
function latest(struct Checkpoints.TraceAddress self) internal view returns (address)Returns the value in the most recent checkpoint, or zero if there are no checkpoints.
function latestCheckpoint(struct Checkpoints.TraceAddress self) internal view returns (bool exists, uint48 _key, address _value)Returns whether there is a checkpoint in the structure (i.e. it is not empty), and if so the key and value in the most recent checkpoint.
function length(struct Checkpoints.TraceAddress self) internal view returns (uint256)Returns the number of checkpoint.
function at(struct Checkpoints.TraceAddress self, uint48 pos) internal view returns (struct Checkpoints.CheckpointAddress)Returns checkpoint at given position.