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

34 lines
839 B
JavaScript
Raw Normal View History

2022-09-16 05:58:45 +03:00
import { getBytesCopy, hexlify } from "../../utils/index.js";
2022-09-05 23:57:11 +03:00
import { Coder } from "./abstract-coder.js";
2022-11-30 23:44:23 +03:00
/**
* @_ignore
*/
2022-09-05 23:57:11 +03:00
export class DynamicBytesCoder extends Coder {
constructor(type, localName) {
super(type, type, localName, true);
}
defaultValue() {
return "0x";
}
encode(writer, value) {
2022-09-16 05:58:45 +03:00
value = getBytesCopy(value);
2022-09-05 23:57:11 +03:00
let length = writer.writeValue(value.length);
length += writer.writeBytes(value);
return length;
}
decode(reader) {
return reader.readBytes(reader.readIndex(), true);
}
}
2022-11-30 23:44:23 +03:00
/**
* @_ignore
*/
2022-09-05 23:57:11 +03:00
export class BytesCoder extends DynamicBytesCoder {
constructor(localName) {
super("bytes", localName);
}
decode(reader) {
return hexlify(super.decode(reader));
}
}
//# sourceMappingURL=bytes.js.map