lotus-sdk
Version:
Central repository for several classes of tools for integrating with, and building for, the Lotusia ecosystem
47 lines (46 loc) • 926 B
JavaScript
export class Chunk {
buf;
len;
opcodenum;
constructor(data) {
if (data) {
this.buf = data.buf;
this.len = data.len;
this.opcodenum = data.opcodenum;
}
else {
this.opcodenum = 0;
}
}
isOpCode() {
return !this.buf && this.opcodenum !== undefined;
}
hasData() {
return !!this.buf;
}
getLength() {
return this.len || 0;
}
getBuffer() {
return this.buf;
}
getOpCode() {
return this.opcodenum;
}
toString() {
if (this.isOpCode()) {
return `OP_${this.opcodenum}`;
}
else if (this.buf) {
return this.buf.toString('hex');
}
return '';
}
toObject() {
return {
buf: this.buf,
len: this.len,
opcodenum: this.opcodenum,
};
}
}