Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Commit

Permalink
Merge pull request #13 from mayankchhabra/master
Browse files Browse the repository at this point in the history
v0.0.5
  • Loading branch information
mayankchhabra committed May 5, 2020
2 parents 3e2b39d + 702ec94 commit df3385b
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 28 deletions.
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ test/
.eslintignore
coverage
.nyc_output
Makefile
Makefile
*.env
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ logs/
package-lock.json
*.bak
lb_settings.json
.env
.nyc_output
coverage
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
volumes:
- "/home/umbrel/lnd:/lnd"
environment:
BITCOIN_NETWORK: "mainnet"
BITCOIN_HOST: "0.0.0.0"
RPC_PORT: "8332"
RPC_USER: "<your rpc username>"
RPC_PASSWORD: "<your rpc password>"
LND_NETWORK: "mainnet"
Expand Down
4 changes: 3 additions & 1 deletion app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require('module-alias/register');
require('module-alias').addPath('.');
require('dotenv').config();

const express = require('express');
const path = require('path');
const morgan = require('morgan');
Expand Down Expand Up @@ -36,7 +38,7 @@ app.use(onionOriginMiddleware);
app.use(cors(corsOptions));

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: true}));
app.use(bodyParser.urlencoded({ extended: true }));
app.use(express.static(path.join(__dirname, 'public')));
app.use(passport.initialize());
app.use(passport.session());
Expand Down
25 changes: 13 additions & 12 deletions logic/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const BitcoindError = require('models/errors.js').BitcoindError;
async function getBlockCount() {
const blockCount = await bitcoindService.getBlockCount();

return {blockCount: blockCount.result};
return { blockCount: blockCount.result };
}

async function getConnectionsCount() {
Expand All @@ -13,7 +13,7 @@ async function getConnectionsCount() {
var outBoundConnections = 0;
var inBoundConnections = 0;

peerInfo.result.forEach(function(peer) {
peerInfo.result.forEach(function (peer) {
if (peer.inbound === false) {
outBoundConnections++;

Expand All @@ -35,10 +35,10 @@ async function getStatus() {
try {
await bitcoindService.help();

return {operational: true};
return { operational: true };
} catch (error) {
if (error instanceof BitcoindError) {
return {operational: false};
return { operational: false };
}

throw error;
Expand All @@ -53,7 +53,7 @@ async function getMaxSyncHeader() {
return -1;
}

const maxPeer = peerInfo.reduce(function(prev, current) {
const maxPeer = peerInfo.reduce(function (prev, current) {
return prev.syncedHeaders > current.syncedHeaders ? prev : current;
});

Expand All @@ -68,13 +68,14 @@ async function getLocalSyncInfo() {
const info = await bitcoindService.getBlockChainInfo();

var blockChainInfo = info.result;

var chain = blockChainInfo.chain;
var blockCount = blockChainInfo.blocks;
var headerCount = blockChainInfo.headers;

const percentSynced = (Math.trunc(blockCount / headerCount * 10000) / 10000).toFixed(4); // eslint-disable-line no-magic-numbers, max-len

return {
chain: chain,
percent: percentSynced,
currentBlock: blockCount,
headerCount: headerCount // eslint-disable-line object-shorthand,
Expand All @@ -99,7 +100,7 @@ async function getVersion() {
// Remove all non-digits or decimals.
const version = unformattedVersion.replace(/[^\d.]/g, '');

return {version: version}; // eslint-disable-line object-shorthand
return { version: version }; // eslint-disable-line object-shorthand
}

async function getBlock(hash) {
Expand Down Expand Up @@ -165,11 +166,11 @@ async function nodeStatusSummary() {
const miningInfo = await bitcoindService.getMiningInfo();

return {
difficulty: blockchainInfo.result.difficulty,
size: blockchainInfo.result.sizeOnDisk,
mempool: mempoolInfo.result.bytes,
connections: networkInfo.result.connections,
networkhashps: miningInfo.result.networkhashps
difficulty: blockchainInfo.result.difficulty,
size: blockchainInfo.result.sizeOnDisk,
mempool: mempoolInfo.result.bytes,
connections: networkInfo.result.connections,
networkhashps: miningInfo.result.networkhashps
}
}

Expand Down
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "umbrel-middleware",
"version": "0.0.4",
"version": "0.0.5",
"description": "Middleware for Umbrel Node",
"author": "Umbrel",
"scripts": {
Expand All @@ -18,6 +18,7 @@
"continuation-local-storage": "^3.2.1",
"cors": "^2.8.5",
"debug": "^2.6.1",
"dotenv": "^8.2.0",
"express": "^4.16.3",
"grpc": "^1.8.0",
"module-alias": "^2.1.0",
Expand Down Expand Up @@ -54,4 +55,4 @@
],
"cache": "false"
}
}
}
16 changes: 8 additions & 8 deletions routes/v1/bitcoind/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ router.get('/stats', auth.jwt, safeHandler((req, res) =>
));

router.get('/block', auth.jwt, safeHandler((req, res) => {
if (req.query.hash !== undefined && req.query.hash !== null) {
bitcoind.getBlock(req.query.hash)
.then(blockhash => res.json(blockhash))
} else if (req.query.height !== undefined && req.query.height !== null) {
bitcoind.getBlockHash(req.query.height)
.then(blockhash => res.json(blockhash))
}
if (req.query.hash !== undefined && req.query.hash !== null) {
bitcoind.getBlock(req.query.hash)
.then(blockhash => res.json(blockhash))
} else if (req.query.height !== undefined && req.query.height !== null) {
bitcoind.getBlockHash(req.query.height)
.then(blockhash => res.json(blockhash))
}
}
));

// /v1/bitcoind/info/block/<hash>
Expand All @@ -67,7 +67,7 @@ router.get('/block/:id', auth.jwt, safeHandler((req, res) =>
.then(blockhash => res.json(blockhash))
));

router.get('/txid/:id', auth.jwt, safeHandler((req,res) =>
router.get('/txid/:id', auth.jwt, safeHandler((req, res) =>
bitcoind.getTransaction(req.params.id)
.then(txhash => res.json(txhash))
));
Expand Down
4 changes: 2 additions & 2 deletions services/bitcoind.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const camelizeKeys = require('camelize-keys');

const BitcoindError = require('models/errors.js').BitcoindError;

const BITCOIND_RPC_PORT = process.env.BITCOIN_NETWORK === 'testnet' ? 18332 : 8332; // eslint-disable-line no-magic-numbers, max-len
const BITCOIND_RPC_PORT = process.env.RPC_PORT || 8332; // eslint-disable-line no-magic-numbers, max-len
const BITCOIND_HOST = process.env.BITCOIN_HOST || '127.0.0.1';
const BITCOIND_RPC_USER = process.env.RPC_USER;
const BITCOIND_RPC_PASSWORD = process.env.RPC_PASSWORD;
Expand Down Expand Up @@ -97,7 +97,7 @@ function getNetworkInfo() {
}

function getMiningInfo() {
return promiseify(rpcClient, rpcClient.getMiningInfo, 'mining info');
return promiseify(rpcClient, rpcClient.getMiningInfo, 'mining info');
}
function help() {
// TODO: missing from the library, but can add it not sure how to package.
Expand Down

0 comments on commit df3385b

Please sign in to comment.