diff --git a/lib/blockchain.js b/lib/blockchain.js index 86a3e1718..edd23b62a 100644 --- a/lib/blockchain.js +++ b/lib/blockchain.js @@ -264,10 +264,7 @@ Blockchain.prototype.getTransactionReceipt = function(hash) { } } -Blockchain.prototype.getTransactionByHash = function(hash) { - var result = this.transactions[hash]; - - if (result !== undefined) { +Blockchain.prototype.formatTransaction = function(hash, result) { var tx = result.tx; return { @@ -283,12 +280,37 @@ Blockchain.prototype.getTransactionByHash = function(hash) { gasPrice: this.toHex(tx.gasPrice), input: this.toHex(tx.data), }; +} + +Blockchain.prototype.getTransactionByHash = function(hash) { + var result = this.transactions[hash]; + + if (result !== undefined) { + return this.formatTransaction(hash, result) } else { return null; } } +Blockchain.prototype.getTransactions = function(address) { + var results = []; + + var self = this; + Object.keys(this.transactions).forEach(function (hash) { + var tx = self.transactions[hash].tx; + if ((self.toHex(tx.getSenderAddress()) === address) || + (self.toHex(tx.to) === address)) { + var result = self.formatTransaction(hash, self.transactions[hash]); + result.gasUsed = self.transactions[hash].gasUsed; + result.timestamp = parseInt(self.transactions[hash].block.header.timestamp.toString('hex'), 16); + results.push(result); + } + }); + + return results; +} + Blockchain.prototype.queueTransaction = function(tx_params, callback) { this.queueAction("eth_sendTransaction", tx_params, callback); }; diff --git a/lib/manager.js b/lib/manager.js index 9d4c0a8e8..494a14698 100644 --- a/lib/manager.js +++ b/lib/manager.js @@ -193,4 +193,8 @@ Manager.prototype.evm_revert = function(snapshot_id, callback) { callback(null, this.blockchain.revert(snapshot_id)); }; +Manager.prototype.explorer_getTransactions = function(address, callback) { + callback(null, this.blockchain.getTransactions(address)); +}; + module.exports = Manager;