All files / src/common Serializable.ts

77.77% Statements 7/9
100% Branches 0/0
66.66% Functions 2/3
77.77% Lines 7/9

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 234x 4x   4x         18x 17x       4x 4x                
import { ethers } from "ethers";
import { hexlifyWithout0xPrefix } from "./utils";
 
export abstract class Serializable {
  abstract toBytes(): Uint8Array;
  abstract toObj(): object;
 
  toBytesHex(): string {
    const serializedBytes = this.toBytes();
    return ethers.utils.hexlify(serializedBytes);
  }
 
  toBytesHexWithout0xPrefix(): string {
    const serializedBytes = this.toBytes();
    return hexlifyWithout0xPrefix(serializedBytes);
  }
 
  toJSON() {
    const serializedPlainObj = this.toObj();
    return JSON.stringify(serializedPlainObj);
  }
}