ethers.js/lib.esm/abi/coders/fixed-bytes.js

28 lines
956 B
JavaScript
Raw Permalink Normal View History

2022-09-15 22:58:45 -04:00
import { defineProperties, getBytesCopy, hexlify } from "../../utils/index.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 FixedBytesCoder extends Coder {
size;
constructor(size, localName) {
let name = "bytes" + String(size);
super(name, name, localName, false);
defineProperties(this, { size }, { size: "number" });
}
defaultValue() {
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
}
encode(writer, _value) {
2022-09-15 22:58:45 -04:00
let data = getBytesCopy(Typed.dereference(_value, this.type));
2022-09-05 16:57:11 -04:00
if (data.length !== this.size) {
this._throwError("incorrect data length", _value);
}
return writer.writeBytes(data);
}
decode(reader) {
return hexlify(reader.readBytes(this.size));
}
}
//# sourceMappingURL=fixed-bytes.js.map