Skip to content

Commit

Permalink
Update template
Browse files Browse the repository at this point in the history
  • Loading branch information
0xVolosnikov committed Aug 28, 2023
1 parent da54fc0 commit 03d713e
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions scripts/generate/templates/Checkpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function latestCheckpoint(${opts.historyTypeName} storage self)
if (pos == 0) {
return (false, 0, 0);
} else {
${opts.checkpointTypeName} memory ckpt = _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1);
${opts.checkpointTypeName} storage ckpt = _unsafeAccess(self.${opts.checkpointFieldName}, pos - 1);
return (true, ckpt.${opts.keyFieldName}, ckpt.${opts.valueFieldName});
}
}
Expand Down Expand Up @@ -147,21 +147,22 @@ function _insert(
uint256 pos = self.length;
if (pos > 0) {
// Copying to memory is important here.
${opts.checkpointTypeName} memory last = _unsafeAccess(self, pos - 1);
${opts.checkpointTypeName} storage last = _unsafeAccess(self, pos - 1);
${opts.keyTypeName} lastKey = last._key;
${opts.valueTypeName} lastValue = last._value;
// Checkpoint keys must be non-decreasing.
if(last.${opts.keyFieldName} > key) {
if (lastKey > key) {
revert CheckpointUnorderedInsertion();
}
// Update or push new checkpoint
if (last.${opts.keyFieldName} == key) {
if (lastKey == key) {
_unsafeAccess(self, pos - 1).${opts.valueFieldName} = value;
} else {
self.push(${opts.checkpointTypeName}({${opts.keyFieldName}: key, ${opts.valueFieldName}: value}));
}
return (last.${opts.valueFieldName}, value);
return (lastValue, value);
} else {
self.push(${opts.checkpointTypeName}({${opts.keyFieldName}: key, ${opts.valueFieldName}: value}));
return (0, value);
Expand Down

0 comments on commit 03d713e

Please sign in to comment.