RPC hookups fill the gaps way better than mongo in some places. See changes
This commit is contained in:
parent
90adbf3ece
commit
b1e540c8df
@ -1,15 +1,17 @@
|
|||||||
const config = {
|
const config = {
|
||||||
start_node: false,
|
start_node: true,
|
||||||
logging: 'debug',
|
logging: 'debug',
|
||||||
bcoin: {
|
bcoin: {
|
||||||
network: 'main',
|
network: 'main',
|
||||||
db: 'leveldb',
|
db: 'leveldb',
|
||||||
prefix: '.',
|
prefix: '.',
|
||||||
checkpoints: true,
|
checkpoints: true,
|
||||||
workers: true,
|
workers: false,
|
||||||
logLevel: 'info',
|
logLevel: 'info',
|
||||||
'max-inbound': 10,
|
'max-inbound': 10,
|
||||||
'max-outbound': 10,
|
'max-outbound': 10,
|
||||||
|
'index-tx': true,
|
||||||
|
'index-address': true,
|
||||||
},
|
},
|
||||||
mongodb: {
|
mongodb: {
|
||||||
uri: 'mongodb://localhost/bitcore',
|
uri: 'mongodb://localhost/bitcore',
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
const Block = require('../../models/block.js');
|
const Block = require('../../models/block.js');
|
||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
|
||||||
const MAX_BLOCKS = 200;
|
const MAX_BLOCKS = 100;
|
||||||
|
|
||||||
function getBlock(params, options, limit, cb) {
|
function getBlock(params, options, limit, cb) {
|
||||||
const defaultOptions = { _id: 0 };
|
const defaultOptions = { _id: 0 };
|
||||||
@ -76,6 +76,7 @@ module.exports = function BlockAPI(router) {
|
|||||||
res.status(501).send();
|
res.status(501).send();
|
||||||
logger.log('err', err);
|
logger.log('err', err);
|
||||||
}
|
}
|
||||||
|
|
||||||
res.json({
|
res.json({
|
||||||
blocks: blocks.map(block => ({
|
blocks: blocks.map(block => ({
|
||||||
hash: block.hash,
|
hash: block.hash,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
const Block = require('../../models/block.js');
|
const Block = require('../../models/block.js');
|
||||||
const Transaction = require('../../models/transaction');
|
const Transaction = require('../../models/transaction');
|
||||||
const logger = require('../logger');
|
const logger = require('../logger');
|
||||||
|
const request = require('request');
|
||||||
|
|
||||||
const MAX_TXS = 20;
|
const MAX_TXS = 20;
|
||||||
const MAX_BLOCKS = 1;
|
const MAX_BLOCKS = 1;
|
||||||
@ -39,151 +40,107 @@ function getTransactions(params, options, cb) {
|
|||||||
|
|
||||||
module.exports = function transactionAPI(router) {
|
module.exports = function transactionAPI(router) {
|
||||||
router.get('/tx/:txid', (req, res) => {
|
router.get('/tx/:txid', (req, res) => {
|
||||||
getBlock(
|
request(`http://localhost:8332/tx/${req.params.txid}`, (err, localRes, body) => {
|
||||||
{ 'txs.hash': req.params.txid },
|
if (err) {
|
||||||
{ },
|
logger.log('error',
|
||||||
MAX_BLOCKS,
|
`${err}`);
|
||||||
(err, blocks) => {
|
}
|
||||||
if (err) {
|
try {
|
||||||
res.status(501).send();
|
body = JSON.parse(body);
|
||||||
logger.log('err', err);
|
} catch (e) {
|
||||||
}
|
logger.log('error',
|
||||||
|
`${err}`);
|
||||||
if (blocks[0] && blocks[0].txs) {
|
}
|
||||||
let t = blocks[0].txs.filter(tx => tx.hash === req.params.txid);
|
res.send({
|
||||||
t = t[0];
|
txid: body.hash,
|
||||||
console.log(t);
|
version: body.version,
|
||||||
console.log(t.inputs);
|
time: body.ps,
|
||||||
console.log(t.inputs);
|
blocktime: body.ps,
|
||||||
// Map bcoin model to insight-api
|
locktime: body.locktime,
|
||||||
res.json({
|
blockhash: body.block,
|
||||||
txid: t.hash,
|
fees: body.fee,
|
||||||
version: t.version,
|
valueOut: body.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||||
locktime: t.lockTime,
|
vin: body.inputs.map(input => ({
|
||||||
vin: t.inputs.map(input => ({
|
addr: input.coin ? input.coin.address : '',
|
||||||
coinbase: input.script,
|
value: input.coin ? input.coin.value / 1e8 : 0,
|
||||||
sequence: input.sequence,
|
})),
|
||||||
n: 0,
|
vout: body.outputs.map(output => ({
|
||||||
})),
|
scriptPubKey: {
|
||||||
vout: t.outputs.map(output => ({
|
addresses: [output.address],
|
||||||
value: output.value / 1e8,
|
},
|
||||||
n: 0,
|
value: output.value / 1e8,
|
||||||
scriptPubKey: {
|
})),
|
||||||
hex: output.script,
|
isCoinbase: body.inputs[0].prevout.hash === '0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
asm: '',
|
|
||||||
addresses: [output.address],
|
|
||||||
type: null,
|
|
||||||
},
|
|
||||||
spentTxId: null,
|
|
||||||
spentIndex: null,
|
|
||||||
spentHeight: null,
|
|
||||||
})),
|
|
||||||
blockhash: t.block,
|
|
||||||
blockheight: t.height,
|
|
||||||
confirmations: 0,
|
|
||||||
time: 0,
|
|
||||||
blocktime: 0,
|
|
||||||
isCoinBase: false,
|
|
||||||
valueOut: t.outputs.reduce((a, b) => a.value + b.value).value / 1e8,
|
|
||||||
size: 0,
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.send();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
router.get('/txs', (req, res) => {
|
router.get('/txs', (req, res) => {
|
||||||
if (req.query.block) {
|
if (req.query.block) {
|
||||||
getBlock(
|
request(`http://localhost:8332/block/${req.query.block}`, (err, localRes, body) => {
|
||||||
{ hash: req.query.block },
|
if (err) {
|
||||||
{ rawBlock: 0 },
|
logger.log('error',
|
||||||
MAX_BLOCKS,
|
`${err}`);
|
||||||
(err, block) => {
|
}
|
||||||
if (err) {
|
try {
|
||||||
res.status(501).send();
|
body = JSON.parse(body);
|
||||||
logger.log('err', err);
|
} catch (e) {
|
||||||
}
|
logger.log('error',
|
||||||
if (block[0]) {
|
`${err}`);
|
||||||
const b = block[0];
|
}
|
||||||
res.json({
|
res.send({
|
||||||
pagesTotal: 1,
|
pagesTotal: 1,
|
||||||
txs: b.txs.map(tx => ({
|
txs: body.txs.map(tx => ({
|
||||||
txid: tx.hash,
|
txid: tx.hash,
|
||||||
version: tx.version,
|
fees: tx.fee,
|
||||||
locktime: tx.locktime,
|
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||||
vin: tx.inputs.map(input => ({
|
vin: tx.inputs.map(input => ({
|
||||||
coinbase: input.script,
|
addr: input.coin ? input.coin.address : '',
|
||||||
sequence: input.sequence,
|
value: input.coin ? input.coin.value / 1e8 : 0,
|
||||||
n: 0,
|
})),
|
||||||
addr: input.address,
|
vout: tx.outputs.map(output => ({
|
||||||
})),
|
scriptPubKey: {
|
||||||
vout: tx.outputs.map(output => ({
|
addresses: [output.address],
|
||||||
value: output.value / 1e8,
|
},
|
||||||
n: 0,
|
value: output.value / 1e8,
|
||||||
scriptPubKey: {
|
})),
|
||||||
hex: '',
|
output: tx.outputs,
|
||||||
asm: '',
|
})),
|
||||||
addresses: [output.address],
|
|
||||||
type: output.type,
|
|
||||||
},
|
|
||||||
spentTxid: '',
|
|
||||||
spentIndex: 0,
|
|
||||||
spentHeight: 0,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.send();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else if (req.query.address) {
|
} else if (req.query.address) {
|
||||||
getBlock(
|
request(`http://localhost:8332/tx/address/${req.query.address}`, (err, localRes, body) => {
|
||||||
{ $or:
|
if (err) {
|
||||||
[
|
logger.log('error',
|
||||||
{ 'txs.outputs.address': req.query.address },
|
`${err}`);
|
||||||
{ 'txs.inputs.prevout.hash': req.query.address },
|
}
|
||||||
],
|
try {
|
||||||
},
|
body = JSON.parse(body);
|
||||||
{ rawBlock: 0 },
|
} catch (e) {
|
||||||
MAX_BLOCKS,
|
logger.log('error',
|
||||||
(err, block) => {
|
`${err}`);
|
||||||
if (err) {
|
}
|
||||||
res.status(501).send();
|
console.log(body);
|
||||||
logger.log('err', err);
|
res.send({
|
||||||
} else if (block[0]) {
|
pagesTotal: 1,
|
||||||
const b = block[0];
|
txs: body.map(tx => ({
|
||||||
res.json({
|
txid: tx.hash,
|
||||||
pagesTotal: 1,
|
fees: tx.fee,
|
||||||
txs: b.txs.map(tx => ({
|
valueOut: tx.outputs.reduce((sum, output) => sum + output.value, 0) / 1e8,
|
||||||
txid: tx.hash,
|
vin: tx.inputs.map(input => ({
|
||||||
version: tx.version,
|
addr: input.coin ? input.coin.address : '',
|
||||||
locktime: tx.locktime,
|
value: input.coin ? input.coin.value / 1e8 : 0,
|
||||||
vin: tx.inputs.map(input => ({
|
})),
|
||||||
coinbase: input.script,
|
vout: tx.outputs.map(output => ({
|
||||||
sequence: input.sequence,
|
scriptPubKey: {
|
||||||
n: 0,
|
addresses: [output.address],
|
||||||
addr: input.address,
|
},
|
||||||
})),
|
value: output.value / 1e8,
|
||||||
vout: tx.outputs.map(output => ({
|
})),
|
||||||
value: output.value / 1e8,
|
output: tx.outputs,
|
||||||
n: 0,
|
})),
|
||||||
scriptPubKey: {
|
|
||||||
hex: '',
|
|
||||||
asm: '',
|
|
||||||
addresses: [output.address],
|
|
||||||
type: output.type,
|
|
||||||
},
|
|
||||||
spentTxid: '',
|
|
||||||
spentIndex: 0,
|
|
||||||
spentHeight: 0,
|
|
||||||
})),
|
|
||||||
})),
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
res.send();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
getTransactions(
|
getTransactions(
|
||||||
{},
|
{},
|
||||||
|
|||||||
@ -26,6 +26,9 @@ const BlockSchema = new Schema({
|
|||||||
id: false,
|
id: false,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
BlockSchema.index({ hash: 1 });
|
||||||
|
BlockSchema.index({ height: 1 });
|
||||||
|
|
||||||
const Block = mongoose.model('Block', BlockSchema);
|
const Block = mongoose.model('Block', BlockSchema);
|
||||||
|
|
||||||
module.exports = Block;
|
module.exports = Block;
|
||||||
|
|||||||
@ -22,6 +22,8 @@ const TransactionSchema = new Schema({
|
|||||||
network: String,
|
network: String,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
TransactionSchema.index({ hash: 1 });
|
||||||
|
|
||||||
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
||||||
|
|
||||||
module.exports = Transaction;
|
module.exports = Transaction;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user