send raw tx by POST
This commit is contained in:
parent
344f543605
commit
c7259ab7e6
|
@ -8,11 +8,19 @@ var async = require('async');
|
|||
var common = require('./common');
|
||||
|
||||
var TransactionDb = require('../../lib/TransactionDb').class();
|
||||
var BlockDb = require('../../lib/BlockDb').class();
|
||||
var BlockDb = require('../../lib/BlockDb').class();
|
||||
var Rpc = require('../../lib/Rpc').class();
|
||||
|
||||
var tDb = new TransactionDb();
|
||||
var bdb = new BlockDb();
|
||||
|
||||
exports.send = function(req, res) {
|
||||
Rpc.sendRawTransaction(req.body.rawtx, function(err, txid) {
|
||||
if (err) return common.handleErrors(err, res);
|
||||
res.json({'txid' : txid});
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Find transaction by hash ...
|
||||
|
|
|
@ -25,6 +25,7 @@ module.exports = function(app) {
|
|||
app.get(apiPrefix + '/tx/:txid', transactions.show);
|
||||
app.param('txid', transactions.transaction);
|
||||
app.get(apiPrefix + '/txs', transactions.list);
|
||||
app.post(apiPrefix + '/tx/send', transactions.send);
|
||||
|
||||
// Address routes
|
||||
var addresses = require('../app/controllers/addresses');
|
||||
|
|
11
lib/Rpc.js
11
lib/Rpc.js
|
@ -96,6 +96,17 @@ function spec(b) {
|
|||
return cb(err,info.result);
|
||||
});
|
||||
};
|
||||
|
||||
Rpc.sendRawTransaction = function(rawtx, cb) {
|
||||
var self = this;
|
||||
bitcoreRpc.sendRawTransaction(rawtx, function(err, txid) {
|
||||
if (err && err.code === -5) return cb(err); // transaction already in block chain
|
||||
if (err) return cb(self.errMsg(err));
|
||||
|
||||
return cb(err, txid.result);
|
||||
});
|
||||
};
|
||||
|
||||
return Rpc;
|
||||
}
|
||||
module.defineClass(spec);
|
||||
|
|
Loading…
Reference in New Issue