@hiero-ledger/sdk
Version:
175 lines (158 loc) • 6.78 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _ScheduleId = _interopRequireDefault(require("./ScheduleId.cjs"));
var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
var _Timestamp = _interopRequireDefault(require("../Timestamp.cjs"));
var _Transaction = _interopRequireDefault(require("../transaction/Transaction.cjs"));
var HieroProto = _interopRequireWildcard(require("@hashgraph/proto"));
var _TransactionId = _interopRequireDefault(require("../transaction/TransactionId.cjs"));
var _Key = _interopRequireDefault(require("../Key.cjs"));
var _KeyList = _interopRequireDefault(require("../KeyList.cjs"));
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
} = HieroProto;
/**
* Response when the client sends the node ScheduleGetInfoQuery.
*/
class ScheduleInfo {
/**
* @private
* @param {object} props
* @param {ScheduleId} props.scheduleId;
* @param {?AccountId} props.creatorAccountID;
* @param {?AccountId} props.payerAccountID;
* @param {?HieroProto.proto.ISchedulableTransactionBody} props.schedulableTransactionBody;
* @param {?Key} props.adminKey
* @param {?KeyList} props.signers;
* @param {?string} props.scheduleMemo;
* @param {?Timestamp} props.expirationTime;
* @param {?Timestamp} props.executed;
* @param {?Timestamp} props.deleted;
* @param {?TransactionId} props.scheduledTransactionId;
* @param {boolean} props.waitForExpiry;
*/
constructor(props) {
/**
* @readonly
*/
this.scheduleId = props.scheduleId;
/**
* @readonly
*/
this.creatorAccountId = props.creatorAccountID;
/**
* @readonly
*/
this.payerAccountId = props.payerAccountID;
/**
* @readonly
*/
this.schedulableTransactionBody = props.schedulableTransactionBody;
/**
* @readonly
*/
this.signers = props.signers;
/**
* @readonly
*/
this.scheduleMemo = props.scheduleMemo;
/**
* @readonly
*/
this.adminKey = props.adminKey != null ? props.adminKey : null;
/**
* @readonly
*/
this.expirationTime = props.expirationTime;
/**
* @readonly
*/
this.executed = props.executed;
/**
* @readonly
*/
this.deleted = props.deleted;
/**
* @readonly
*/
this.scheduledTransactionId = props.scheduledTransactionId;
/**
*
* @readonly
*/
this.waitForExpiry = props.waitForExpiry;
Object.freeze(this);
}
/**
* @internal
* @param {HieroProto.proto.IScheduleInfo} info
* @returns {ScheduleInfo}
*/
static _fromProtobuf(info) {
return new ScheduleInfo({
scheduleId: _ScheduleId.default._fromProtobuf(/** @type {HieroProto.proto.IScheduleID} */info.scheduleID),
creatorAccountID: info.creatorAccountID != null ? _AccountId.default._fromProtobuf(/** @type {HieroProto.proto.IAccountID} */
info.creatorAccountID) : null,
payerAccountID: info.payerAccountID != null ? _AccountId.default._fromProtobuf(/** @type {HieroProto.proto.IAccountID} */
info.payerAccountID) : null,
schedulableTransactionBody: info.scheduledTransactionBody != null ? info.scheduledTransactionBody : null,
adminKey: info.adminKey != null ? _Key.default._fromProtobufKey(info.adminKey) : null,
signers: info.signers != null ? _KeyList.default.__fromProtobufKeyList(info.signers) : null,
scheduleMemo: info.memo != null ? info.memo : null,
expirationTime: info.expirationTime != null ? _Timestamp.default._fromProtobuf(/** @type {HieroProto.proto.ITimestamp} */
info.expirationTime) : null,
executed: info.executionTime != null ? _Timestamp.default._fromProtobuf(/** @type {HieroProto.proto.ITimestamp} */
info.executionTime) : null,
deleted: info.deletionTime != null ? _Timestamp.default._fromProtobuf(/** @type {HieroProto.proto.ITimestamp} */
info.deletionTime) : null,
scheduledTransactionId: info.scheduledTransactionID != null ? _TransactionId.default._fromProtobuf(info.scheduledTransactionID) : null,
waitForExpiry: info.waitForExpiry != null ? info.waitForExpiry : false
});
}
/**
* @returns {HieroProto.proto.IScheduleInfo}
*/
_toProtobuf() {
return {
scheduleID: this.scheduleId != null ? this.scheduleId._toProtobuf() : null,
creatorAccountID: this.creatorAccountId != null ? this.creatorAccountId._toProtobuf() : null,
payerAccountID: this.payerAccountId != null ? this.payerAccountId._toProtobuf() : null,
scheduledTransactionBody: this.schedulableTransactionBody != null ? this.schedulableTransactionBody : null,
adminKey: this.adminKey != null ? this.adminKey._toProtobufKey() : null,
signers: this.signers != null ? this.signers._toProtobufKey().keyList : null,
memo: this.scheduleMemo != null ? this.scheduleMemo : "",
expirationTime: this.expirationTime != null ? this.expirationTime._toProtobuf() : null,
scheduledTransactionID: this.scheduledTransactionId != null ? this.scheduledTransactionId._toProtobuf() : null,
waitForExpiry: this.waitForExpiry
};
}
/**
* @returns {Transaction}
*/
get scheduledTransaction() {
if (this.schedulableTransactionBody == null) {
throw new Error("Scheduled transaction body is empty");
}
const scheduled = new proto.SchedulableTransactionBody(this.schedulableTransactionBody);
const data = /** @type {NonNullable<HieroProto.proto.SchedulableTransactionBody["data"]>} */
scheduled.data;
return _Transaction.default.fromBytes(proto.TransactionList.encode({
transactionList: [{
signedTransactionBytes: proto.SignedTransaction.encode({
bodyBytes: proto.TransactionBody.encode({
transactionFee: this.schedulableTransactionBody.transactionFee,
memo: this.schedulableTransactionBody.memo,
[data]: scheduled[data]
}).finish()
}).finish()
}]
}).finish());
}
}
exports.default = ScheduleInfo;