Browse Source

detect low fee txs in tx history

feat/estimateFee-limit
Ivan Socolsky 8 years ago
parent
commit
1d4cf86a56
No known key found for this signature in database GPG Key ID: FAECE6A05FAA4F56
  1. 29
      lib/server.js
  2. 15
      test/integration/server.js

29
lib/server.js

@ -2590,6 +2590,7 @@ WalletService.prototype._normalizeTxHistory = function(txs) {
confirmations: tx.confirmations,
blockheight: tx.blockheight,
fees: parseInt((tx.fees * 1e8).toFixed(0)),
size: tx.size,
time: t,
inputs: inputs,
outputs: outputs,
@ -2736,6 +2737,10 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
confirmations: tx.confirmations,
};
if (_.isNumber(tx.size) && tx.size > 0) {
newTx.feePerKb = +(tx.fees * 1000 / tx.size).toFixed();
}
if (opts.includeExtendedInfo) {
newTx.inputs = _.map(inputs, function(input) {
return _.pick(input, 'address', 'amount', 'isMine');
@ -2907,10 +2912,28 @@ WalletService.prototype.getTxHistory = function(opts, cb) {
var finalTxs = decorate(wallet, res.txs.items, addresses, res.txps, res.notes);
if (res.txs.fromCache)
log.debug("History from cache for:", self.walletId, from, to);
self.getFeeLevels({
network: wallet.network
}, function(err, levels) {
if (err) {
log.warn('Could not fetch fee levels', err);
} else {
var level = _.find(levels, {
level: 'superEconomy'
});
if (level) {
var minFeePerKb = level.feePerKb;
_.each(finalTxs, function(tx) {
tx.lowFees = tx.feePerKb < minFeePerKb;
});
}
}
return cb(null, finalTxs, !!res.txs.fromCache);
if (res.txs.fromCache)
log.debug("History from cache for:", self.walletId, from, to);
return cb(null, finalTxs, !!res.txs.fromCache);
});
});
});
});

15
test/integration/server.js

@ -4139,6 +4139,9 @@ describe('Wallet service', function() {
}],
}];
helpers.stubHistory(txs);
helpers.stubFeeLevels({
24: 10000,
});
server.editTxNote({
txid: '123',
body: 'just some note'
@ -4341,6 +4344,9 @@ describe('Wallet service', function() {
}],
}];
helpers.stubHistory(txs);
helpers.stubFeeLevels({
24: 10000,
});
server.getTxHistory({}, function(err, txs) {
should.not.exist(err);
should.exist(txs);
@ -5984,6 +5990,9 @@ describe('Wallet service', function() {
helpers.createAddresses(server, wallet, 1, 1, function(main, change) {
mainAddresses = main;
changeAddresses = change;
helpers.stubFeeLevels({
24: 10000,
});
done();
});
});
@ -6003,7 +6012,6 @@ describe('Wallet service', function() {
done();
});
});
it('should get tx history for incoming txs', function(done) {
server._normalizeTxHistory = sinon.stub().returnsArg(0);
var txs = [{
@ -6019,6 +6027,7 @@ describe('Wallet service', function() {
address: mainAddresses[0].address,
amount: 200,
}],
size: 500,
}];
helpers.stubHistory(txs);
server.getTxHistory({}, function(err, txs) {
@ -6030,6 +6039,7 @@ describe('Wallet service', function() {
tx.amount.should.equal(200);
tx.fees.should.equal(100);
tx.time.should.equal(20);
tx.lowFees.should.be.true;
done();
});
});
@ -6310,6 +6320,9 @@ describe('Wallet service', function() {
helpers.createAddresses(server, wallet, 1, 1, function(main, change) {
mainAddresses = main;
changeAddresses = change;
helpers.stubFeeLevels({
24: 10000,
});
done();
});
});

Loading…
Cancel
Save