2019-08-25 02:39:20 -04:00
|
|
|
"use strict";
|
|
|
|
import { arrayify, hexlify } from "@ethersproject/bytes";
|
|
|
|
import { Coder } from "./abstract-coder";
|
|
|
|
// @TODO: Merge this with bytes
|
|
|
|
export class FixedBytesCoder extends Coder {
|
|
|
|
constructor(size, localName) {
|
|
|
|
let name = "bytes" + String(size);
|
|
|
|
super(name, name, localName, false);
|
|
|
|
this.size = size;
|
|
|
|
}
|
2020-11-23 03:43:28 -05:00
|
|
|
defaultValue() {
|
|
|
|
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
|
|
|
|
}
|
2019-08-25 02:39:20 -04:00
|
|
|
encode(writer, value) {
|
|
|
|
let data = arrayify(value);
|
|
|
|
if (data.length !== this.size) {
|
|
|
|
this._throwError("incorrect data length", value);
|
|
|
|
}
|
|
|
|
return writer.writeBytes(data);
|
|
|
|
}
|
|
|
|
decode(reader) {
|
|
|
|
return reader.coerce(this.name, hexlify(reader.readBytes(this.size)));
|
|
|
|
}
|
|
|
|
}
|
2020-07-13 08:03:56 -04:00
|
|
|
//# sourceMappingURL=fixed-bytes.js.map
|