ethers.js/packages/abi/lib/coders/address.js

26 lines
812 B
JavaScript
Raw Permalink Normal View History

2022-04-11 17:14:19 -04:00
import { getAddress } from "@ethersproject/address";
import { toHex } from "@ethersproject/math";
import { Typed } from "../typed.js";
import { Coder } from "./abstract-coder.js";
export class AddressCoder extends Coder {
constructor(localName) {
super("address", "address", localName, false);
}
defaultValue() {
return "0x0000000000000000000000000000000000000000";
}
encode(writer, _value) {
let value = Typed.dereference(_value, "string");
try {
value = getAddress(value);
}
catch (error) {
return this._throwError(error.message, _value);
}
return writer.writeValue(value);
}
decode(reader) {
return getAddress(toHex(reader.readValue(), 20));
}
}
//# sourceMappingURL=address.js.map