broadcast tx

This commit is contained in:
tenthirtyone 2017-08-15 15:41:25 -04:00
parent 358662fb84
commit afd68116e7
4 changed files with 31 additions and 8 deletions

View File

@ -53,7 +53,7 @@ module.exports = function BlockAPI(router) {
poolInfo: {}, poolInfo: {},
}); });
} else { } else {
res.send(); res.status(404).send('Not Found');
} }
}); });
}); });
@ -107,8 +107,10 @@ module.exports = function BlockAPI(router) {
}); });
router.get('/block-index/:height', (req, res) => { router.get('/block-index/:height', (req, res) => {
let blockHeight = parseInt(req.params.height) || 1;
getBlock( getBlock(
{ height: req.params.height }, { height: blockHeight },
{ hash: 1 }, { hash: 1 },
MAX_BLOCKS, MAX_BLOCKS,
(err, block) => { (err, block) => {
@ -121,7 +123,7 @@ module.exports = function BlockAPI(router) {
blockHash: block[0].hash, blockHash: block[0].hash,
}); });
} else { } else {
res.send(); res.status(404).send('Not Found');
} }
}); });
}); });

View File

@ -1,5 +1,6 @@
const express = require('express'); const express = require('express');
const config = require('../../config'); const config = require('../../config');
const bodyParser = require('body-parser');
const app = express(); const app = express();
const api = express.Router(); const api = express.Router();
@ -7,6 +8,10 @@ const cors = require('./cors');
app.use(cors); app.use(cors);
app.use(bodyParser.urlencoded({ extended: false }))
app.use(bodyParser.json())
// Serve insight ui front end from root dir public folder // Serve insight ui front end from root dir public folder
app.use('/', express.static('./public')); app.use('/', express.static('./public'));
app.use('/blocks', express.static('./public')); app.use('/blocks', express.static('./public'));

View File

@ -52,6 +52,7 @@ module.exports = function transactionAPI(router) {
} }
if (block[0]) { if (block[0]) {
const height = block[0].height; const height = block[0].height;
request(`http://${config.bcoin_http}:${config.bcoin['http-port']}/tx/${req.params.txid}`, (err, localRes, body) => { request(`http://${config.bcoin_http}:${config.bcoin['http-port']}/tx/${req.params.txid}`, (err, localRes, body) => {
if (err) { if (err) {
logger.log('error', logger.log('error',
@ -68,7 +69,7 @@ module.exports = function transactionAPI(router) {
if (!body || !body.hash) { if (!body || !body.hash) {
logger.log('error', logger.log('error',
'No results found'); 'No results found');
res.status(501).send(); res.status(404).send();
return; return;
} }
res.send({ res.send({
@ -115,7 +116,6 @@ module.exports = function transactionAPI(router) {
logger.log('err', err); logger.log('err', err);
} }
if (block[0]) { if (block[0]) {
const height = block[0].height; const height = block[0].height;
request(`http://${config.bcoin_http}:${config.bcoin['http-port']}/block/${req.query.block}`, (err, localRes, body) => { request(`http://${config.bcoin_http}:${config.bcoin['http-port']}/block/${req.query.block}`, (err, localRes, body) => {
if (err) { if (err) {
@ -250,6 +250,21 @@ module.exports = function transactionAPI(router) {
}); });
router.post('/tx/send', (req, res) => { router.post('/tx/send', (req, res) => {
res.send('tx send stub'); const rawtx = req.body.rawtx || '';
console.log(rawtx);
request.post({
url: `http://${config.bcoin_http}:${config.bcoin['http-port']}/broadcast`,
body: {"tx": rawtx },
json: true,
}, (err, localRes, body) => {
if (err) {
logger.log('error',
`${err}`);
res.status(400).send(err);
return;
}
res.json(true);
});
}); });
}; };

View File

@ -14,6 +14,7 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"bcoin": "^1.0.0-beta.14", "bcoin": "^1.0.0-beta.14",
"body-parser": "^1.17.2",
"express": "^4.15.3", "express": "^4.15.3",
"mongoose": "^4.11.5", "mongoose": "^4.11.5",
"request": "^2.81.0", "request": "^2.81.0",