@hashgraph/sdk
Version:
110 lines (101 loc) • 4.26 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var HieroProto = _interopRequireWildcard(require("@hashgraph/proto"));
var _FeeComponents = _interopRequireDefault(require("./FeeComponents.cjs"));
var _FeeDataType = _interopRequireDefault(require("./FeeDataType.cjs"));
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
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
/**
* A total fee, in component amounts charged for a transaction.
*
* Total fees are composed of three sets of components.
* - Node data, components that compensate the specific node that submitted
* the transaction.
* - Network data, components that compensate the Hedera network for gossiping
* the transaction and determining the consensus timestamp.
* - Service data, components that compensate the Hedera network for the ongoing
* maintenance and operation of the network, as well as ongoing development
* of network services.
*
* Fee components are recorded in thousandths of a tiny cent, and the network
* exchange rate converts these to tinybar amounts, which are what the network
* charges for transactions and what the network reports in the record stream.
*/
class FeeData {
/**
* @param {object} [props]
* @param {FeeComponents} [props.nodedata]
* @param {FeeComponents} [props.networkdata]
* @param {FeeComponents} [props.servicedata]
* @param {FeeDataType} [props.feeDataType]
*/
constructor(props = {}) {
/*
* Fee paid to the submitting node
*
* @type {FeeComponents}
*/
this.nodedata = props.nodedata;
/*
* Fee paid to the network for processing a transaction into consensus
*
* @type {FeeComponents}
*/
this.networkdata = props.networkdata;
/*
* Fee paid to the network for providing the service associated with the transaction; for instance, storing a file
*
* @type {FeeComponents}
*/
this.servicedata = props.servicedata;
/*
* SubType distinguishing between different types of FeeData, correlating to the same HederaFunctionality
*
* @type {SubType}
*/
this.feeDataType = props.feeDataType;
}
/**
* @param {Uint8Array} bytes
* @returns {FeeData}
*/
static fromBytes(bytes) {
return FeeData._fromProtobuf(HieroProto.proto.FeeData.decode(bytes));
}
/**
* @internal
* @param {HieroProto.proto.IFeeData} feeData
* @returns {FeeData}
*/
static _fromProtobuf(feeData) {
return new FeeData({
nodedata: feeData.nodedata != null ? _FeeComponents.default._fromProtobuf(feeData.nodedata) : undefined,
networkdata: feeData.networkdata != null ? _FeeComponents.default._fromProtobuf(feeData.networkdata) : undefined,
servicedata: feeData.servicedata != null ? _FeeComponents.default._fromProtobuf(feeData.servicedata) : undefined,
feeDataType: feeData.subType != null ? _FeeDataType.default._fromCode(feeData.subType) : undefined
});
}
/**
* @internal
* @returns {HieroProto.proto.IFeeData}
*/
_toProtobuf() {
return {
nodedata: this.nodedata != null ? this.nodedata._toProtobuf() : undefined,
networkdata: this.networkdata != null ? this.networkdata._toProtobuf() : undefined,
servicedata: this.servicedata != null ? this.servicedata._toProtobuf() : undefined,
subType: this.feeDataType != null ? this.feeDataType.valueOf() : undefined
};
}
/**
* @returns {Uint8Array}
*/
toBytes() {
return HieroProto.proto.FeeData.encode(this._toProtobuf()).finish();
}
}
exports.default = FeeData;
;