ethers.js/packages/abi/lib/coders/bytes.js

28 lines
789 B
JavaScript
Raw Permalink Normal View History

2022-04-11 17:14:19 -04:00
import { arrayify, hexlify } from "@ethersproject/bytes";
import { Coder } from "./abstract-coder.js";
export class DynamicBytesCoder extends Coder {
constructor(type, localName) {
super(type, type, localName, true);
}
defaultValue() {
return "0x";
}
encode(writer, value) {
value = arrayify(value);
let length = writer.writeValue(value.length);
length += writer.writeBytes(value);
return length;
}
decode(reader) {
return reader.readBytes(reader.readIndex(), true);
}
}
export class BytesCoder extends DynamicBytesCoder {
constructor(localName) {
super("bytes", localName);
}
decode(reader) {
2022-04-19 04:50:19 -04:00
return hexlify(super.decode(reader));
2022-04-11 17:14:19 -04:00
}
}
//# sourceMappingURL=bytes.js.map