diff options
author | Dan Finlay <dan@danfinlay.com> | 2017-09-23 04:59:25 +0800 |
---|---|---|
committer | Dan Finlay <dan@danfinlay.com> | 2017-09-23 04:59:25 +0800 |
commit | 11c8c07bfc6677e347873f02ae8c401f8d6c4dcf (patch) | |
tree | f94da3caa86d7fd7de6275d25cb9c161175208e3 /app | |
parent | 977405fc7d89256a911e73b83a6678235fa1cfb8 (diff) | |
download | tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.gz tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.bz2 tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.lz tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.xz tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.tar.zst tangerine-wallet-browser-11c8c07bfc6677e347873f02ae8c401f8d6c4dcf.zip |
Refactor eth-store into account-tracker
EthStore was only being used for tracking account balances and nonces now, so I removed its block-tracking duties, renamed it account-tracker, and removed it as a dependency from `KeyringController`, so that KRC can go live on without a hard dep on it.
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/controllers/computed-balances.js (renamed from app/scripts/controllers/balances.js) | 4 | ||||
-rw-r--r-- | app/scripts/controllers/transactions.js | 6 | ||||
-rw-r--r-- | app/scripts/lib/account-tracker.js (renamed from app/scripts/lib/eth-store.js) | 2 | ||||
-rw-r--r-- | app/scripts/metamask-controller.js | 26 |
4 files changed, 22 insertions, 16 deletions
diff --git a/app/scripts/controllers/balances.js b/app/scripts/controllers/computed-balances.js index 89c2ca95d..a85eb5590 100644 --- a/app/scripts/controllers/balances.js +++ b/app/scripts/controllers/computed-balances.js @@ -2,7 +2,7 @@ const ObservableStore = require('obs-store') const extend = require('xtend') const BalanceController = require('./balance') -class BalancesController { +class ComputedbalancesController { constructor (opts = {}) { const { ethStore, txController } = opts @@ -61,4 +61,4 @@ class BalancesController { } } -module.exports = BalancesController +module.exports = ComputedbalancesController diff --git a/app/scripts/controllers/transactions.js b/app/scripts/controllers/transactions.js index 59a3f5329..2aff4e5ff 100644 --- a/app/scripts/controllers/transactions.js +++ b/app/scripts/controllers/transactions.js @@ -22,7 +22,7 @@ module.exports = class TransactionController extends EventEmitter { this.provider = opts.provider this.blockTracker = opts.blockTracker this.signEthTx = opts.signTransaction - this.ethStore = opts.ethStore + this.accountTracker = opts.accountTracker this.nonceTracker = new NonceTracker({ provider: this.provider, @@ -52,7 +52,7 @@ module.exports = class TransactionController extends EventEmitter { provider: this.provider, nonceTracker: this.nonceTracker, getBalance: (address) => { - const account = this.ethStore.getState().accounts[address] + const account = this.accountTracker.getState().accounts[address] if (!account) return return account.balance }, @@ -73,7 +73,7 @@ module.exports = class TransactionController extends EventEmitter { this.blockTracker.on('rawBlock', this.pendingTxTracker.checkForTxInBlock.bind(this.pendingTxTracker)) // this is a little messy but until ethstore has been either // removed or redone this is to guard against the race condition - // where ethStore hasent been populated by the results yet + // where accountTracker hasent been populated by the results yet this.blockTracker.once('latest', () => { this.blockTracker.on('latest', this.pendingTxTracker.resubmitPendingTxs.bind(this.pendingTxTracker)) }) diff --git a/app/scripts/lib/eth-store.js b/app/scripts/lib/account-tracker.js index ff22eca4a..bf949597b 100644 --- a/app/scripts/lib/eth-store.js +++ b/app/scripts/lib/account-tracker.js @@ -1,4 +1,4 @@ -/* Ethereum Store +/* Account Tracker * * This module is responsible for tracking any number of accounts * and caching their current balances & transaction counts. diff --git a/app/scripts/metamask-controller.js b/app/scripts/metamask-controller.js index 02c06ead2..b1cfe1a2d 100644 --- a/app/scripts/metamask-controller.js +++ b/app/scripts/metamask-controller.js @@ -4,7 +4,7 @@ const promiseToCallback = require('promise-to-callback') const pipe = require('pump') const Dnode = require('dnode') const ObservableStore = require('obs-store') -const EthStore = require('./lib/eth-store') +const AccountTracker = require('./lib/account-tracker') const EthQuery = require('eth-query') const streamIntoProvider = require('web3-stream-provider/handler') const setupMultiplex = require('./lib/stream-utils.js').setupMultiplex @@ -81,19 +81,25 @@ module.exports = class MetamaskController extends EventEmitter { // eth data query tools this.ethQuery = new EthQuery(this.provider) - this.ethStore = new EthStore({ - provider: this.provider, - blockTracker: this.provider, - }) // key mgmt this.keyringController = new KeyringController({ initState: initState.KeyringController, - ethStore: this.ethStore, + accountTracker: this.accountTracker, getNetwork: this.networkController.getNetworkState.bind(this.networkController), }) + + // account tracker watches balances, nonces, and any code at their address. + this.accountTracker = new AccountTracker({ + provider: this.provider, + blockTracker: this.provider, + }) this.keyringController.on('newAccount', (address) => { this.preferencesController.setSelectedAddress(address) + this.accountTracker.addAccount(address) + }) + this.keyringController.on('removedAccount', (address) => { + this.accountTracker.removeAccount(address) }) // address book controller @@ -112,13 +118,13 @@ module.exports = class MetamaskController extends EventEmitter { provider: this.provider, blockTracker: this.provider, ethQuery: this.ethQuery, - ethStore: this.ethStore, + accountTracker: this.accountTracker, }) this.txController.on('newUnaprovedTx', opts.showUnapprovedTx.bind(opts)) // computed balances (accounting for pending transactions) this.balancesController = new BalancesController({ - ethStore: this.ethStore, + accountTracker: this.accountTracker, txController: this.txController, }) this.networkController.on('networkDidChange', () => { @@ -177,7 +183,7 @@ module.exports = class MetamaskController extends EventEmitter { // manual mem state subscriptions this.networkController.store.subscribe(this.sendUpdate.bind(this)) - this.ethStore.subscribe(this.sendUpdate.bind(this)) + this.accountTracker.subscribe(this.sendUpdate.bind(this)) this.txController.memStore.subscribe(this.sendUpdate.bind(this)) this.balancesController.store.subscribe(this.sendUpdate.bind(this)) this.messageManager.memStore.subscribe(this.sendUpdate.bind(this)) @@ -260,7 +266,7 @@ module.exports = class MetamaskController extends EventEmitter { isInitialized, }, this.networkController.store.getState(), - this.ethStore.getState(), + this.accountTracker.getState(), this.txController.memStore.getState(), this.messageManager.memStore.getState(), this.personalMessageManager.memStore.getState(), |