Add checkpoint variant with uint256 keys and values (#5748)
Co-authored-by: Hadrien Croubois <hadrien.croubois@gmail.com>
This commit is contained in:
@ -223,7 +223,7 @@ function _unsafeAccess(
|
||||
) private pure returns (${opts.checkpointTypeName} storage result) {
|
||||
assembly {
|
||||
mstore(0, self.slot)
|
||||
result.slot := add(keccak256(0, 0x20), pos)
|
||||
result.slot := add(keccak256(0, 0x20), ${opts.checkpointSize === 1 ? 'pos' : `mul(pos, ${opts.checkpointSize})`})
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@ -1,11 +1,12 @@
|
||||
// OPTIONS
|
||||
const VALUE_SIZES = [224, 208, 160];
|
||||
const VALUE_SIZES = [256, 224, 208, 160];
|
||||
|
||||
const defaultOpts = size => ({
|
||||
historyTypeName: `Trace${size}`,
|
||||
checkpointTypeName: `Checkpoint${size}`,
|
||||
checkpointFieldName: '_checkpoints',
|
||||
keyTypeName: `uint${256 - size}`,
|
||||
checkpointSize: size < 256 ? 1 : 2,
|
||||
keyTypeName: size < 256 ? `uint${256 - size}` : 'uint256',
|
||||
keyFieldName: '_key',
|
||||
valueTypeName: `uint${size}`,
|
||||
valueFieldName: '_value',
|
||||
|
||||
@ -24,7 +24,11 @@ Checkpoints.${opts.historyTypeName} internal _ckpts;
|
||||
function _bound${capitalize(opts.keyTypeName)}(${opts.keyTypeName} x, ${opts.keyTypeName} min, ${
|
||||
opts.keyTypeName
|
||||
} max) internal pure returns (${opts.keyTypeName}) {
|
||||
return SafeCast.to${capitalize(opts.keyTypeName)}(bound(uint256(x), uint256(min), uint256(max)));
|
||||
return ${
|
||||
opts.keyTypeName === 'uint256'
|
||||
? 'bound(x, min, max)'
|
||||
: `SafeCast.to${capitalize(opts.keyTypeName)}(bound(uint256(x), uint256(min), uint256(max)))`
|
||||
};
|
||||
}
|
||||
|
||||
function _prepareKeys(${opts.keyTypeName}[] memory keys, ${opts.keyTypeName} maxSpread) internal pure {
|
||||
|
||||
Reference in New Issue
Block a user