Merge remote-tracking branch 'bitpay/master' into feature/prototype-p2p

This commit is contained in:
Manuel Araoz 2014-01-08 14:31:38 -03:00
commit 4cb232e5ca
18 changed files with 194 additions and 53 deletions

View File

@ -48,7 +48,6 @@ $ npm install -g bower
## API
## Prerequisites
Get bitcore from github repository:
@ -62,21 +61,23 @@ $ npm install -g bower
check utils/sync.js --help for options.
## API
A REST API is provided at /api. The entry points are:
### Blocks
```
/block/[:hash]
/block/00000000a967199a2fad0877433c93df785a8d8ce062e5f9b451cd1397bdbf62
/api/block/[:hash]
/api/block/00000000a967199a2fad0877433c93df785a8d8ce062e5f9b451cd1397bdbf62
```
### Transactions
```
/tx/[:txid]
/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
/api/tx/[:txid]
/api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
```
## Troubleshooting
If you did not get all library during grunt command, please use the follow command:

View File

@ -1,15 +1,13 @@
'use strict';
var Block = require('../models/Block');
//, _ = require('lodash');
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block');
//, _ = require('lodash');
/**
* Find block by hash ...
@ -25,9 +23,47 @@ exports.block = function(req, res, next, hash) {
/**
* Show block
* Show block
*/
exports.show = function(req, res) {
res.jsonp(req.block);
};
/**
* List of blocks at HomePage
*/
exports.last_blocks = function(req, res) {
Block.find().sort({time:-1}).limit(7).exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};
/**
* List of blocks by date
*/
exports.list = function(req, res) {
var findParam = {};
if (req.query.blockDate) {
findParam = {};
}
Block
.find(findParam)
.limit(5)
.exec(function(err, blocks) {
if (err) {
res.render('error', {
status: 500
});
} else {
res.jsonp(blocks);
}
});
};

View File

@ -19,6 +19,7 @@ var BlockSchema = new Schema({
unique: true,
},
size: Number,
height: Number,
confirmations: Number,
version: Number,
merkleroot: String,
@ -93,5 +94,4 @@ BlockSchema.statics.fromHash = function(hash, cb) {
}).exec(cb);
};
module.exports = mongoose.model('Block', BlockSchema);

View File

@ -23,9 +23,12 @@ script(type='text/javascript', src='/js/directives.js')
script(type='text/javascript', src='/js/filters.js')
//Application Services
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')
//Application Controllers
script(type='text/javascript', src='/js/controllers/index.js')
script(type='text/javascript', src='/js/controllers/header.js')
script(type='text/javascript', src='/js/controllers/blocks.js')
script(type='text/javascript', src='/js/init.js')

View File

@ -2,24 +2,3 @@ extends layouts/default
block content
section.container(data-ng-view)
section.container
p ˈmɪst(ə)ri/'
| noun
audio(src="https://ssl.gstatic.com/dictionary/static/sounds/de/0/mystery.mp3",preload="auto",data-dobid="aud",id="aud")
button(onclick="document.getElementById('aud').play()") Play
ol
li
strong something that is difficult or impossible to understand or explain.
p "the mysteries of outer space"
| synonyms: puzzle, enigma, conundrum, riddle, secret, unsolved problem, problem, question, question mark, closed book; secrecy or obscurity.
p "much of her past is shrouded in mystery"
| synonyms: secrecy, darkness, obscurity, ambiguity, ambiguousness, uncertainty, impenetrability, vagueness, nebulousness; More
li
strong a person or thing whose identity or nature is puzzling or unknown.
p "He's a bit of a mystery, said Nina"
li
strong a novel, play, or film dealing with a puzzling crime, especially a murder.
p "the 1920s murder mystery, The Ghost Train"
| synonyms: thriller, detective story/novel, murder story; More

View File

@ -8,12 +8,14 @@ module.exports = function(app) {
//Block routes
var blocks = require('../app/controllers/blocks');
app.get('/block/:blockHash', blocks.show);
app.get('/api/blocks', blocks.list);
app.get('/api/block/:blockHash', blocks.show);
app.param('blockHash', blocks.block);
app.get('/last_blocks', blocks.last_blocks);
var transactions = require('../app/controllers/transactions');
app.get('/tx/:txid', transactions.show);
app.param('txid', transactions.transaction);
};

View File

@ -1,5 +1,7 @@
'use strict';
angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system']);
angular.module('mystery', ['ngCookies', 'ngResource', 'ngRoute', 'ui.bootstrap', 'ui.route', 'mystery.system', 'mystery.index', 'mystery.blocks']);
angular.module('mystery.system', []);
angular.module('mystery.system', []);
angular.module('mystery.index', []);
angular.module('mystery.blocks', []);

View File

@ -4,9 +4,18 @@
angular.module('mystery').config(['$routeProvider',
function($routeProvider) {
$routeProvider.
when('/block/:blockHash', {
templateUrl: 'views/block.html'
}).
when('/', {
templateUrl: 'views/index.html'
}).
when('/blocks', {
templateUrl: 'views/blocks/list.html'
}).
when('/blocks-date/:blockDate', {
templateUrl: 'views/blocks/list_date.html'
}).
otherwise({
redirectTo: '/'
});

View File

@ -0,0 +1,30 @@
'use strict';
angular.module('mystery.blocks').controller('BlocksController', ['$scope', '$routeParams', '$location', 'Global', 'Block', 'Blocks', function ($scope, $routeParams, $location, Global, Block, Blocks) {
$scope.global = Global;
$scope.list_blocks = function() {
Blocks.query(function(blocks) {
$scope.blocks = blocks;
});
};
$scope.list_blocks_date = function() {
Blocks.query({
blockDate: $routeParams.blockDate
}, function(blocks) {
$scope.blocks = blocks;
});
};
$scope.findOne = function() {
Block.get({
blockHash: $routeParams.blockHash
}, function(block) {
$scope.block = block;
});
};
// for avoid warning. please remove when you use Blocks
$scope.blocks = Blocks;
}]);

View File

@ -4,11 +4,8 @@ angular.module('mystery.system').controller('HeaderController', ['$scope', 'Glob
$scope.global = Global;
$scope.menu = [{
'title': 'Articles',
'link': 'articles'
}, {
'title': 'Create New Article',
'link': 'articles/create'
'title': 'Blocks',
'link': 'blocks'
}];
$scope.isCollapsed = false;

View File

@ -1,5 +1,10 @@
'use strict';
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', function ($scope, Global) {
angular.module('mystery.system').controller('IndexController', ['$scope', 'Global', 'Index', function ($scope, Global, Index) {
$scope.global = Global;
}]);
$scope.last_blocks = function() {
Index.query(function(blocks) {
$scope.blocks = blocks;
});
};
}]);

View File

@ -0,0 +1,11 @@
'use strict';
angular.module('mystery.blocks').factory('Block', ['$resource', function($resource) {
return $resource('/api/block/:blockHash', {
blockHash: '@blockHash'
});
}]);
angular.module('mystery.blocks').factory('Blocks', ['$resource', function($resource) {
return $resource('/api/blocks');
}]);

View File

@ -0,0 +1,5 @@
'use strict';
angular.module('mystery.index').factory('Index', ['$resource', function($resource) {
return $resource('/last_blocks');
}]);

23
public/views/block.html Normal file
View File

@ -0,0 +1,23 @@
<section data-ng-controller="BlocksController" data-ng-init="findOne()">
<div class="page-header">
<h1>Block Page</h1>
</div>
<table class="table table-striped">
<thead>
<th>Height</th>
<th>Age</th>
<th>Transactions</th>
<th>Confirmations</th>
<th>Size (kB)</th>
</thead>
<tbody>
<tr>
<td>{{block.height}}</td>
<td>{{block.time | date:'short'}}</td>
<td>{{block.tx.length }}</td>
<td>{{block.confirmations}}</td>
<td>{{block.size / 1024}}</td>
</tr>
</tbody>
</table>
</section>

View File

@ -0,0 +1,10 @@
<section data-ng-controller="BlocksController" data-ng-init="list_blocks()">
<div class="page-header">
<h1>Blocks by Date</h1>
</div>
<ul>
<li data-ng-repeat="block in blocks">
<span>{{block.hash}}</span> {{block.time}}
</li>
</ul>
</section>

View File

@ -0,0 +1,10 @@
<section data-ng-controller="BlocksController" data-ng-init="list_blocks_date()">
<div class="page-header">
<h1>Blocks by defined date</h1>
</div>
<ul>
<li data-ng-repeat="block in blocks">
<span>{{block.hash}}</span> {{block.time}}
</li>
</ul>
</section>

View File

@ -6,13 +6,13 @@
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">Mystery</a>
<a class="navbar-brand" href="#!">Mystery</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li class="active"><a href="#">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li data-ng-repeat="item in menu" ui-route="/{{item.link}}" ng-class="{active: $uiRoute}">
<a href="#!/{{item.link}}">{{item.title}}</a>
</li>
</ul>
</div>
</div>

View File

@ -1,5 +1,23 @@
<section data-ng-controller="IndexController">
<section data-ng-controller="IndexController" data-ng-init="last_blocks()">
<div class="page-header">
<h1>Hello BitPay!</h1>
</div>
<table class="table table-striped">
<thead>
<th>Height</th>
<th>Age</th>
<th>Transactions</th>
<th>Confirmations</th>
<th>Size (kB)</th>
</thead>
<tbody>
<tr data-ng-repeat="block in blocks">
<td><a href="#!/block/{{block.hash}}">{{block.height}}</a></td>
<td>{{block.time | date:'short'}}</td>
<td>{{block.tx.length }}</td>
<td>{{block.confirmations}}</td>
<td>{{block.size / 1024}}</td>
</tr>
</tbody>
</table>
</section>