@hashgraph/sdk
Version:
163 lines (144 loc) • 4.37 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var entity_id = _interopRequireWildcard(require("../EntityIdHelper.cjs"));
var HieroProto = _interopRequireWildcard(require("@hashgraph/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); }
// SPDX-License-Identifier: Apache-2.0
/**
* @typedef {import("long")} Long
* @typedef {import("../client/Client.js").default<*, *>} Client
*/
/**
* Class representing a unique identifier for a scheduled transaction on the Hedera network.
*
* A ScheduleId consists of three components:
* Shard ID: The shard number where the schedule exists
* Realm ID: The realm number within the shard
* Schedule Number: The unique number identifying the schedule
* @augments {EntityId<HieroProto.proto.IScheduleID>}
*/
class ScheduleId {
/**
* @param {number | Long | import("../EntityIdHelper").IEntityId} props
* @param {(number | Long)=} realm
* @param {(number | Long)=} num
*/
constructor(props, realm, num) {
const result = entity_id.constructor(props, realm, num);
this.shard = result.shard;
this.realm = result.realm;
this.num = result.num;
/**
* @type {string | null}
*/
this._checksum = null;
}
/**
* @param {string} text
* @returns {ScheduleId}
*/
static fromString(text) {
const result = entity_id.fromString(text);
const id = new ScheduleId(result);
id._checksum = result.checksum;
return id;
}
/**
* @internal
* @param {HieroProto.proto.IScheduleID} id
* @returns {ScheduleId}
*/
static _fromProtobuf(id) {
const scheduleId = new ScheduleId(id.shardNum != null ? id.shardNum : 0, id.realmNum != null ? id.realmNum : 0, id.scheduleNum != null ? id.scheduleNum : 0);
return scheduleId;
}
/**
* @returns {string | null}
*/
get checksum() {
return this._checksum;
}
/**
* @deprecated - Use `validateChecksum` instead
* @param {Client} client
*/
validate(client) {
console.warn("Deprecated: Use `validateChecksum` instead");
this.validateChecksum(client);
}
/**
* @param {Client} client
*/
validateChecksum(client) {
entity_id.validateChecksum(this.shard, this.realm, this.num, this._checksum, client);
}
/**
* @param {Uint8Array} bytes
* @returns {ScheduleId}
*/
static fromBytes(bytes) {
return ScheduleId._fromProtobuf(HieroProto.proto.ScheduleID.decode(bytes));
}
/**
* @param {string} address
* @returns {ScheduleId}
*/
static fromSolidityAddress(address) {
return new ScheduleId(...entity_id.fromSolidityAddress(address));
}
/**
* @returns {string}
*/
toSolidityAddress() {
return entity_id.toSolidityAddress([this.shard, this.realm, this.num]);
}
/**
* @internal
* @returns {HieroProto.proto.ScheduleID}
*/
_toProtobuf() {
return {
scheduleNum: this.num,
shardNum: this.shard,
realmNum: this.realm
};
}
/**
* @returns {string}
*/
toString() {
return `${this.shard.toString()}.${this.realm.toString()}.${this.num.toString()}`;
}
/**
* @param {Client} client
* @returns {string}
*/
toStringWithChecksum(client) {
return entity_id.toStringWithChecksum(this.toString(), client);
}
/**
* @returns {Uint8Array}
*/
toBytes() {
return HieroProto.proto.ScheduleID.encode(this._toProtobuf()).finish();
}
/**
* @returns {ScheduleId}
*/
clone() {
const id = new ScheduleId(this);
id._checksum = this._checksum;
return id;
}
/**
* @param {ScheduleId} other
* @returns {number}
*/
compare(other) {
return entity_id.compare([this.shard, this.realm, this.num], [other.shard, other.realm, other.num]);
}
}
exports.default = ScheduleId;