Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: getBlockTransactionCount doesn't work on testRPC #27

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
FROM node:6

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY . /usr/src/app
RUN rm /usr/src/app/.git
RUN npm install && \
node_modules/.bin/bower install --allow-root
RUN chmod +x selectRpcAndRun.sh
CMD ["./selectRpcAndRun.sh"]
1 change: 1 addition & 0 deletions app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ angular.module('ethExplorer', ['ngRoute','ui.bootstrap'])
var eth_node_url = 'http://localhost:8545'; // TODO: remote URL
web3.setProvider(new web3.providers.HttpProvider(eth_node_url));
$rootScope.web3 = web3;
$rootScope.abiDecoder = abiDecoder;
function sleepFor( sleepDuration ){
var now = new Date().getTime();
while(new Date().getTime() < now + sleepDuration){ /* do nothing */ }
Expand Down
5 changes: 3 additions & 2 deletions app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<title>Ethereum Block Explorer</title>
<meta name="description" content="">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="styles/main.css">
<link rel="stylesheet" href="./styles/main.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script src="bower_components/web3/dist/web3.min.js"></script>

Expand All @@ -19,7 +19,7 @@
<nav class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<span class="icon-bar"></span><a href="/#/" class="navbar-brand">Ether Block Explorer</a>
<span class="icon-bar"></span><a href="./#/" class="navbar-brand">Ether Block Explorer</a>
</div>
<div id="navbar" class="navbar-collapse collapse">
<ul class="nav navbar-nav">
Expand All @@ -42,6 +42,7 @@
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
<script src="bower_components/angular-bootstrap/ui-bootstrap.min.js"></script>
<script src="bower_components/angular-route/angular-route.js"></script>
<script src="bower_components/abi-decoder/dist/abi-decoder.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<!--Core-->
Expand Down
66 changes: 63 additions & 3 deletions app/scripts/controllers/addressInfoController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ angular.module('ethExplorer')
.controller('addressInfoCtrl', function ($rootScope, $scope, $location, $routeParams, $q) {

var web3 = $rootScope.web3;

var abiDecoder = $rootScope.abiDecoder;

$scope.init=function(){

$scope.addressId=$routeParams.addressId;
Expand All @@ -28,12 +29,71 @@ angular.module('ethExplorer')
deferred.reject(error);
}
});
getTransactionsByAccount($scope.addressId);
return deferred.promise;
}
} // getAddressInfos()

function getTransactionsByAccount(myaccount, startBlockNumber, endBlockNumber) {
if (endBlockNumber == null) {
endBlockNumber = web3.eth.blockNumber;
// console.log("Using endBlockNumber: " + endBlockNumber);
}
if (startBlockNumber == null) {
startBlockNumber = ( endBlockNumber - 1000 < 0) ? 0: endBlockNumber - 1000;
// console.log("Using startBlockNumber: " + startBlockNumber);
}
console.log("Searching for transactions to/from account \"" + myaccount + "\" within blocks " + startBlockNumber + " and " + endBlockNumber);

for (var i = startBlockNumber; i <= endBlockNumber; i++) {
if (i % 1000 == 0) {
//console.log("Searching block " + i);
}
var block = web3.eth.getBlock(i, true);
if (block != null && block.transactions != null) {
$scope.transactions = [];
block.transactions.forEach( function(result) {
if (myaccount == "*" || myaccount == result.from || myaccount == result.to) {
/* console.log(" tx hash : " + result.hash + "\n"
+ " nonce : " + result.nonce + "\n"
+ " blockHash : " + result.blockHash + "\n"
+ " blockNumber : " + result.blockNumber + "\n"
+ " transactionIndex: " + result.transactionIndex + "\n"
+ " from : " + result.from + "\n"
+ " to : " + result.to + "\n"
+ " value : " + result.value + "\n"
+ " time : " + block.timestamp + " " + new Date(block.timestamp * 1000).toGMTString() + "\n"
+ " gasPrice : " + result.gasPrice + "\n"
+ " gas : " + result.gas + "\n"
+ " input : " + result.input); */

var transaction = {
id: result.hash,
hash: result.hash,
from: result.from,
to: result.to,
gas: result.gas,
input: result.input,
decoded: decodeData(result.input),
value: result.value
}

web3.eth.getTransactionReceipt(result.hash, function (err2, receipt) {
if(!err2) {
for (var attrname in receipt) { transaction[attrname] = receipt[attrname]; }
}

$scope.$apply(
$scope.transactions.push(transaction)
);
}); // getTransactionReceipt();
} // if tx is for myaccount to or from
}) // for each tx in block
} // if there is tx in block
} // for each block
} // getTransactionsByAccount()

};

$scope.init();

});
47 changes: 31 additions & 16 deletions app/scripts/controllers/blockInfosController.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ angular.module('ethExplorer')
$scope.number = result.number;
$scope.parentHash = result.parentHash;
$scope.blockNumber = result.number;
$scope.timestamp = result.timestamp;
$scope.timestamp = result.timestamp + '000';
$scope.extraData = result.extraData;
$scope.dataFromHex = hex2a(result.extraData);
$scope.size = result.size;
$scope.txCount = result.transactions.length;
if($scope.blockNumber!==undefined){
$scope.conf = number - $scope.blockNumber + " Confirmations";
if($scope.conf===0 + " Confirmations"){
Expand All @@ -55,9 +56,7 @@ angular.module('ethExplorer')
$scope.time = newDate.toUTCString();
}
}



getTransactions(result);
});

} else {
Expand All @@ -70,6 +69,7 @@ angular.module('ethExplorer')

web3.eth.getBlock($scope.blockId,function(error, result) {
if(!error) {
//console.debug("getBlockInfos: ", result);
deferred.resolve(result);
} else {
deferred.reject(error);
Expand All @@ -79,33 +79,48 @@ angular.module('ethExplorer')

}


};
$scope.init();

// parse transactions
$scope.transactions = []
web3.eth.getBlockTransactionCount($scope.blockId, function(error, result){
var txCount = result
function getTransactions(result) {
// TODO: move this to a common js (similar function is in addressInfoController.js)
// parse transactions
// getBlockTransactionCount doesn't work on testRPC
// web3.eth.getBlockTransactionCount($scope.blockId, function(error, result){
//var txCount = result

txCount = result.transactions.length;
$scope.transactions = []

for (var blockIdx = 0; blockIdx < txCount; blockIdx++) {
web3.eth.getTransactionFromBlock($scope.blockId, blockIdx, function(error, result) {

// console.debug("getTransactionFromBlock: ", result);
var transaction = {
id: result.hash,
hash: result.hash,
from: result.from,
to: result.to,
gas: result.gas,
input: result.input,
decoded: decodeData(result.input),
value: result.value
}
$scope.$apply(
$scope.transactions.push(transaction)
)
})
}
})

web3.eth.getTransactionReceipt(result.hash, function (err2, receipt) {
if(!err2) {
for (var attrname in receipt) { transaction[attrname] = receipt[attrname]; }
}
//console.log(transaction);

$scope.$apply(
$scope.transactions.push(transaction)
);
}); // getTransactionReceipt()
}); // getTransactionFromBlock ()
} // for each tx in block

} // getTransactions() for block
//}) //getBlockTransactionCount


function hex2a(hexx) {
Expand Down
97 changes: 66 additions & 31 deletions app/scripts/controllers/mainController.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading