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

29 lines
603 B
TypeScript
Raw Normal View History

2022-09-05 23:14:43 +03:00
import { Coder } from "./abstract-coder.js";
import type { Reader, Writer } from "./abstract-coder.js";
const Empty = new Uint8Array([ ]);
2022-11-28 05:54:49 +03:00
/**
* @_ignore
*/
2022-09-05 23:14:43 +03:00
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);
return null;
}
}