Merge branch 'master' of github.com:bitpay/mystery into test/test-p2p-sync

This commit is contained in:
Manuel Araoz 2014-01-16 15:39:51 -03:00
commit 8c2e118f76
10 changed files with 288 additions and 114 deletions

View File

@ -5,12 +5,11 @@
*/ */
var Status = require('../models/Status'); var Status = require('../models/Status');
var async = require('async');
/** /**
* Status * Status
*/ */
exports.show = function(req, res) { exports.show = function(req, res, next) {
if (! req.query.q) { if (! req.query.q) {
res.status(400).send('Bad Request'); res.status(400).send('Bad Request');
@ -19,30 +18,37 @@ exports.show = function(req, res) {
var s = req.query.q; var s = req.query.q;
var d = Status.new(); var d = Status.new();
if (s == 'getInfo') { if (s === 'getInfo') {
d.getInfo(function(err) { d.getInfo(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(d);
}); });
} }
else if (s == 'getDifficulty') { else if (s === 'getDifficulty') {
d.getDifficulty(function(err) { d.getDifficulty(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(d);
}); });
} }
else if (s == 'getTxOutSetInfo') { else if (s === 'getTxOutSetInfo') {
d.getTxOutSetInfo(function(err) { d.getTxOutSetInfo(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(d);
}); });
} }
else if (s == 'getBestBlockHash') { else if (s === 'getBestBlockHash') {
d.getBestBlockHash(function(err) { d.getBestBlockHash(function(err) {
if (err) next(err); if (err) next(err);
res.jsonp(d); res.jsonp(d);
}); });
} }
else if (s === 'getLastBlockHash') {
d.getLastBlockHash(function(err) {
if (err) next(err);
res.jsonp(d);
});
}
else { else {
res.status(400).send('Bad Request'); res.status(400).send('Bad Request');
} }

View File

@ -13,6 +13,7 @@ function spec() {
this.difficulty = {}; this.difficulty = {};
this.txoutsetinfo = {}; this.txoutsetinfo = {};
this.bestblockhash = {}; this.bestblockhash = {};
this.lastblockhash = {};
} }
Status.prototype.getInfo = function(next) { Status.prototype.getInfo = function(next) {
@ -79,6 +80,31 @@ function spec() {
}); });
}; };
Status.prototype.getLastBlockHash = function(next) {
var that = this;
async.waterfall(
[
function(callback){
rpc.getBlockCount(function(err, bc){
if (err) return callback(err);
callback(null, bc.result);
});
},
function(bc, callback){
rpc.getBlockHash(bc, function(err, bh){
if (err) return callback(err);
callback(null, bh.result);
});
}
],
function (err, result) {
that.lastblockhash = result;
return next();
}
);
};
return Status; return Status;
} }

View File

@ -4,6 +4,7 @@
//script(type='text/javascript', src='/lib/jquery/jquery.min.js') //script(type='text/javascript', src='/lib/jquery/jquery.min.js')
//script(type='text/javascript', src='/lib/bootstrap/dist/js/bootstrap.min.js') //script(type='text/javascript', src='/lib/bootstrap/dist/js/bootstrap.min.js')
script(type='text/javascript', src='/socket.io/socket.io.js')
script(type='text/javascript', src='/lib/momentjs/moment.js') script(type='text/javascript', src='/lib/momentjs/moment.js')
//AngularJS //AngularJS
@ -27,11 +28,11 @@ script(type='text/javascript', src='/js/directives.js')
script(type='text/javascript', src='/js/filters.js') script(type='text/javascript', src='/js/filters.js')
//Application Services //Application Services
script(type='text/javascript', src='/js/services/global.js')
script(type='text/javascript', src='/js/services/status.js') script(type='text/javascript', src='/js/services/status.js')
script(type='text/javascript', src='/js/services/address.js') script(type='text/javascript', src='/js/services/address.js')
script(type='text/javascript', src='/js/services/transactions.js') script(type='text/javascript', src='/js/services/transactions.js')
script(type='text/javascript', src='/js/services/blocks.js') script(type='text/javascript', src='/js/services/blocks.js')
script(type='text/javascript', src='/js/services/global.js')
script(type='text/javascript', src='/js/services/index.js') script(type='text/javascript', src='/js/services/index.js')
//Application Controllers //Application Controllers

View File

@ -8,10 +8,8 @@ head
meta(name="keywords", content="node.js, express, mongoose, mongodb, angularjs") meta(name="keywords", content="node.js, express, mongoose, mongodb, angularjs")
meta(name="description", content="Mystery") meta(name="description", content="Mystery")
link(href='/img/icons/favicon.ico', rel='shortcut icon', type='image/x-icon') link(rel='shortcut icon', href='/img/icons/favicon.ico', type='image/x-icon')
link(rel='stylesheet', href='//fonts.googleapis.com/css?family=Ubuntu:300,400,500,700,400italic')
link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap.min.css') link(rel='stylesheet', href='/lib/bootstrap/dist/css/bootstrap.min.css')
link(rel='stylesheet', href='/css/common.css') link(rel='stylesheet', href='/css/common.css')
script(src='/socket.io/socket.io.js')

View File

@ -10,6 +10,7 @@
-------------------------------------------------- */ -------------------------------------------------- */
html, html,
body { body {
color: #373D42;
font-family: Ubuntu, sans-serif; font-family: Ubuntu, sans-serif;
height: 100%; height: 100%;
/* The html and body elements cannot have any padding or margin. */ /* The html and body elements cannot have any padding or margin. */
@ -74,12 +75,97 @@ body {
line-height: 18px; line-height: 18px;
} }
.col-gray {
background-color: #F4F4F4;
padding: 15px;
margin-top: 10px;
width: 360px;
height: 89%;
border-radius: 5px;
}
.ellipsis {
display: block;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
}
.line20 {
border: 1px solid #D4D4D4;
margin-bottom: 15px;
}
.line10 {
border: 1px solid #EAEAEA;
margin: 10px 0;
}
.col-gray .address {
float: right;
width: 150px;
}
.block-id {
background: #373D42;
border: 3px solid #FFFFFF;
width: 165px;
height: 165px;
margin: 10px auto;
border-radius: :;px;
}
.block-id h1 {
font-family: Ubuntu-Medium;
font-size: 24px;
color: #FFFFFF;
line-height: 30px;
text-align: center;
}
.icon-block {
font-size: 27px;
color: white;
margin-top: 20px;
}
.block-tx {
border-radius: 2px;
background: #F4F4F4;
margin: 20px 0;
padding: 15px;
}
.btn-primary {
border-radius: 2px;
background: #64920F;
border: 2px solid #557F08;
}
.btn-primary:hover, .btn-primary:focus, .btn-primary:active, .btn-primary.active, .open .dropdown-toggle.btn-primary {
background: #fff;
border: 2px solid #ccc;
color: #373D42;
font-weight: bold;
}
/* Set the fixed height of the footer here */ /* Set the fixed height of the footer here */
#footer { #footer {
height: 60px; height: 60px;
background-color: #f5f5f5; background-color: #f5f5f5;
} }
.line-bot {
padding: 0 0 10px 0;
margin-bottom: 10px;
border-bottom: 2px solid #EAEAEA;
}
.line-top {
padding: 10px 0;
margin-top: 10px;
border-top: 1px solid #EAEAEA;
}
/* Custom page CSS /* Custom page CSS
-------------------------------------------------- */ -------------------------------------------------- */
@ -102,7 +188,7 @@ body {
} }
.address { .address {
font-size: 10px; font-size: 11px;
} }
#search { width: 400px; } #search { width: 400px; }

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
var app = angular.module('mystery', angular.module('mystery',
['ngAnimate', ['ngAnimate',
'ngCookies', 'ngCookies',
'ngResource', 'ngResource',

View File

@ -7,18 +7,22 @@ angular.module('mystery.status').controller('StatusController', ['$scope', '$rou
Status.get({ Status.get({
q: q q: q
}, function(d) { }, function(d) {
if (q == 'getInfo') { if (q === 'getInfo') {
$scope.info = d.info; $scope.info = d.info;
} }
if (q == 'getDifficulty') { if (q === 'getDifficulty') {
$scope.difficulty = d.difficulty; $scope.difficulty = d.difficulty;
} }
if (q == 'getTxOutSetInfo') { if (q === 'getTxOutSetInfo') {
$scope.txoutsetinfo = d.txoutsetinfo; $scope.txoutsetinfo = d.txoutsetinfo;
} }
if (q == 'getBestBlockHash') { if (q === 'getBestBlockHash') {
$scope.bestblockhash = d.bestblockhash; $scope.bestblockhash = d.bestblockhash;
} }
if (q === 'getLastBlockHash') {
$scope.lastblockhash = d.lastblockhash;
}
}); });
}; };

View File

@ -1,107 +1,150 @@
<section data-ng-controller="BlocksController" data-ng-init="findOne()"> <section data-ng-controller="BlocksController" data-ng-init="findOne()">
<div class="page-header">
<h1 data-ng-if="block">Block #{{ block.height }}</h1>
</div>
<div class="row"> <div class="row">
<div class="col-md-6"> <div class="col-md-4">
<div class="panel panel-default"> <div class="bs-sidebar hidden-print affix col-gray">
<div class="panel-heading"> <div class="block-id">
<h3 class="panel-title">Summary</h3> <div class="icon-block text-center">
<span class="glyphicon glyphicon-list-alt"></span>
</div>
<h1 data-ng-if="block">Block #{{ block.height }}</h1>
</div> </div>
<div class="panel-body">
<table class="table table-striped"> <div data-ng-show="!tx.isCoinBase">
<tbody> <div class="panel-heading">
<tr> <h3>Hashes</h3>
<td>Number Of Transactions</td> </div>
<td>{{block.tx.length}}<td> <div class="panel-body">
</tr> <table class="table table">
<tr> <tbody>
<td>Height</td> <tr>
<td>{{block.height}}</td> <td>Hash</td>
</tr> <td><a class="address ellipsis" href="/#!/block/{{block.hash}}">{{block.hash}}</a></td>
<tr> </tr>
<td>Timestamp</td> <tr>
<td>{{block.time * 1000 | date:'medium'}}</td> <td>Previous Block</td>
</tr> <td><a class="address ellipsis" href="/#!/block/{{block.previousblockhash}}">{{block.previousblockhash}}</a></td>
<tr> </tr>
<td>Difficulty</td> <tr>
<td>{{block.difficulty}}</td> <td>Next Block</td>
</tr> <td><a class="address ellipsis" href="/#!/block/{{block.nextblockhash}}">{{block.nextblockhash}}</a></td>
<tr> </tr>
<td>Bits</td> <tr>
<td>{{block.bits}}</td> <td>Merkle Root</td>
</tr> <td> <p class="address ellipsis"> {{block.merkleroot}} </p> </td>
<tr> </tr>
<td>Size</td> </tbody>
<td>{{block.size}}</td> </table>
</tr> </div>
<tr>
<td>Version</td>
<td>{{block.version}}</td>
</tr>
<tr>
<td>Nonce</td>
<td>{{block.nonce}}</td>
</tr>
</tbody>
</table>
</div> </div>
</div> </div>
</div> </div> <!-- END OF COL-GRAY -->
<div class="col-md-6">
<div class="panel panel-default" data-ng-show="!tx.isCoinBase"> <div class="col-md-8">
<div class="panel-heading"> <h3>Summary</h3>
<h3 class="panel-title">Hashes</h3> <div class="row">
</div> <div class="col-md-6">
<div class="panel-body"> <table class="table">
<table class="table table-striped">
<tbody> <tbody>
<tr> <tr>
<td>Hash</td> <td> <strong> Number Of Transactions </strong> </td>
<td><a class="address" href="/#!/block/{{block.hash}}">{{block.hash}}</a></td> <td class="text-right text-muted">{{block.tx.length}}<td>
</tr> </tr>
<tr> <tr>
<td>Previous Block</td> <td> <strong> Output Total</strong></td>
<td><a class="address" href="/#!/block/{{block.previousblockhash}}">{{block.previousblockhash}}</a></td> <td class="text-right text-muted">--</td>
</tr> </tr>
<tr> <tr>
<td>Next Block</td> <td> <strong> Estimated Transaction Volume </strong></td>
<td><a class="address" href="/#!/block/{{block.nextblockhash}}">{{block.nextblockhash}}</a></td> <td class="text-right text-muted">--</td>
</tr> </tr>
<tr> <tr>
<td>Merkle Root</td> <td> <strong> Transaction Fees </strong></td>
<td class="address">{{block.merkleroot}}</td> <td class="text-right text-muted">--</td>
</tr> </tr>
<tr>
<td> <strong> Height </strong></td>
<td class="text-right text-muted">{{block.height}}</td>
</tr>
<tr>
<td> <strong> Timestamp </strong></td>
<td class="text-right text-muted">{{block.time * 1000 | date:'medium'}}</td>
</tr>
</tbody> </tbody>
</table> </table>
</div> </div>
<div class="col-md-6">
<table class="table">
<tbody>
<tr>
<td> <strong> Relayed By </strong></td>
<td class="text-right text-muted">--</td>
</tr>
<tr>
<td> <strong> Difficulty </strong></td>
<td class="text-right text-muted">{{block.difficulty}}</td>
</tr>
<tr>
<td> <strong> Bits </strong></td>
<td class="text-right text-muted">{{block.bits}}</td>
</tr>
<tr>
<td> <strong> Size </strong></td>
<td class="text-right text-muted">{{block.size}}</td>
</tr>
<tr>
<td> <strong> Version </strong></td>
<td class="text-right text-muted">{{block.version}}</td>
</tr>
<tr>
<td> <strong> Nonce </strong></td>
<td class="text-right text-muted">{{block.nonce}}</td>
</tr>
</tbody>
</table>
</div>
</div><!-- END OF ROW -->
<div data-ng-controller="transactionsController" data-ng-init="byBlock(params.blockHash)">
<h2>Transactions <small >Transactions contained within this block</small></h2>
<div class="block-tx" data-ng-repeat="tx in txs">
<div class="line-bot">
<a href="/#!/tx/{{tx.txid}}">{{tx.txid}}</a>
<span class="pull-right">{{tx.time * 1000 | date:'medium'}}</span>
</div>
<div class="row">
<div class="col-md-5">
Transmitter
</div>
<div class="col-md-2">
<span class="glyphicon glyphicon-arrow-right lead"></span>
</div>
<div class="col-md-5">
<div class="row">
<div class="col-md-6">
<p>Receptor</p>
<p>Receptor</p>
</div>
<div class="col-md-6 text-right">
<p>Bitcoin of Receptor</p>
<p>Bitcoin of Receptor</p>
</div>
</div>
</div>
</div>
<div class="line-top">
<small class="text-muted">Feeds: {{tx.feeds}}</small>
<div class="btn btn-primary pull-right">
{{tx.valueOut}}
</div>
</div>
</div><!-- END OF BLOCK-TX -->
</div> </div>
</div> </div>
</div> </div>
<div data-ng-controller="transactionsController" data-ng-init="byBlock(params.blockHash)">
<h2>Transactions <small>Transactions contained within this block</small></h2>
<table class="table table-striped">
<thead>
<tr>
<th>Transaction Hash</th>
<th>Datetime</th>
<th>Fee</th>
<th>Transacted Amount</th>
</tr>
</thead>
<tbody>
<tr data-ng-show="!txs.length">
<td colspan="4" class="text-center">Loading...</td>
</tr>
<tr data-ng-repeat="tx in txs">
<td><a href="/#!/tx/{{tx.txid}}">{{tx.txid}}</a></td>
<td>{{tx.time * 1000 | date:'medium'}}</td>
<td>{{tx.feeds}}</td>
<td>{{tx.valueOut}}</td>
</tr>
</tbody>
</table>
</div>
</section> </section>

View File

@ -127,14 +127,14 @@
</table> </table>
</div> </div>
<div class="col-lg-6"> <div class="col-lg-6">
<h3>getBestBlockHash</h3> <h3>getLastBlockHash</h3>
<table class="table table-striped" data-ng-init="getData('getBestBlockHash')"> <table class="table table-striped" data-ng-init="getData('getLastBlockHash')">
<tbody> <tbody>
<tr data-ng-show="!bestblockhash"> <tr data-ng-show="!lastblockhash">
<td colspan="1" class="text-center">Loading...</td> <td colspan="1" class="text-center">Loading...</td>
</tr> </tr>
<tr> <tr>
<td>{{bestblockhash}}</td> <td>{{lastblockhash}}</td>
</tr> </tr>
</tbody> </tbody>
</table> </table>

View File

@ -60,6 +60,16 @@ describe('Status', function(){
}); });
}); });
it('getLastBlockHash', function(done) {
var d = new Status();
d.getLastBlockHash(function(err) {
if (err) done(err);
assert.equal('string', typeof d.lastblockhash);
done();
});
});
}); });