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

32 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2022-09-05 16:57:11 -04:00
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FixedBytesCoder = void 0;
2022-09-15 22:58:45 -04:00
const index_js_1 = require("../../utils/index.js");
2022-09-05 16:57:11 -04:00
const typed_js_1 = require("../typed.js");
const abstract_coder_js_1 = require("./abstract-coder.js");
2022-11-30 15:44:23 -05:00
/**
* @_ignore
*/
2022-09-05 16:57:11 -04:00
class FixedBytesCoder extends abstract_coder_js_1.Coder {
size;
constructor(size, localName) {
let name = "bytes" + String(size);
super(name, name, localName, false);
2022-09-15 22:58:45 -04:00
(0, index_js_1.defineProperties)(this, { size }, { size: "number" });
2022-09-05 16:57:11 -04:00
}
defaultValue() {
return ("0x0000000000000000000000000000000000000000000000000000000000000000").substring(0, 2 + this.size * 2);
}
encode(writer, _value) {
2022-09-15 22:58:45 -04:00
let data = (0, index_js_1.getBytesCopy)(typed_js_1.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) {
2022-09-15 22:58:45 -04:00
return (0, index_js_1.hexlify)(reader.readBytes(this.size));
2022-09-05 16:57:11 -04:00
}
}
exports.FixedBytesCoder = FixedBytesCoder;
//# sourceMappingURL=fixed-bytes.js.map