@hashgraph/sdk
Version:
155 lines (140 loc) • 4.51 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _TokenId = _interopRequireDefault(require("./TokenId.cjs"));
var _CustomFee = _interopRequireDefault(require("./CustomFee.cjs"));
var _AccountId = _interopRequireDefault(require("../account/AccountId.cjs"));
var _long = _interopRequireDefault(require("long"));
var _Hbar = _interopRequireDefault(require("../Hbar.cjs"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
// SPDX-License-Identifier: Apache-2.0
/**
* @namespace proto
* @typedef {import("@hashgraph/proto").proto.ICustomFee} HieroProto.proto.ICustomFee
* @typedef {import("@hashgraph/proto").proto.IFixedFee} HieroProto.proto.IFixedFee
* @typedef {import("@hashgraph/proto").proto.IFixedCustomFee} HieroProto.proto.IFixedCustomFee
*/
class CustomFixedFee extends _CustomFee.default {
/**
* @param {object} props
* @param {AccountId | string} [props.feeCollectorAccountId]
* @param {boolean} [props.allCollectorsAreExempt]
* @param {TokenId | string} [props.denominatingTokenId]
* @param {Long | number} [props.amount]
*/
constructor(props = {}) {
super(props);
/**
* @type {?TokenId}
*/
this._denominatingTokenId = null;
if (props.denominatingTokenId != null) {
this.setDenominatingTokenId(props.denominatingTokenId);
}
/**
* @type {?Long}
*/
this._amount = null;
if (props.amount != null) {
this.setAmount(props.amount);
}
}
/**
* @param {Hbar} amount
* @returns {CustomFixedFee}
*/
setHbarAmount(amount) {
this._amount = amount.toTinybars();
this._denominatingTokenId = null;
return this;
}
/**
* @returns {TokenId | Hbar | null}
*/
get hbarAmount() {
return this._denominatingTokenId != null ? null : _Hbar.default.fromTinybars(this._amount != null ? this._amount : 0);
}
/**
* @returns {CustomFixedFee}
*/
setDenominatingTokenToSameToken() {
this._denominatingTokenId = new _TokenId.default(0, 0, 0);
return this;
}
/**
* @returns {?TokenId}
*/
get denominatingTokenId() {
return this._denominatingTokenId;
}
/**
* @param {TokenId | string} denominatingTokenId
* @returns {CustomFixedFee}
*/
setDenominatingTokenId(denominatingTokenId) {
this._denominatingTokenId = typeof denominatingTokenId === "string" ? _TokenId.default.fromString(denominatingTokenId) : denominatingTokenId;
return this;
}
/**
* @returns {?Long}
*/
get amount() {
return this._amount;
}
/**
* @param {Long | number} amount
* @returns {CustomFixedFee}
*/
setAmount(amount) {
this._amount = typeof amount === "number" ? _long.default.fromNumber(amount) : amount;
return this;
}
/**
* @internal
* @override
* @param {HieroProto.proto.ICustomFee} info
* @returns {CustomFixedFee}
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
static _fromProtobuf(info) {
const fee = /** @type {HieroProto.proto.IFixedFee} */info.fixedFee;
return new CustomFixedFee({
feeCollectorAccountId: info.feeCollectorAccountId != null ? _AccountId.default._fromProtobuf(info.feeCollectorAccountId) : undefined,
allCollectorsAreExempt: info.allCollectorsAreExempt != null ? info.allCollectorsAreExempt : undefined,
denominatingTokenId: fee.denominatingTokenId != null ? _TokenId.default._fromProtobuf(fee.denominatingTokenId) : undefined,
amount: fee.amount != null ? fee.amount : undefined
});
}
/**
* @internal
* @abstract
* @returns {HieroProto.proto.ICustomFee}
*/
_toProtobuf() {
return {
feeCollectorAccountId: this.feeCollectorAccountId != null ? this.feeCollectorAccountId._toProtobuf() : null,
allCollectorsAreExempt: this.allCollectorsAreExempt,
fixedFee: {
denominatingTokenId: this._denominatingTokenId != null ? this._denominatingTokenId._toProtobuf() : null,
amount: this._amount
}
};
}
/**
* @internal
* @abstract
* @returns {HieroProto.proto.IFixedCustomFee}
*/
_toTopicFeeProtobuf() {
return {
feeCollectorAccountId: this.feeCollectorAccountId != null ? this.feeCollectorAccountId._toProtobuf() : null,
fixedFee: {
denominatingTokenId: this._denominatingTokenId != null ? this._denominatingTokenId._toProtobuf() : null,
amount: this._amount
}
};
}
}
exports.default = CustomFixedFee;