Procedurally generate EnumerableSet and EnumerableMap (#3429)

This commit is contained in:
Hadrien Croubois
2022-08-19 14:12:18 +02:00
committed by GitHub
parent c797195f1d
commit 17bc2dabe0
9 changed files with 708 additions and 15 deletions

View File

@ -0,0 +1,30 @@
function toBytes32 (type, value) {
switch (type) {
case 'bytes32':
return value;
case 'uint256':
return `bytes32(${value})`;
case 'address':
return `bytes32(uint256(uint160(${value})))`;
default:
throw new Error(`Conversion from ${type} to bytes32 not supported`);
}
}
function fromBytes32 (type, value) {
switch (type) {
case 'bytes32':
return value;
case 'uint256':
return `uint256(${value})`;
case 'address':
return `address(uint160(uint256(${value})))`;
default:
throw new Error(`Conversion from bytes32 to ${type} not supported`);
}
}
module.exports = {
toBytes32,
fromBytes32,
};