UNPKG

@hashgraph/sdk

Version:
128 lines (116 loc) 3.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _ContractId = _interopRequireDefault(require("./ContractId.cjs")); var _long = _interopRequireDefault(require("long")); var protos = _interopRequireWildcard(require("@hiero-ledger/proto")); function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); } function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; } // SPDX-License-Identifier: Apache-2.0 const { proto } = protos; /** * @namespace proto * @typedef {import("@hiero-ledger/proto").proto.IContractNonceInfo} HieroProto.proto.IContractNonceInfo * @typedef {import("@hiero-ledger/proto").proto.IContractID} HieroProto.proto.IContractID * @typedef {object} ContractNonceInfoJSON * @property {string} contractId * @property {number} nonce */ /** * Info about a contract account's nonce value. * A nonce of a contract is only incremented when that contract creates another contract. */ class ContractNonceInfo { /** * @param {object} props * @param {ContractId} props.contractId * @param {Long} props.nonce */ constructor(props) { /** * Id of the contract * * @readonly */ this.contractId = props.contractId; /** * The current value of the contract account's nonce property * * @readonly */ this.nonce = props.nonce; Object.freeze(this); } /** * Extract the contractNonce from the protobuf. * * @internal * @param {HieroProto.proto.IContractNonceInfo} contractNonceInfo the protobuf * @returns {ContractNonceInfo} the contract object */ static _fromProtobuf(contractNonceInfo) { return new ContractNonceInfo({ contractId: _ContractId.default._fromProtobuf(/** @type {HieroProto.proto.IContractID} */ contractNonceInfo.contractId), nonce: contractNonceInfo.nonce != null ? contractNonceInfo.nonce : _long.default.ZERO }); } /** * Build the protobuf * * @internal * @returns {HieroProto.proto.IContractNonceInfo} the protobuf representation */ _toProtobuf() { return { contractId: this.contractId._toProtobuf(), nonce: this.nonce }; } /** * Extract the contractNonce from a byte array. * * @param {Uint8Array} bytes the byte array * @returns {ContractNonceInfo} the extracted contract nonce info */ static fromBytes(bytes) { return ContractNonceInfo._fromProtobuf(proto.ContractNonceInfo.decode(bytes)); } /** * Create a byte array representation. * * @returns {Uint8Array} the byte array representation */ toBytes() { return proto.ContractNonceInfo.encode(this._toProtobuf()).finish(); } /** * Create a JSON representation. * * @returns {ContractNonceInfoJSON} the JSON representation */ toJSON() { return { contractId: this.contractId.toString(), nonce: this.nonce.toNumber() }; } /** * @returns {string} */ toString() { return JSON.stringify(this.toJSON()); } /** * @param {this} other * @returns {boolean} */ equals(other) { return this.contractId.equals(other.contractId) && this.nonce.eq(other.nonce); } } exports.default = ContractNonceInfo;