@hashgraph/sdk
Version:
176 lines (159 loc) • 6.95 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 _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
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;