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

29 lines
838 B
JavaScript
Raw Permalink Normal View History

2022-09-05 16:57:11 -04:00
import { getAddress } from "../../address/index.js";
2022-12-09 18:24:58 -05:00
import { toBeHex } from "../../utils/maths.js";
2022-09-05 16:57:11 -04:00
import { Typed } from "../typed.js";
import { Coder } from "./abstract-coder.js";
2022-11-30 15:44:23 -05:00
/**
* @_ignore
*/
2022-09-05 16:57:11 -04:00
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) {
2022-12-09 18:24:58 -05:00
return getAddress(toBeHex(reader.readValue(), 20));
2022-09-05 16:57:11 -04:00
}
}
//# sourceMappingURL=address.js.map