Skip to content
This repository has been archived by the owner on Dec 12, 2018. It is now read-only.

Commit

Permalink
Support 'explorer_getTransactions' RPC call
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Mar 24, 2016
1 parent 2eb6057 commit c6a3f44
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
30 changes: 26 additions & 4 deletions lib/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
};
Expand Down
4 changes: 4 additions & 0 deletions lib/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit c6a3f44

Please sign in to comment.