fix problem with transaction by hash

This commit is contained in:
Manuel Araoz 2015-04-30 07:29:57 -03:00
parent 6628263b31
commit 49f26d3ae5
6 changed files with 1480 additions and 25 deletions

1484
README.md

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,10 @@
'use strict';
var bitcore = require('bitcore');
var _ = bitcore.deps._;
var $ = bitcore.util.preconditions;
var Block = bitcore.Block;
var BitcoreNode = require('../../');
var errors = require('../../lib/errors');
var Blocks = {};
@ -28,7 +27,7 @@ Blocks.blockHashParam = function(req, res, next, blockHash) {
req.block = block;
})
.then(next)
.catch(BitcoreNode.errors.Blocks.NotFound, function() {
.catch(errors.Blocks.NotFound, function() {
res.status(404).send('Block with id ' + blockHash + ' not found');
})
.catch(function() {
@ -46,7 +45,7 @@ Blocks.heightParam = function(req, res, next, height) {
req.block = block;
})
.then(next)
.catch(BitcoreNode.errors.Blocks.NotFound, function() {
.catch(errors.Blocks.NotFound, function() {
res.status(404).send('Block with height ' + height + ' not found');
})
.catch(function() {

View File

@ -7,7 +7,7 @@ var _ = bitcore.deps._;
var $ = bitcore.util.preconditions;
var Transaction = bitcore.Transaction;
var BitcoreNode = require('../../');
var errors = require('../../lib/errors');
var Transactions = {};
@ -30,7 +30,7 @@ Transactions.txHashParam = function(req, res, next, txHash) {
req.tx = tx;
})
.then(next)
.catch(BitcoreNode.errors.Transactions.NotFound, function() {
.catch(errors.Transactions.NotFound, function() {
res.status(404).send('Transaction with id ' + txHash + ' not found');
})
.catch(function() {
@ -81,7 +81,7 @@ Transactions.send = function(req, res) {
.then(function() {
res.send('Transaction broadcasted successfully');
})
.catch(BitcoreNode.errors.Transactions.CantBroadcast, function(err) {
.catch(errors.Transactions.CantBroadcast, function(err) {
res.status(422).send(err.message);
});
};

View File

@ -1,7 +1,6 @@
'use strict';
var BitcoreNode = require('./lib/node');
BitcoreNode.errors = require('./lib/errors');
var BitcoreHTTP = require('./api/lib/http');
var bitcore = require('bitcore');
var Promise = require('bluebird');

View File

@ -223,4 +223,6 @@ BitcoreNode.prototype.sync = function() {
});
};
var errors = require('./errors');
BitcoreNode.errors = errors;
module.exports = BitcoreNode;

View File

@ -20,12 +20,11 @@ var LevelUp = require('levelup');
var Promise = require('bluebird');
var bitcore = require('bitcore');
var config = require('config');
var BitcoreNode = require('../../');
var errors = require('../errors');
var _ = bitcore.deps._;
var $ = bitcore.util.preconditions;
var NULLTXHASH = bitcore.util.buffer.emptyBuffer(32).toString('hex');
var GENESISTX = '4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b';
var helper = function(name) {
@ -87,7 +86,7 @@ TransactionService.Index = Index;
var txNotFound = function(error) {
if (error.message === 'No information available about transaction') {
throw new BitcoreNode.errors.Transactions.NotFound();
throw new errors.Transactions.NotFound();
}
throw error;
};