diff options
Diffstat (limited to 'app')
-rw-r--r-- | app/scripts/lib/eth-store.js | 39 |
1 files changed, 17 insertions, 22 deletions
diff --git a/app/scripts/lib/eth-store.js b/app/scripts/lib/eth-store.js index e2451408c..0ed7ef545 100644 --- a/app/scripts/lib/eth-store.js +++ b/app/scripts/lib/eth-store.js @@ -24,12 +24,12 @@ function EthereumStore(engine) { // public // -EthereumStore.prototype.getState = function(){ +EthereumStore.prototype.getState = function () { const self = this return clone(self._currentState) } -EthereumStore.prototype.addAccount = function(address){ +EthereumStore.prototype.addAccount = function (address) { const self = this self._currentState.accounts[address] = {} self._didUpdate() @@ -37,13 +37,13 @@ EthereumStore.prototype.addAccount = function(address){ self._updateAccount(self.currentBlockNumber, address, noop) } -EthereumStore.prototype.removeAccount = function(address){ +EthereumStore.prototype.removeAccount = function (address) { const self = this delete self._currentState.accounts[address] self._didUpdate() } -EthereumStore.prototype.addTransaction = function(txHash){ +EthereumStore.prototype.addTransaction = function (txHash) { const self = this self._currentState.transactions[txHash] = {} self._didUpdate() @@ -51,7 +51,7 @@ EthereumStore.prototype.addTransaction = function(txHash){ self._updateTransaction(self.currentBlockNumber, txHash, noop) } -EthereumStore.prototype.removeTransaction = function(address){ +EthereumStore.prototype.removeTransaction = function (address) { const self = this delete self._currentState.transactions[address] self._didUpdate() @@ -62,36 +62,36 @@ EthereumStore.prototype.removeTransaction = function(address){ // private // -EthereumStore.prototype._didUpdate = function() { +EthereumStore.prototype._didUpdate = function () { const self = this var state = self.getState() self.emit('update', state) } -EthereumStore.prototype._updateForBlock = function(block) { +EthereumStore.prototype._updateForBlock = function (block) { const self = this var blockNumber = '0x'+block.number.toString('hex') self.currentBlockNumber = blockNumber async.parallel([ self._updateAccounts.bind(self), self._updateTransactions.bind(self, blockNumber), - ], function(err){ + ], function (err) { if (err) return console.error(err) self.emit('block', self.getState()) }) } -EthereumStore.prototype._updateAccounts = function(cb) { +EthereumStore.prototype._updateAccounts = function (cb) { const self = this var accountsState = self._currentState.accounts var addresses = Object.keys(accountsState) async.each(addresses, self._updateAccount.bind(self), cb) } -EthereumStore.prototype._updateAccount = function(address, cb) { +EthereumStore.prototype._updateAccount = function (address, cb) { const self = this var accountsState = self._currentState.accounts - self._query.getAccount(address, function(err, result){ + self._query.getAccount(address, function (err, result) { if (err) return cb(err) result.address = address // only populate if the entry is still present @@ -103,7 +103,7 @@ EthereumStore.prototype._updateAccount = function(address, cb) { }) } -EthereumStore.prototype.getAccount = function(address, cb){ +EthereumStore.prototype.getAccount = function (address, cb) { const block = 'latest' async.parallel({ balance: this._query.getBalance.bind(this, address, block), @@ -112,21 +112,20 @@ EthereumStore.prototype.getAccount = function(address, cb){ }, cb) } -EthereumStore.prototype._updateTransactions = function(block, cb) { +EthereumStore.prototype._updateTransactions = function (block, cb) { const self = this var transactionsState = self._currentState.transactions var txHashes = Object.keys(transactionsState) async.each(txHashes, self._updateTransaction.bind(self, block), cb) } -EthereumStore.prototype._updateTransaction = function(block, txHash, cb) { +EthereumStore.prototype._updateTransaction = function (block, txHash, cb) { const self = this // would use the block here to determine how many confirmations the tx has var transactionsState = self._currentState.transactions - self._query.getTransaction(txHash, function(err, result){ + self._query.getTransaction(txHash, function (err, result) { if (err) return cb(err) - // only populate if the entry is still present - if (transactionsState[txHash]) { + // only populate if the entry is still present if (transactionsState[txHash]) { transactionsState[txHash] = result self._didUpdate() } @@ -134,8 +133,4 @@ EthereumStore.prototype._updateTransaction = function(block, txHash, cb) { }) } -function valuesFor(obj){ - return Object.keys(obj).map(function(key){ return obj[key] }) -} - -function noop(){} +function noop() {} |