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

26 lines
789 B
JavaScript
Raw Normal View History

"use strict";
import { arrayify, hexlify } from "@ethersproject/bytes";
import { Coder } from "./abstract-coder";
export class DynamicBytesCoder extends Coder {
constructor(type, localName) {
super(type, type, localName, true);
}
encode(writer, value) {
value = arrayify(value);
let length = writer.writeValue(value.length);
length += writer.writeBytes(value);
return length;
}
decode(reader) {
2020-09-08 02:55:52 +03:00
return reader.readBytes(reader.readValue().toNumber(), true);
}
}
export class BytesCoder extends DynamicBytesCoder {
constructor(localName) {
super("bytes", localName);
}
decode(reader) {
return reader.coerce(this.name, hexlify(super.decode(reader)));
}
}
2020-07-13 15:03:56 +03:00
//# sourceMappingURL=bytes.js.map