api/rawtx endpoint added to return a JSON containing the raw transaction serialized as a hex-encoded string

This commit is contained in:
Richard Hoop 2015-03-09 15:24:10 -04:00
parent d0fab56469
commit 3019229e44
3 changed files with 43 additions and 10 deletions

View File

@ -180,6 +180,8 @@ The end-points are:
```
/api/tx/[:txid]
/api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
/api/raw/[:rawid]
/api/raw/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
```
### Address
```

View File

@ -10,6 +10,12 @@ var util = require('util');
var Rpc = require('../../lib/Rpc');
var imports = require('soop').imports();
var bitcore = require('bitcore');
var RpcClient = bitcore.RpcClient;
var config = require('../../config/config');
var bitcoreRpc = imports.bitcoreRpc || new RpcClient(config.bitcoind);
var tDb = require('../../lib/TransactionDb').default();
var bdb = require('../../lib/BlockDb').default();
@ -34,6 +40,17 @@ exports.send = function(req, res) {
});
};
exports.rawTransaction = function (req, res, next, txid) {
console.log(txid);
bitcoreRpc.getRawTransaction(txid, function (err, transaction) {
if (err || !transaction)
return common.handleErrors(err, res);
else {
req.rawTransaction = { 'rawtx': transaction.result };
return next();
}
});
};
/**
* Find transaction by hash ...
@ -61,6 +78,16 @@ exports.show = function(req, res) {
}
};
/**
* Show raw transaction
*/
exports.showRaw = function(req, res) {
if (req.rawTransaction) {
res.jsonp(req.rawTransaction);
}
};
var getTransaction = function(txid, cb) {

View File

@ -27,6 +27,10 @@ module.exports = function(app) {
app.get(apiPrefix + '/txs', transactions.list);
app.post(apiPrefix + '/tx/send', transactions.send);
// Raw Routes
app.get(apiPrefix + '/rawtx/:txid', transactions.showRaw);
app.param('txid', transactions.rawTransaction);
// Address routes
var addresses = require('../app/controllers/addresses');
app.get(apiPrefix + '/addr/:addr', addresses.show);