diff --git a/packages/wallet-lib/src/EVENTS.js b/packages/wallet-lib/src/EVENTS.js index 1f6448ffc82..7be5a5edd6d 100644 --- a/packages/wallet-lib/src/EVENTS.js +++ b/packages/wallet-lib/src/EVENTS.js @@ -10,7 +10,6 @@ module.exports = { TRANSACTION: 'transaction', BLOCKHEADER: 'blockheader', FETCHED_ADDRESS: 'FETCHED/ADDRESS', - UPDATED_ADDRESS: 'UPDATED/ADDRESS', ERROR_UPDATE_ADDRESS: 'ERROR/UPDATE_ADDRESS', FETCHED_TRANSACTION: 'FETCHED/TRANSACTION', FETCHED_UNCONFIRMED_TRANSACTION: 'FETCHED/UNCONFIRMED_TRANSACTION', diff --git a/packages/wallet-lib/src/types/Account/Account.js b/packages/wallet-lib/src/types/Account/Account.js index 1949da45c31..e9f9d293f83 100644 --- a/packages/wallet-lib/src/types/Account/Account.js +++ b/packages/wallet-lib/src/types/Account/Account.js @@ -93,7 +93,6 @@ class Account extends EventEmitter { this.storage = wallet.storage; // Forward all storage event - this.storage.on(EVENTS.UPDATED_ADDRESS, (ev) => this.emit(ev.type, ev)); this.storage.on(EVENTS.CONFIGURED, (ev) => this.emit(ev.type, ev)); this.storage.on(EVENTS.REHYDRATE_STATE_FAILED, (ev) => this.emit(ev.type, ev)); this.storage.on(EVENTS.REHYDRATE_STATE_SUCCESS, (ev) => this.emit(ev.type, ev)); @@ -115,15 +114,6 @@ class Account extends EventEmitter { switch (this.walletType) { case WALLET_TYPES.HDWALLET: this.accountPath = getBIP44Path(this.network, this.index); - // this.storage - // .getWalletStore(this.walletId) - // .createPathState(this.BIP44PATH); - // this.storage.createAccount( - // this.walletId, - // this.BIP44PATH, - // this.network, - // this.label, - // ); break; case WALLET_TYPES.HDPUBLIC: case WALLET_TYPES.PRIVATEKEY: @@ -131,14 +121,6 @@ class Account extends EventEmitter { case WALLET_TYPES.ADDRESS: case WALLET_TYPES.SINGLE_ADDRESS: this.accountPath = 'm/0'; - // this.storage - // .getWalletStore(this.walletId) - // .createPathState(this); - // this.storage.createSingleAddress( - // this.walletId, - // this.network, - // this.label, - // ); break; default: throw new Error(`Invalid wallet type ${this.walletType}`); @@ -196,25 +178,6 @@ class Account extends EventEmitter { watchers: {}, }; - // // Handle import of cache - // if (opts.cache) { - // if (opts.cache.addresses) { - // try { - // this.storage.importAddresses(opts.cache.addresses, this.walletId); - // } catch (e) { - // this.disconnect(); - // throw e; - // } - // } - // if (opts.cache.transactions) { - // try { - // this.storage.importTransactions(opts.cache.transactions); - // } catch (e) { - // this.disconnect(); - // throw e; - // } - // } - // } this.emit(EVENTS.CREATED, { type: EVENTS.CREATED, payload: null }); /** diff --git a/packages/wallet-lib/src/types/Account/_initializeAccount.js b/packages/wallet-lib/src/types/Account/_initializeAccount.js index 9e418da3f32..adee1ea8a00 100644 --- a/packages/wallet-lib/src/types/Account/_initializeAccount.js +++ b/packages/wallet-lib/src/types/Account/_initializeAccount.js @@ -1,22 +1,11 @@ const logger = require('../../logger'); const EVENTS = require('../../EVENTS'); const preparePlugins = require('./_preparePlugins'); -const { UPDATED_ADDRESS } = require('../../EVENTS'); // eslint-disable-next-line no-underscore-dangle async function _initializeAccount(account, userUnsafePlugins) { const self = account; - function markAddressAsUsed(props) { - const { address } = props.payload; - // This works if the TX cames from our main address, but not in all cases... - self.keyChainStore - .getMasterKeyChain() - .markAddressAsUsed(address); - } - - self.on(UPDATED_ADDRESS, markAddressAsUsed); - const accountStore = account.storage .getWalletStore(account.walletId) .getPathState(account.accountPath); diff --git a/packages/wallet-lib/src/types/Account/methods/importTransactions.js b/packages/wallet-lib/src/types/Account/methods/importTransactions.js index 9af3b9681c5..42c5f167884 100644 --- a/packages/wallet-lib/src/types/Account/methods/importTransactions.js +++ b/packages/wallet-lib/src/types/Account/methods/importTransactions.js @@ -15,6 +15,8 @@ module.exports = async function importTransactions(transactionsWithMayBeMetadata keyChainStore, } = this; + let addressesGenerated = 0; + const chainStore = storage.getChainStore(network); const accountStore = storage .getWalletStore(walletId) @@ -36,6 +38,7 @@ module.exports = async function importTransactions(transactionsWithMayBeMetadata keyChains.forEach((keyChain) => { const issuedPaths = keyChain.markAddressAsUsed(address); if (issuedPaths) { + addressesGenerated += issuedPaths.length; issuedPaths.forEach((issuedPath) => { if (keyChain.keyChainId === masterKeyChain.keyChainId) { logger.silly(`Account.importTransactions - newly issued paths ${issuedPath.length}`); @@ -48,5 +51,5 @@ module.exports = async function importTransactions(transactionsWithMayBeMetadata }); }); logger.silly(`Account.importTransactions(len: ${transactionsWithMayBeMetadata.length})`); - return 0; + return addressesGenerated; }; diff --git a/packages/wallet-lib/tests/integration/plugins/Workers/TransactionSyncStreamWorker.spec.js b/packages/wallet-lib/tests/integration/plugins/Workers/TransactionSyncStreamWorker.spec.js index 053cdbd4e07..109d93ba870 100644 --- a/packages/wallet-lib/tests/integration/plugins/Workers/TransactionSyncStreamWorker.spec.js +++ b/packages/wallet-lib/tests/integration/plugins/Workers/TransactionSyncStreamWorker.spec.js @@ -206,13 +206,13 @@ describe('TransactionSyncStreamWorker', function suite() { // the last used address expect(Object.keys(addressesInStorage).length).to.be.equal(40); // It should reconnect after the gap limit is reached - expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(1); + expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(2); // 20 external and 20 internal expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[0].length).to.be.equal(40); expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[1]).to.be.deep.equal({ fromBlockHeight: 40, count: 2}); // 20 more of external, since the last address is used. - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 2}); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 2}); expect(worker.stream).to.be.null; expect(transactionsInStorage.length).to.be.equal(2); @@ -427,13 +427,13 @@ describe('TransactionSyncStreamWorker', function suite() { // the last used address expect(Object.keys(addressesInStorage).length).to.be.equal(40); // It should reconnect after the gap limit is reached - expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(1); + expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(2); // 20 external and 20 internal expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[0].length).to.be.equal(40); expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[1]).to.be.deep.equal({ fromBlockHeight: 40, count: 0}); // 20 more of external, since the last address is used. - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 0}); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 0}); expect(worker.stream).to.be.null; expect(transactionsInStorage.length).to.be.equal(2); @@ -691,13 +691,13 @@ describe('TransactionSyncStreamWorker', function suite() { expect(Object.keys(externalAddressesInStorage).length).to.be.equal(40); expect(Object.keys(internalAddressesInStorage).length).to.be.equal(20); // It should reconnect after the gap limit is reached - expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(1); + expect(account.transport.subscribeToTransactionsWithProofs.callCount).to.be.equal(2); // 20 external and 20 internal expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[1]).to.be.deep.equal({ fromBlockHeight: 40, count: 0}); expect(account.transport.subscribeToTransactionsWithProofs.firstCall.args[0].length).to.be.equal(40); // 20 more of external, since the last address is used, Merkle Block received - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); - // expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 0}); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[0].length).to.be.equal(60); + expect(account.transport.subscribeToTransactionsWithProofs.secondCall.args[1]).to.be.deep.equal({ fromBlockHash: '0000025d24ebe65454bd51a61bab94095a6ad1df996be387e31495f764d8e2d9', count: 0}); expect(worker.stream).to.be.null; expect(transactionsInStorage.length).to.be.equal(2); expect(transactionsInStorage).to.have.deep.members(expectedTransactions);