fix conflicts
This commit is contained in:
parent
b9fb7b235f
commit
ef0b558ed9
@ -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
|
* List of blocks by date
|
||||||
|
|||||||
@ -72,6 +72,15 @@ BlockSchema.statics.load = function(id, cb) {
|
|||||||
}).exec(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) {
|
BlockSchema.statics.fromHash = function(hash, cb) {
|
||||||
this.findOne({
|
this.findOne({
|
||||||
|
|||||||
@ -14,6 +14,9 @@ module.exports = function(app, historicSync) {
|
|||||||
app.get('/api/block/:blockHash', blocks.show);
|
app.get('/api/block/:blockHash', blocks.show);
|
||||||
app.param('blockHash', blocks.block);
|
app.param('blockHash', blocks.block);
|
||||||
|
|
||||||
|
app.get('/api/block-index/:height', blocks.blockindex);
|
||||||
|
app.param('height', blocks.blockindex);
|
||||||
|
|
||||||
// Transaction routes
|
// Transaction routes
|
||||||
var transactions = require('../app/controllers/transactions');
|
var transactions = require('../app/controllers/transactions');
|
||||||
app.get('/api/tx/:txid', transactions.show);
|
app.get('/api/tx/:txid', transactions.show);
|
||||||
|
|||||||
@ -7,6 +7,10 @@ angular.module('insight').config(['$routeProvider',
|
|||||||
when('/block/:blockHash', {
|
when('/block/:blockHash', {
|
||||||
templateUrl: 'views/block.html'
|
templateUrl: 'views/block.html'
|
||||||
}).
|
}).
|
||||||
|
when('/block-index/:blockHeight', {
|
||||||
|
controller: 'BlocksController',
|
||||||
|
template: 'Redirecting...'
|
||||||
|
}).
|
||||||
when('/tx/:txId', {
|
when('/tx/:txId', {
|
||||||
templateUrl: 'views/transaction.html'
|
templateUrl: 'views/transaction.html'
|
||||||
}).
|
}).
|
||||||
|
|||||||
@ -23,5 +23,11 @@ angular.module('insight.blocks').factory('Block',
|
|||||||
|
|
||||||
angular.module('insight.blocks').factory('Blocks',
|
angular.module('insight.blocks').factory('Blocks',
|
||||||
function($resource) {
|
function($resource) {
|
||||||
return $resource('/api/blocks');
|
return $resource('/api/blocks');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
angular.module('insight.blocks').factory('BlockByHeight',
|
||||||
|
function($resource) {
|
||||||
|
return $resource('/api/block-index/:blockHeight');
|
||||||
|
});
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user