ethers.js/lib.esm/transaction/accesslist.js
2022-09-05 16:57:11 -04:00

38 lines
1.4 KiB
JavaScript

import { getAddress } from "../address/index.js";
import { dataLength } from "../utils/index.js";
function accessSetify(addr, storageKeys) {
return {
address: getAddress(addr),
storageKeys: (storageKeys || []).map((storageKey, index) => {
if (dataLength(storageKey) !== 32) {
//logger.throwArgumentError("invalid access list storageKey", `accessList[${ addr }>
throw new Error("");
}
return storageKey.toLowerCase();
})
};
}
export function accessListify(value) {
if (Array.isArray(value)) {
return value.map((set, index) => {
if (Array.isArray(set)) {
if (set.length > 2) {
//logger.throwArgumentError("access list expected to be [ address, storageKeys[>
throw new Error("");
}
return accessSetify(set[0], set[1]);
}
return accessSetify(set.address, set.storageKeys);
});
}
const result = Object.keys(value).map((addr) => {
const storageKeys = value[addr].reduce((accum, storageKey) => {
accum[storageKey] = true;
return accum;
}, {});
return accessSetify(addr, Object.keys(storageKeys).sort());
});
result.sort((a, b) => (a.address.localeCompare(b.address)));
return result;
}
//# sourceMappingURL=accesslist.js.map