ethers.js/packages/abi/src.ts/coders/null.ts

26 lines
582 B
TypeScript
Raw Permalink Normal View History

2022-04-11 17:09:17 -04:00
import { Coder } from "./abstract-coder.js";
import type { Reader, Writer } from "./abstract-coder.js";
const Empty = new Uint8Array([ ]);
export class NullCoder extends Coder {
constructor(localName: string) {
super("null", "", localName, false);
}
defaultValue(): null {
return null;
}
encode(writer: Writer, value: any): number {
if (value != null) { this._throwError("not null", value); }
return writer.writeBytes(Empty);
}
decode(reader: Reader): any {
reader.readBytes(0);
2022-04-19 03:33:55 -04:00
return null;
2022-04-11 17:09:17 -04:00
}
}