Remote#fee_tx: Return an Amount of fees for a specified number of units.

This commit is contained in:
Stefan Thomas
2013-07-26 11:59:52 -07:00
parent 6e2170156d
commit f69ad8b172
2 changed files with 21 additions and 5 deletions

View File

@@ -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;

View File

@@ -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;