From 344f543605eb2bede72544e9ea653fca85d68252 Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Wed, 26 Feb 2014 18:57:51 -0300 Subject: [PATCH 1/2] fix route when reload the page from the front-end --- config/routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.js b/config/routes.js index 220b51b5..8d35cd46 100644 --- a/config/routes.js +++ b/config/routes.js @@ -45,5 +45,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); }; From c7259ab7e6c57a363968d05fbdf6cc33d3b3695e Mon Sep 17 00:00:00 2001 From: Gustavo Cortez Date: Thu, 27 Feb 2014 14:11:05 -0300 Subject: [PATCH 2/2] send raw tx by POST --- app/controllers/transactions.js | 10 +++++++++- config/routes.js | 1 + lib/Rpc.js | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/controllers/transactions.js b/app/controllers/transactions.js index e7b09ad3..4b1ac985 100644 --- a/app/controllers/transactions.js +++ b/app/controllers/transactions.js @@ -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 ... diff --git a/config/routes.js b/config/routes.js index 8d35cd46..4ccb56e8 100644 --- a/config/routes.js +++ b/config/routes.js @@ -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'); diff --git a/lib/Rpc.js b/lib/Rpc.js index 9a465935..466690bd 100644 --- a/lib/Rpc.js +++ b/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);