send raw tx by POST
This commit is contained in:
parent
344f543605
commit
c7259ab7e6
|
@ -9,10 +9,18 @@ var common = require('./common');
|
||||||
|
|
||||||
var TransactionDb = require('../../lib/TransactionDb').class();
|
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 tDb = new TransactionDb();
|
||||||
var bdb = new BlockDb();
|
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 ...
|
* Find transaction by hash ...
|
||||||
|
|
|
@ -25,6 +25,7 @@ module.exports = function(app) {
|
||||||
app.get(apiPrefix + '/tx/:txid', transactions.show);
|
app.get(apiPrefix + '/tx/:txid', transactions.show);
|
||||||
app.param('txid', transactions.transaction);
|
app.param('txid', transactions.transaction);
|
||||||
app.get(apiPrefix + '/txs', transactions.list);
|
app.get(apiPrefix + '/txs', transactions.list);
|
||||||
|
app.post(apiPrefix + '/tx/send', transactions.send);
|
||||||
|
|
||||||
// Address routes
|
// Address routes
|
||||||
var addresses = require('../app/controllers/addresses');
|
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);
|
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;
|
return Rpc;
|
||||||
}
|
}
|
||||||
module.defineClass(spec);
|
module.defineClass(spec);
|
||||||
|
|
Loading…
Reference in New Issue