txdb: fee.
This commit is contained in:
parent
9049053a1e
commit
3aee9861a3
@ -2801,15 +2801,17 @@ function Details(txdb, tx) {
|
|||||||
this.network = this.db.network;
|
this.network = this.db.network;
|
||||||
this.wid = txdb.wallet.wid;
|
this.wid = txdb.wallet.wid;
|
||||||
this.id = txdb.wallet.id;
|
this.id = txdb.wallet.id;
|
||||||
|
|
||||||
this.hash = tx.hash('hex');
|
this.hash = tx.hash('hex');
|
||||||
this.height = tx.height;
|
this.tx = tx;
|
||||||
|
|
||||||
this.block = tx.block;
|
this.block = tx.block;
|
||||||
|
this.height = tx.height;
|
||||||
|
this.ts = tx.ts;
|
||||||
this.index = tx.index;
|
this.index = tx.index;
|
||||||
this.confirmations = tx.getConfirmations(this.db.height);
|
this.confirmations = tx.getConfirmations(this.db.height);
|
||||||
this.fee = tx.getFee();
|
|
||||||
this.ts = tx.ts;
|
|
||||||
this.ps = tx.ps;
|
this.ps = tx.ps;
|
||||||
this.tx = tx;
|
|
||||||
|
|
||||||
this.inputs = [];
|
this.inputs = [];
|
||||||
this.outputs = [];
|
this.outputs = [];
|
||||||
@ -2878,6 +2880,34 @@ Details.prototype.setOutput = function setOutput(i, path) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate fee. Only works if wallet
|
||||||
|
* owns all inputs. Returns 0 otherwise.
|
||||||
|
* @returns {Amount}
|
||||||
|
*/
|
||||||
|
|
||||||
|
Details.prototype.getFee = function getFee() {
|
||||||
|
var inputValue = 0;
|
||||||
|
var outputValue = 0;
|
||||||
|
var i, input, output;
|
||||||
|
|
||||||
|
for (i = 0; i < this.inputs.length; i++) {
|
||||||
|
input = this.inputs[i];
|
||||||
|
|
||||||
|
if (!input.path)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
inputValue += input.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < this.outputs.length; i++) {
|
||||||
|
output = this.outputs[i];
|
||||||
|
outputValue += output.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
return inputValue - outputValue;
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert details to a more json-friendly object.
|
* Convert details to a more json-friendly object.
|
||||||
* @returns {Object}
|
* @returns {Object}
|
||||||
@ -2894,7 +2924,7 @@ Details.prototype.toJSON = function toJSON() {
|
|||||||
ts: this.ts,
|
ts: this.ts,
|
||||||
ps: this.ps,
|
ps: this.ps,
|
||||||
index: this.index,
|
index: this.index,
|
||||||
fee: utils.btc(this.fee),
|
fee: utils.btc(this.getFee()),
|
||||||
confirmations: this.confirmations,
|
confirmations: this.confirmations,
|
||||||
inputs: this.inputs.map(function(input) {
|
inputs: this.inputs.map(function(input) {
|
||||||
return input.toJSON(self.network);
|
return input.toJSON(self.network);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user