From c2c51e709abbda72e5be09f18784321c46525a01 Mon Sep 17 00:00:00 2001 From: tenthirtyone Date: Tue, 22 Aug 2017 00:29:10 -0400 Subject: [PATCH] more cleaning up --- server/config/index.js | 2 +- server/lib/api/address.js | 5 ----- server/lib/api/status.js | 12 ++++++------ server/models/block.js | 3 ++- server/models/input.js | 2 -- server/models/output.js | 2 -- server/models/transaction.js | 4 ++++ 7 files changed, 13 insertions(+), 17 deletions(-) diff --git a/server/config/index.js b/server/config/index.js index 50638e3..011f3d8 100644 --- a/server/config/index.js +++ b/server/config/index.js @@ -28,7 +28,7 @@ const config = { ticker_url: 'https://www.bitstamp.net/api/ticker/', ticker_prop: 'bitstamp', max_blocks: 72, - max_txs: 50, + max_txs: 10, max_page_txs: 10, request_ttl: 100000, }, diff --git a/server/lib/api/address.js b/server/lib/api/address.js index dfec674..cc9c077 100644 --- a/server/lib/api/address.js +++ b/server/lib/api/address.js @@ -1,12 +1,7 @@ const logger = require('../logger'); -const request = require('request'); -const config = require('../../config'); const util = require('../util'); const db = require('../db'); -const API_URL = `http://${config.bcoin_http}:${config.bcoin['http-port']}`; -const TTL = config.api.request_ttl; - module.exports = function AddressAPI(router) { router.get('/addr/:addr', (req, res) => { const addr = req.params.addr || ''; diff --git a/server/lib/api/status.js b/server/lib/api/status.js index 725eca1..bc0cfa3 100644 --- a/server/lib/api/status.js +++ b/server/lib/api/status.js @@ -97,12 +97,12 @@ module.exports = function statusAPI(router) { }); // Copied from previous source router.get('/peer', (req, res) => res.json({ - connected: true, - host: '127.0.0.1', - port: null, - })); + connected: true, + host: '127.0.0.1', + port: null, + })); router.get('/version', (req, res) => res.json({ - version: pkg.version, - })); + version: pkg.version, + })); }; diff --git a/server/models/block.js b/server/models/block.js index 22ef2c3..9c18bc7 100644 --- a/server/models/block.js +++ b/server/models/block.js @@ -2,7 +2,8 @@ const mongoose = require('mongoose'); const config = require('../config'); const Schema = mongoose.Schema; -const MAX_BLOCKS = config.api.max_blocks; // ~ 12 hours +// These limits can be overriden higher up the stack +const MAX_BLOCKS = config.api.max_blocks; const BlockSchema = new Schema({ hash: { type: String, default: '' }, diff --git a/server/models/input.js b/server/models/input.js index dc29b43..77f115c 100644 --- a/server/models/input.js +++ b/server/models/input.js @@ -11,8 +11,6 @@ const InputSchema = new Schema({ address: { type: String, default: '' }, }); -InputSchema.index({ address: 1 }); - const Input = mongoose.model('Input', InputSchema); module.exports = Input; diff --git a/server/models/output.js b/server/models/output.js index 56694eb..65f2194 100644 --- a/server/models/output.js +++ b/server/models/output.js @@ -9,8 +9,6 @@ const OutputSchema = new Schema({ type: { type: String, default: '' }, }); -OutputSchema.index({ address: 1 }); - const Output = mongoose.model('Output', OutputSchema); module.exports = Output; diff --git a/server/models/transaction.js b/server/models/transaction.js index e199330..2b2358a 100644 --- a/server/models/transaction.js +++ b/server/models/transaction.js @@ -5,6 +5,7 @@ const logger = require('../lib/logger'); const config = require('../config'); const Schema = mongoose.Schema; +// These limits can be overriden higher up the stack const MAX_TXS = config.api.max_txs; const MAX_PAGE_TXS = config.api.max_page_txs; @@ -27,6 +28,9 @@ const TransactionSchema = new Schema({ }); TransactionSchema.index({ hash: 1 }); +TransactionSchema.index({ 'outputs.address': 1 }); +TransactionSchema.index({ 'inputs.address': 1 }); + TransactionSchema.methods.byId = function txById(txid, cb) { return this.model('Transaction').findOne(