@hiero-ledger/sdk
Version:
159 lines (144 loc) • 5.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _AccountId = _interopRequireDefault(require("./account/AccountId.cjs"));
var _Hbar = _interopRequireDefault(require("./Hbar.cjs"));
var _Timestamp = _interopRequireDefault(require("./Timestamp.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); }
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// SPDX-License-Identifier: Apache-2.0
/**
* @typedef {import("long")} Long
*/
/**
* @typedef {object} StakingInfoJson
* @property {boolean} declineStakingReward
* @property {?string} stakePeriodStart
* @property {?string} pendingReward
* @property {?string} stakedToMe
* @property {?string} stakedAccountId
* @property {?string} stakedNodeId
*/
/**
* Staking metadata for an account or a contract returned in CryptoGetInfo or ContractGetInfo queries
*/
class StakingInfo {
/**
* @private
* @param {object} props
* @param {boolean} props.declineStakingReward
* @param {?Timestamp} props.stakePeriodStart
* @param {?Hbar} props.pendingReward
* @param {?Hbar} props.stakedToMe
* @param {?AccountId} props.stakedAccountId
* @param {?Long} props.stakedNodeId
*/
constructor(props) {
/**
* If true, this account or contract declined to receive a staking reward.
*
* @readonly
*/
this.declineStakingReward = props.declineStakingReward;
/**
* The staking period during which either the staking settings for this
* account or contract changed (such as starting staking or changing
* staked_node_id) or the most recent reward was earned, whichever is
* later. If this account or contract is not currently staked to a
* node, then this field is not set.
*
* @readonly
*/
this.stakePeriodStart = props.stakePeriodStart;
/**
* The amount in tinybars that will be received in the next reward
* situation.
*
* @readonly
*/
this.pendingReward = props.pendingReward;
/**
* The total of balance of all accounts staked to this account or contract.
*
* @readonly
*/
this.stakedToMe = props.stakedToMe;
/**
* The account to which this account or contract is staking.
*
* @readonly
*/
this.stakedAccountId = props.stakedAccountId;
/**
* The ID of the node this account or contract is staked to.
*
* @readonly
*/
this.stakedNodeId = props.stakedNodeId;
Object.freeze(this);
}
/**
* @internal
* @param {HieroProto.proto.IStakingInfo} info
* @returns {StakingInfo}
*/
static _fromProtobuf(info) {
return new StakingInfo({
declineStakingReward: info.declineReward == true,
stakePeriodStart: info.stakePeriodStart != null ? _Timestamp.default._fromProtobuf(info.stakePeriodStart) : null,
pendingReward: info.pendingReward != null ? _Hbar.default.fromTinybars(info.pendingReward) : null,
stakedToMe: info.stakedToMe != null ? _Hbar.default.fromTinybars(info.stakedToMe) : null,
stakedAccountId: info.stakedAccountId != null ? _AccountId.default._fromProtobuf(info.stakedAccountId) : null,
stakedNodeId: info.stakedNodeId != null ? info.stakedNodeId : null
});
}
/**
* @returns {HieroProto.proto.IStakingInfo}
*/
_toProtobuf() {
return {
declineReward: this.declineStakingReward,
stakePeriodStart: this.stakePeriodStart != null ? this.stakePeriodStart._toProtobuf() : null,
pendingReward: this.pendingReward != null ? this.pendingReward.toTinybars() : null,
stakedToMe: this.stakedToMe != null ? this.stakedToMe.toTinybars() : null,
stakedAccountId: this.stakedAccountId != null ? this.stakedAccountId._toProtobuf() : null,
stakedNodeId: this.stakedNodeId
};
}
/**
* @param {Uint8Array} bytes
* @returns {StakingInfo}
*/
static fromBytes(bytes) {
return StakingInfo._fromProtobuf(HieroProto.proto.StakingInfo.decode(bytes));
}
/**
* @returns {Uint8Array}
*/
toBytes() {
return HieroProto.proto.StakingInfo.encode(this._toProtobuf()).finish();
}
/**
* @returns {string}
*/
toString() {
return JSON.stringify(this.toJSON());
}
/**
* @returns {StakingInfoJson}
*/
toJSON() {
return {
declineStakingReward: this.declineStakingReward,
stakePeriodStart: this.stakePeriodStart != null ? this.stakePeriodStart.toString() : null,
pendingReward: this.pendingReward != null ? this.pendingReward.toString() : null,
stakedToMe: this.stakedToMe != null ? this.stakedToMe.toString() : null,
stakedAccountId: this.stakedAccountId != null ? this.stakedAccountId.toString() : null,
stakedNodeId: this.stakedNodeId != null ? this.stakedNodeId.toString() : null
};
}
}
exports.default = StakingInfo;