UNPKG

@ganache/utils

Version:
55 lines 1.81 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BaseJsonRpcType = void 0; const input_parsers_1 = require("./input-parsers"); const inspect = Symbol.for("nodejs.util.inspect.custom"); class BaseJsonRpcType { // used to make console.log debugging a little easier [inspect](_depth, _options) { return `[${this.constructor.name}] ${this.toString()}`; } constructor(value) { if (value == null) { this.bufferValue = null; } else if (Buffer.isBuffer(value)) { // empty buffer should be treated as null this.bufferValue = value.length === 0 ? null : value; } else { switch (typeof value) { case "string": this.bufferValue = (0, input_parsers_1.parseAndValidateStringInput)(value); break; case "number": this.bufferValue = (0, input_parsers_1.parseAndValidateNumberInput)(value); break; case "bigint": this.bufferValue = (0, input_parsers_1.parseAndValidateBigIntInput)(value); break; default: throw new Error(`Cannot wrap a "${typeof value}" as a json-rpc type`); } } } toString() { if (this.bufferValue == null) { return null; } return `0x${this.bufferValue.toString("hex")}`; } toBuffer() { return this.bufferValue; } valueOf() { return this.bufferValue; } toJSON() { return this.toString(); } isNull() { return this.bufferValue == null; } } exports.BaseJsonRpcType = BaseJsonRpcType; //# sourceMappingURL=json-rpc-base-types.js.map