Skip to content
This repository has been archived by the owner on Mar 7, 2023. It is now read-only.

Separate TxList for each context #252

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ API.prototype.getUnspent = function (fromAddresses, confirmations) {
return this.retry(this.request.bind(this, 'POST', 'unspent', data));
};

API.prototype.getHistory = function (addresses, txFilter, offset, n, syncBool) {
API.prototype.getHistory = function (addresses, txFilter, offset, n, syncBool, onlyShow) {
var clientTime = (new Date()).getTime();
offset = offset || 0;
n = n || 0;
Expand All @@ -180,6 +180,10 @@ API.prototype.getHistory = function (addresses, txFilter, offset, n, syncBool) {
no_buttons: true
};

if (onlyShow) {
data.onlyShow = onlyShow.join('|');
}

if (txFilter !== undefined && txFilter !== null) {
data.filter = txFilter;
}
Expand Down
24 changes: 24 additions & 0 deletions src/blockchain-wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ function Wallet (object) {
this._finalBalance = 0;
this._numberTxTotal = 0;
this._txList = new TxList();
this._txListLegacy = new TxList();
this._latestBlock = null;
this._accountInfo = null;
this._external = null;
Expand Down Expand Up @@ -175,6 +176,10 @@ Object.defineProperties(Wallet.prototype, {
configurable: false,
get: function () { return this._txList; }
},
'txListLegacy': {
configurable: false,
get: function () { return this._txListLegacy; }
},
'numberTxTotal': {
configurable: false,
get: function () { return this._numberTxTotal; },
Expand Down Expand Up @@ -399,6 +404,25 @@ Wallet.prototype.fetchTransactions = function () {
.then(this._updateWalletInfo.bind(this));
};

Wallet.prototype.fetchTransactionsForLegacy = function () {
var _updateAllLegacy = function (o) {
var updateAddress = function (e) {
var address = this.activeKey(e.address);
if (address) {
address.balance = e.final_balance;
address.totalReceived = e.total_received;
address.totalSent = e.total_sent;
}
};
o.addresses.forEach(updateAddress.bind(this));
this.txListLegacy.pushTxs(o.txs);
return o.txs.length;
};
return API.getHistory(this.context, 0, this.txListLegacy.fetched,
this.txListLegacy.loadNumber, false, this.activeAddresses)
.then(_updateAllLegacy.bind(this));
};

Wallet.prototype.getBalancesForArchived = function () {
var updateBalance = function (key) {
if (this.containsLegacyAddress(key.address)) {
Expand Down
25 changes: 24 additions & 1 deletion src/hd-account.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var assert = require('assert');
var Helpers = require('./helpers');
var KeyRing = require('./keyring');
var MyWallet = require('./wallet'); // This cyclic import should be avoided once the refactor is complete
var TxList = require('./transaction-list');
var API = require('./api');
var constants = require('./constants');

// HDAccount Class
Expand All @@ -27,6 +29,7 @@ function HDAccount (object) {
this._lastUsedReceiveIndex = null;
this._changeIndex = 0;
this._n_tx = 0;
this._txList = new TxList();
this._balance = null;
this._index = Helpers.isPositiveInteger(obj.index) ? obj.index : null;
}
Expand Down Expand Up @@ -57,6 +60,10 @@ Object.defineProperties(HDAccount.prototype, {
}
}
},
'txList': {
configurable: false,
get: function () { return this._txList; }
},
'n_tx': {
get: function () { return this._n_tx; },
set: function (num) {
Expand Down Expand Up @@ -251,8 +258,24 @@ HDAccount.prototype.persist = function () {
return this;
};

// Address labels:
HDAccount.prototype.fetchTransactions = function () {
var _updateAccount = function (o) {
this.balance = o.addresses[0].final_balance;
this.n_tx = o.addresses[0].n_tx;
this.lastUsedReceiveIndex = o.addresses[0].account_index;
this.receiveIndex = Math.max(this.lastUsedReceiveIndex, this.maxLabeledReceiveIndex);
this.changeIndex = o.addresses[0].change_index;
if (this.getLabelForReceivingAddress(this.receiveIndex)) {
this.incrementReceiveIndex();
}
this.txList.pushTxs(o.txs);
return o.txs.length;
};
return API.getHistory(MyWallet.wallet.context, 0, this.txList.fetched, this.txList.loadNumber, false, [this._xpub])
.then(_updateAccount.bind(this));
};

// Address labels:
HDAccount.prototype._orderedAddressLabels = function () {
return this._address_labels.sort((a, b) => a.index - b.index);
};
Expand Down