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