Skip to content

Commit

Permalink
Merge pull request #165 from hackmod/rich-list
Browse files Browse the repository at this point in the history
support Rich List
  • Loading branch information
YazzyYaz authored Nov 19, 2018
2 parents ea6e1ca + de3ee7b commit 3513fbf
Show file tree
Hide file tree
Showing 11 changed files with 1,098 additions and 1 deletion.
14 changes: 14 additions & 0 deletions db.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ var Block = new Schema(
"uncles": [String]
});

var Account = new Schema(
{
"address": {type: String, index: {unique: true}},
"balance": Number,
"blockNumber": Number,
"type": {type: Number, default: 0} // address: 0x0, contract: 0x1
});

var Contract = new Schema(
{
"address": {type: String, index: {unique: true}},
Expand Down Expand Up @@ -70,16 +78,22 @@ var BlockStat = new Schema(
Transaction.index({blockNumber:-1});
Transaction.index({from:1, blockNumber:-1});
Transaction.index({to:1, blockNumber:-1});
Account.index({balance:-1});
Account.index({balance:-1, blockNumber:-1});
Account.index({type:-1, balance:-1});
Block.index({miner:1});
Block.index({miner:1, blockNumber:-1});

mongoose.model('BlockStat', BlockStat);
mongoose.model('Block', Block);
mongoose.model('Account', Account);
mongoose.model('Contract', Contract);
mongoose.model('Transaction', Transaction);
module.exports.BlockStat = mongoose.model('BlockStat');
module.exports.Block = mongoose.model('Block');
module.exports.Contract = mongoose.model('Contract');
module.exports.Transaction = mongoose.model('Transaction');
module.exports.Account = mongoose.model('Account');

mongoose.Promise = global.Promise;
mongoose.connect(process.env.MONGO_URI || 'mongodb://localhost/blockDB', {
Expand Down
101 changes: 101 additions & 0 deletions lib/trace.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
/**
* @author Alexis Roussel <[email protected]>
* @author Peter Pratscher <[email protected]>
* @date 2017
* @license LGPL
* @changelog 2018/05/19 - modified for web3.js 0.20.x using _extend() method. (by hackyminer <[email protected]>)
*/
module.exports = function(web3) {
/**
* @file trace.js
* @author Alexis Roussel <[email protected]>
* @date 2017
* @license LGPL
*/
web3._extend({
property: 'trace',
methods: [
new web3._extend.Method({
name: 'call',
call: 'trace_call',
params: 3,
inputFormatter: [web3._extend.formatters.inputCallFormatter, null, web3._extend.formatters.inputDefaultBlockNumberFormatter]
}),

new web3._extend.Method({
name: 'rawTransaction',
call: 'trace_rawTransaction',
params: 2
}),

new web3._extend.Method({
name: 'replayTransaction',
call: 'trace_replayTransaction',
params: 2
}),

new web3._extend.Method({
name: 'block',
call: 'trace_block',
params: 1,
inputFormatter: [web3._extend.formatters.inputDefaultBlockNumberFormatter]
}),

new web3._extend.Method({
name: 'filter',
call: 'trace_filter',
params: 1
}),

new web3._extend.Method({
name: 'get',
call: 'trace_get',
params: 2
}),

new web3._extend.Method({
name: 'transaction',
call: 'trace_transaction',
params: 1
})
]
});

/**
* @file parity.js
* @author Peter Pratscher <[email protected]>
* @date 2017
* @license LGPL
*/
web3._extend({
property: 'parity',
methods: [
new web3._extend.Method({
name: 'pendingTransactions',
call: 'parity_pendingTransactions',
params: 0,
outputFormatter: web3._extend.formatters.outputTransactionFormatter
}),

new web3._extend.Method({
name: 'pendingTransactionsStats',
call: 'parity_pendingTransactionsStats',
params: 0
}),

new web3._extend.Method({
name: 'listAccounts',
call: 'parity_listAccounts',
params: 3,
inputFormatter: [null, null, web3._extend.formatters.inputDefaultBlockNumberFormatter]
}),

new web3._extend.Method({
name: 'phraseToAddress',
call: 'parity_phraseToAddress',
params: 1
})
]
});
return web3;
};
95 changes: 95 additions & 0 deletions public/js/controllers/AccountsController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
angular.module('BlocksApp').controller('AccountsController', function($stateParams, $rootScope, $scope, $http, $filter) {
$scope.settings = $rootScope.setup;

// fetch accounts
var getAccounts = function() {
$("#table_accounts").DataTable({
processing: true,
serverSide: true,
paging: true,
ajax: function(data, callback, settings) {
// get totalSupply only once.
data.totalSupply = $scope.totalSupply || -1;
data.recordsTotal = $scope.totalAccounts || 0;
$http.post('/richlist', data).then(function(resp) {
// set the totalSupply
if (resp.data.totalSupply) {
$scope.totalSupply = resp.data.totalSupply;
}
// set the number of total accounts
$scope.totalAccounts = resp.data.recordsTotal;

// fixup data to show percentages
var newdata = resp.data.data.map(function(item) {
var num = item[0];
var addr = item[1];
var type = item[2];
var balance = item[3];
var lastmod = item[4];
return [num, addr, type, balance, (balance / $scope.totalSupply) * 100, lastmod];
});
resp.data.data = newdata;
callback(resp.data);
});
},
lengthMenu: [
[20, 50, 100, 150, 200, 500],
[20, 50, 100, 150, 200, 500] // change per page values here
],
pageLength: 20,
order: [
[3, "desc"]
],
language: {
lengthMenu: "_MENU_ accounts",
zeroRecords: "No accounts found",
infoEmpty: "",
infoFiltered: "(filtered from _MAX_ total accounts)"
},
columnDefs: [
{ orderable: false, "targets": [0,1,4] },
{
render:
function(data, type, row) {
return '<a href="/addr/' + data +'">' + data + '</a>'
},
targets: [1]
},
{
render:
function(data, type, row) {
if (data & 0x1) {
return "Contract";
}
if (data & 0x4) { // user defined account type
var accountType = data >> 3;
accountType = accountType.toString();
if ($scope.settings.accountTypes && $scope.settings.accountTypes[accountType]) {
return $scope.settings.accountTypes[accountType];
}
return "Genesis Alloc";
}
return "Account";
},
targets: [2]
},
{
render:
function(data, type, row) {
return $filter('number')(data, 8);
},
targets: [3]
},
{
render:
function(data, type, row) {
return $filter('number')(data, 4) + ' %';
},
targets: [4]
}
]
});
};

getAccounts();
});
21 changes: 21 additions & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,27 @@ BlocksApp.config(['$stateProvider', '$urlRouterProvider', function($stateProvide
}]
}
})
.state('accounts', {
url: "/accounts",
templateUrl: "views/accounts.html",
data: {pageTitle: 'Accounts'},
controller: "AccountsController",
resolve: {
deps: ['$ocLazyLoad', function($ocLazyLoad) {
return $ocLazyLoad.load({
name: 'BlocksApp',
insertBefore: '#ng_load_plugins_before', // load the above css files before '#ng_load_plugins_before'
files: [
'/js/controllers/AccountsController.js',
'/plugins/datatables/datatables.min.css',
'/plugins/datatables/datatables.bootstrap.css',
'/plugins/datatables/datatables.all.min.js',
'/plugins/datatables/datatable.min.js'
]
});
}]
}
})
.state('block', {
url: "/block/{number}",
templateUrl: "views/block.html",
Expand Down
3 changes: 3 additions & 0 deletions public/tpl/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@
<li class="active">
<a href="/">Home</a>
</li>
<li ng-show="settings.showRichList">
<a href="/accounts">Accounts</a>
</li>
<li class="menu-dropdown mega-menu-dropdown ">
<a data-hover="megamenu-dropdown" data-close-others="true" data-toggle="dropdown" href="/token" class="dropdown-toggle"> Tokens
<i class="fa fa-angle-down"></i>
Expand Down
37 changes: 37 additions & 0 deletions public/views/accounts.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="row">
<div class="col-md-12 portlet light">
<div class="portlet-title">
<div class="caption">Overview</div>
</div>
<div class="portlet-body">
<div class="row">
<div class="col-md-6 center">
<div>
<span class="eth-stat-title">Total supply: {{ totalSupply | number: 2 }} {{ settings.symbol }} </span>
<div class="margin-top-20">
Total {{ totalAccounts | number }} <span class="eth-stat-text"> accounts</span>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 portlet light">
<div class="portlet-body">
<table id="table_accounts" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>#</th>
<th>Address</th>
<th>Type</th>
<th>Balance</th>
<th>Percent</th>
</tr>
</thead>
<tbody></tbody>
</table>
</div>
</div>
</div>
2 changes: 2 additions & 0 deletions routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ module.exports = function(app){
var compile = require('./compiler');
var fiat = require('./fiat');
var stats = require('./stats');
var richList = require('./richlist');

/*
Local DB: data request format
{ "address": "0x1234blah", "txin": true }
{ "tx": "0x1234blah" }
{ "block": "1234" }
*/
app.post('/richlist', richList);
app.post('/addr', getAddr);
app.post('/addr_count', getAddrCounter);
app.post('/tx', getTx);
Expand Down
Loading

0 comments on commit 3513fbf

Please sign in to comment.