Parsers moved to their own files, full node added to config.

This commit is contained in:
tenthirtyone 2017-08-05 00:41:26 -04:00
parent 434b077467
commit b13d8df2de
14 changed files with 5662 additions and 35 deletions

View File

@ -6,6 +6,7 @@
},
"rules": {
"no-multi-spaces": 0,
"no-use-before-define": 1
"no-use-before-define": 1,
"object-shorthand": 1
}
}

View File

@ -4,11 +4,10 @@ Rebuilt Bitcore with Bcoin engine and Insight API sitting on top of Mongo.
### Requirements
Mongodo running on your system.
A [PR has been submitted](https://github.com/bcoin-org/bcoin/pull/264) to Bcoin repo to fix a bug in their script library that is causing our sync process to crash when one of their checks to a tx script assesses if this is a pay to pubkey input. This is Bcoin-specific and should not affect syncing via DC Pool.
node >=7.6.0 - This requirement comes from Bcoin. Developed under 8.2.0.
### Usage
```
git clone
npm install
npm start
```
@ -40,9 +39,9 @@ The API is configured to run on port 3000 by default. Use the standard Nginx rev
1. Required Insight-UI
* /addr/:addrStr/?noTxList=1
* /block/:blockhash
* /blocks
* /block-index/:blockHeight
* X /block/:blockhash
* X /blocks
* X /block-index/:blockHeight
* /currency
* /version
* /status

View File

@ -1,4 +1,5 @@
const config = {
full_node: true,
logging: 'debug',
bcoin: {
network: 'main',

View File

@ -10,10 +10,10 @@ logger.log('debug',
db.connect(config.mongodb.uri, config.mongodb.options);
db.connection.once('open', () => {
Bcoin.start();
});
if (config.full_node) Bcoin.start();
Api.listen(config.api.port, () => {
logger.log('debug',
'listening on port 3000');
Api.listen(config.api.port, () => {
logger.log('debug',
'listening on port 3000');
});
});

View File

@ -12,7 +12,7 @@ function getBlock(params, options, cb) {
params,
defaultOptions,
cb)
.sort({ height: 1 })
.sort({ height: -1 })
.limit(MAX_BLOCKS);
}

View File

@ -1,6 +1,6 @@
const Transaction = require('../../models/transaction.js').Transaction;
var MAX_TXS = 200;
const MAX_TXS = 200;
function getTransaction(params, options, cb) {
const defaultOptions = { _id: 0 };
@ -11,13 +11,13 @@ function getTransaction(params, options, cb) {
params,
defaultOptions,
cb)
.sort({ height: -1 })
.sort({ height: 1 })
.limit(MAX_TXS);
}
module.exports = function transactionAPI(app) {
app.get('/tx/:txid', (req, res) => {
Transaction.find({"txid":req.params.txid}, (err, tx) => {
Transaction.find({ txid: req.params.txid }, (err, tx) => {
if (err) {
res.status(501).send();
}
@ -31,11 +31,10 @@ module.exports = function transactionAPI(app) {
{},
(err, txs) => {
if (err) {
res.status(501).send();
}
console.log(txs.length);
res.send(txs);
}
res.status(501).send();
}
res.send(txs);
},
);
});

View File

@ -1,6 +1,6 @@
const FullNode = require('bcoin/lib/node/fullnode');
const logger = require('../../lib/logger');
const BlockParser = require('./block');
const BlockParser = require('../parser').Block;
const config = require('../../config');
const node = new FullNode(config.bcoin);

View File

@ -7,7 +7,7 @@ function parse(entry, block) {
const blockHash = util.revHex(block.hash().toString('hex'));
const merkle = util.revHex(block.merkleRoot);
const rawBlock = block.toRaw().toString('hex');
console.log(block.toJSON().txs);
const newBlock = new BlockModel({
hash: blockHash,
size: block.size,

7
lib/parser/index.js Normal file
View File

@ -0,0 +1,7 @@
const Block = require('./block');
const Transaction = require('./transaction');
module.exports = {
Block,
Transaction,
};

View File

@ -17,6 +17,8 @@ function parse(entry, txs) {
vin: tx.inputs.map((input) => {
const inputJSON = input.toJSON();
//console.log(inputJSON);
return new InputModel({
utxo: inputJSON.prevout.hash,
vout: inputJSON.prevout.index,

View File

@ -1,4 +1,5 @@
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const BlockSchema = new Schema({
@ -25,9 +26,6 @@ const BlockSchema = new Schema({
});
BlockSchema.index({ hash: 1 }, { unique: true });
BlockSchema.index({ height: 1 });
BlockSchema.index({ time: 1 });
BlockSchema.index({ timeNormalized: 1 });
const Block = mongoose.model('Block', BlockSchema);

View File

@ -34,16 +34,6 @@ const TransactionSchema = new Schema({
});
TransactionSchema.index({ txid: 1 }, { unique: true });
TransactionSchema.index({ blockHeight: 1, wallets: 1 });
TransactionSchema.index({ blockHash: 1 });
TransactionSchema.index({ blockTime: 1 });
TransactionSchema.index({ blockTimeNormalized: 1, wallets: 1 });
TransactionSchema.index({ 'outputs.address': 1 });
TransactionSchema.index({ 'inputs.address': 1 });
TransactionSchema.index({ wallets: 1 }, { sparse: true });
TransactionSchema.index({ 'inputs.wallets': 1 }, { sparse: true });
TransactionSchema.index({ 'outputs.wallets': 1 }, { sparse: true });
const Transaction = mongoose.model('Transaction', TransactionSchema);
const Input = mongoose.model('Input', InputSchema);

View File

5630
test/test.js Normal file

File diff suppressed because it is too large Load Diff