towards polishing tx api
This commit is contained in:
parent
749b8db70c
commit
ae03c8e454
@ -32,6 +32,9 @@ Transactions.txHashParam = function(req, res, next, txHash) {
|
||||
.then(next)
|
||||
.catch(BitcoreNode.errors.Transactions.NotFound, function() {
|
||||
res.status(404).send('Transaction with id ' + txHash + ' not found');
|
||||
})
|
||||
.catch(function() {
|
||||
console.log(arguments);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@ -15,7 +15,7 @@ var BitcoreHTTP = require('../../lib/http');
|
||||
var BitcoreNode = require('../../../');
|
||||
var mockTransactions = require('../data/transactions');
|
||||
|
||||
describe('BitcoreHTTP v1 transactions routes', function() {
|
||||
describe.only('BitcoreHTTP v1 transactions routes', function() {
|
||||
|
||||
// mocks
|
||||
var mockValidTx = new Transaction();
|
||||
@ -37,7 +37,7 @@ describe('BitcoreHTTP v1 transactions routes', function() {
|
||||
}
|
||||
return Promise.resolve();
|
||||
};
|
||||
app = new BitcoreHTTP(nodeMock).app;
|
||||
app = require('../app')(nodeMock);
|
||||
agent = request(app);
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,7 @@ var LevelUp = require('levelup');
|
||||
var Promise = require('bluebird');
|
||||
var bitcore = require('bitcore');
|
||||
var config = require('config');
|
||||
var BitcoreNode = require('../../');
|
||||
|
||||
var _ = bitcore.deps._;
|
||||
var $ = bitcore.util.preconditions;
|
||||
@ -53,7 +54,7 @@ var Index = {
|
||||
output: 'txo-', // txo-<txid>-<n> -> serialized Output
|
||||
spent: 'txs-', // txo-<txid>-<n>-<spend txid>-<m> -> block height of confirmation for spend
|
||||
address: 'txa-', // txa-<address>-<txid>-<n> -> Output
|
||||
addressSpent: 'txas-',
|
||||
addressSpent: 'txas-',
|
||||
// txa-<address>-<txid>-<n> -> {
|
||||
// heightSpent: number, (may be -1 for unconfirmed tx)
|
||||
// spentTx: string, spentTxInputIndex: number, spendInput: Input
|
||||
@ -84,10 +85,14 @@ function TransactionService(opts) {
|
||||
}
|
||||
TransactionService.Index = Index;
|
||||
|
||||
TransactionService.transactionRPCtoBitcore = function(rpcResponse) {
|
||||
if (rpcResponse.error) {
|
||||
throw new bitcore.Error(rpcResponse.error);
|
||||
var txNotFound = function(error) {
|
||||
if (error.message === 'No information available about transaction') {
|
||||
throw new BitcoreNode.errors.Transactions.NotFound();
|
||||
}
|
||||
throw error;
|
||||
};
|
||||
|
||||
TransactionService.transactionRPCtoBitcore = function(rpcResponse) {
|
||||
return new bitcore.Transaction(rpcResponse.result);
|
||||
};
|
||||
|
||||
@ -99,10 +104,12 @@ TransactionService.prototype.getTransaction = function(transactionId) {
|
||||
}
|
||||
|
||||
return Promise.try(function() {
|
||||
return self.rpc.getRawTransactionAsync(transactionId);
|
||||
}).then(function(rawTransaction) {
|
||||
return TransactionService.transactionRPCtoBitcore(rawTransaction);
|
||||
});
|
||||
return self.rpc.getRawTransactionAsync(transactionId);
|
||||
})
|
||||
.catch(txNotFound)
|
||||
.then(function(rawTransaction) {
|
||||
return TransactionService.transactionRPCtoBitcore(rawTransaction);
|
||||
});
|
||||
};
|
||||
|
||||
TransactionService.prototype._confirmOutput = function(ops, block, transaction) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user