api/rawtx endpoint added to return a JSON containing the raw transaction serialized as a hex-encoded string
This commit is contained in:
parent
d0fab56469
commit
3019229e44
@ -180,6 +180,8 @@ The end-points are:
|
|||||||
```
|
```
|
||||||
/api/tx/[:txid]
|
/api/tx/[:txid]
|
||||||
/api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
|
/api/tx/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
|
||||||
|
/api/raw/[:rawid]
|
||||||
|
/api/raw/525de308971eabd941b139f46c7198b5af9479325c2395db7f2fb5ae8562556c
|
||||||
```
|
```
|
||||||
### Address
|
### Address
|
||||||
```
|
```
|
||||||
|
|||||||
@ -8,7 +8,13 @@ var async = require('async');
|
|||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
var util = require('util');
|
var util = require('util');
|
||||||
|
|
||||||
var Rpc = require('../../lib/Rpc');
|
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 tDb = require('../../lib/TransactionDb').default();
|
||||||
var bdb = require('../../lib/BlockDb').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 ...
|
* 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) {
|
var getTransaction = function(txid, cb) {
|
||||||
|
|
||||||
|
|||||||
@ -27,6 +27,10 @@ module.exports = function(app) {
|
|||||||
app.get(apiPrefix + '/txs', transactions.list);
|
app.get(apiPrefix + '/txs', transactions.list);
|
||||||
app.post(apiPrefix + '/tx/send', transactions.send);
|
app.post(apiPrefix + '/tx/send', transactions.send);
|
||||||
|
|
||||||
|
// Raw Routes
|
||||||
|
app.get(apiPrefix + '/rawtx/:txid', transactions.showRaw);
|
||||||
|
app.param('txid', transactions.rawTransaction);
|
||||||
|
|
||||||
// Address routes
|
// Address routes
|
||||||
var addresses = require('../app/controllers/addresses');
|
var addresses = require('../app/controllers/addresses');
|
||||||
app.get(apiPrefix + '/addr/:addr', addresses.show);
|
app.get(apiPrefix + '/addr/:addr', addresses.show);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user