Merge pull request #6 from cmgustavo/feature/01-sendtx-support

Feature/01 sendtx support
This commit is contained in:
Matias Alejo Garcia 2014-02-27 15:38:28 -02:00
commit 1af6bb7a02
3 changed files with 22 additions and 2 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');
@ -45,5 +46,5 @@ module.exports = function(app) {
//Home route
var index = require('../app/controllers/index');
app.get(apiPrefix + '/version', index.version);
app.get('/', index.render);
app.get('*', index.render);
};

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