send raw tx by POST

This commit is contained in:
Gustavo Cortez 2014-02-27 14:11:05 -03:00
parent 344f543605
commit c7259ab7e6
3 changed files with 21 additions and 1 deletions

View File

@ -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 ...

View File

@ -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');

View File

@ -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);