fix conflicts

This commit is contained in:
Gustavo Cortez 2014-01-20 18:52:28 -03:00
parent b9fb7b235f
commit ef0b558ed9
5 changed files with 37 additions and 1 deletions

View File

@ -32,6 +32,20 @@ exports.show = function(req, res) {
}
};
/**
* Show block by Height
*/
exports.blockindex = function(req, res, next, height) {
Block.fromHeight(height, function(err, hash) {
if (err) {
console.log(err);
res.status(400).send('Bad Request'); // TODO
}
else {
res.jsonp(hash);
}
});
};
/**
* List of blocks by date

View File

@ -72,6 +72,15 @@ BlockSchema.statics.load = function(id, cb) {
}).exec(cb);
};
BlockSchema.statics.fromHeight = function(height, cb) {
var rpc = new RpcClient(config.bitcoind);
var hash = {};
rpc.getBlockHash(height, function(err, bh){
if (err) return cb(err);
hash.blockHash = bh.result;
cb(null, hash);
});
};
BlockSchema.statics.fromHash = function(hash, cb) {
this.findOne({

View File

@ -14,6 +14,9 @@ module.exports = function(app, historicSync) {
app.get('/api/block/:blockHash', blocks.show);
app.param('blockHash', blocks.block);
app.get('/api/block-index/:height', blocks.blockindex);
app.param('height', blocks.blockindex);
// Transaction routes
var transactions = require('../app/controllers/transactions');
app.get('/api/tx/:txid', transactions.show);

View File

@ -7,6 +7,10 @@ angular.module('insight').config(['$routeProvider',
when('/block/:blockHash', {
templateUrl: 'views/block.html'
}).
when('/block-index/:blockHeight', {
controller: 'BlocksController',
template: 'Redirecting...'
}).
when('/tx/:txId', {
templateUrl: 'views/transaction.html'
}).

View File

@ -25,3 +25,9 @@ angular.module('insight.blocks').factory('Blocks',
function($resource) {
return $resource('/api/blocks');
});
angular.module('insight.blocks').factory('BlockByHeight',
function($resource) {
return $resource('/api/block-index/:blockHeight');
});