Current Folder
This commit is contained in:
1 parent
8b3382289b
commit
cfcada880d
4379 files changed
No files matched your search
+21
@@ -0,0 +1,21 @@
|
||||
"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;
|
||||
}
|
||||
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)));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user