ethers.js/lib.commonjs/transaction/accesslist.js

41 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-09-05 23:57:11 +03:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.accessListify = void 0;
const index_js_1 = require("../address/index.js");
const index_js_2 = require("../utils/index.js");
function accessSetify(addr, storageKeys) {
return {
address: (0, index_js_1.getAddress)(addr),
2022-11-30 23:44:23 +03:00
storageKeys: storageKeys.map((storageKey, index) => {
(0, index_js_2.assertArgument)((0, index_js_2.isHexString)(storageKey, 32), "invalid slot", `storageKeys[${index}]`, storageKey);
2022-09-05 23:57:11 +03:00
return storageKey.toLowerCase();
})
};
}
2022-12-03 05:27:06 +03:00
/**
* Returns a [[AccessList]] from any ethers-supported access-list structure.
*/
2022-09-05 23:57:11 +03:00
function accessListify(value) {
if (Array.isArray(value)) {
return value.map((set, index) => {
if (Array.isArray(set)) {
2022-11-30 23:44:23 +03:00
(0, index_js_2.assertArgument)(set.length === 2, "invalid slot set", `value[${index}]`, set);
2022-09-05 23:57:11 +03:00
return accessSetify(set[0], set[1]);
}
2022-11-30 23:44:23 +03:00
(0, index_js_2.assertArgument)(set != null && typeof (set) === "object", "invalid address-slot set", "value", value);
2022-09-05 23:57:11 +03:00
return accessSetify(set.address, set.storageKeys);
});
}
2022-11-30 23:44:23 +03:00
(0, index_js_2.assertArgument)(value != null && typeof (value) === "object", "invalid access list", "value", value);
2022-09-05 23:57:11 +03:00
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;
}
exports.accessListify = accessListify;
//# sourceMappingURL=accesslist.js.map