mirror of
https://github.com/Xahau/xahau.js.git
synced 2025-11-23 13:45:48 +00:00
Remote#fee_tx: Return an Amount of fees for a specified number of units.
This commit is contained in:
@@ -1437,15 +1437,29 @@ Remote.prototype.transaction = function () {
|
||||
return new Transaction(this);
|
||||
};
|
||||
|
||||
/**
|
||||
* Calculate a transaction fee for a number of tx fee units.
|
||||
*
|
||||
* This takes into account the last known network and local load fees.
|
||||
*
|
||||
* @return {Amount} Final fee in XRP for specified number of fee units.
|
||||
*/
|
||||
Remote.prototype.fee_tx = function (units)
|
||||
{
|
||||
var fee_unit = this.fee_tx_unit();
|
||||
|
||||
return Amount.from_json(""+Math.ceil(units * fee_unit));
|
||||
};
|
||||
|
||||
/**
|
||||
* Get the current recommended transaction fee unit.
|
||||
*
|
||||
* Multiply this value with the number of fee units in order to calculate the
|
||||
* recommended fee for the transaction you are trying to submit.
|
||||
*
|
||||
* @return {Number} Recommended amount for one fee unit.
|
||||
* @return {Number} Recommended amount for one fee unit as float.
|
||||
*/
|
||||
Remote.prototype.fee_tx = function ()
|
||||
Remote.prototype.fee_tx_unit = function ()
|
||||
{
|
||||
var fee_unit = this._fee_base / this._fee_ref;
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ var Transaction = function (remote) {
|
||||
util.inherits(Transaction, EventEmitter);
|
||||
|
||||
// XXX This needs to be determined from the network.
|
||||
Transaction.fees = {
|
||||
Transaction.fee_units = {
|
||||
'default' : 10,
|
||||
};
|
||||
|
||||
@@ -196,7 +196,7 @@ Transaction.prototype.complete = function () {
|
||||
var tx_json = this.tx_json;
|
||||
|
||||
if ("undefined" === typeof tx_json.Fee && this.remote.local_fee) {
|
||||
this.tx_json.Fee = "" + Math.ceil(this.remote.fee_tx() * this.fee_units());
|
||||
this.tx_json.Fee = this.remote.fee_tx(this.fee_units()).to_json();
|
||||
}
|
||||
|
||||
if ("undefined" === typeof tx_json.SigningPubKey && (!this.remote || this.remote.local_signing)) {
|
||||
@@ -714,10 +714,12 @@ Transaction.prototype.wallet_add = function (src, amount, authorized_key, public
|
||||
* current load on both the network and the server.
|
||||
*
|
||||
* @see https://ripple.com/wiki/Transaction_Fee
|
||||
*
|
||||
* @return {Number} Number of fee units for this transaction.
|
||||
*/
|
||||
Transaction.prototype.fee_units = function ()
|
||||
{
|
||||
return Transaction.fees["default"];
|
||||
return Transaction.fee_units["default"];
|
||||
};
|
||||
|
||||
exports.Transaction = Transaction;
|
||||
|
||||
Reference in New Issue
Block a user