2019-05-14 18:25:46 -04:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
import { getAddress } from "@ethersproject/address";
|
|
|
|
import { hexZeroPad } from "@ethersproject/bytes";
|
|
|
|
|
|
|
|
import { Coder, Reader, Writer } from "./abstract-coder";
|
|
|
|
|
|
|
|
export class AddressCoder extends Coder {
|
|
|
|
|
|
|
|
constructor(localName: string) {
|
|
|
|
super("address", "address", localName, false);
|
|
|
|
}
|
|
|
|
|
2020-11-23 00:59:44 -05:00
|
|
|
defaultValue(): string {
|
|
|
|
return "0x0000000000000000000000000000000000000000";
|
|
|
|
}
|
|
|
|
|
2019-05-14 18:25:46 -04:00
|
|
|
encode(writer: Writer, value: string): number {
|
|
|
|
try {
|
|
|
|
getAddress(value);
|
|
|
|
} catch (error) {
|
|
|
|
this._throwError(error.message, value);
|
|
|
|
}
|
|
|
|
return writer.writeValue(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
decode(reader: Reader): any {
|
|
|
|
return getAddress(hexZeroPad(reader.readValue().toHexString(), 20));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|