Skip to content

Commit

Permalink
Updated design (#2)
Browse files Browse the repository at this point in the history
Updates the UI
  • Loading branch information
KayBeSee authored Mar 11, 2022
1 parent 8aa53fb commit cd1d3f8
Show file tree
Hide file tree
Showing 81 changed files with 37,083 additions and 123,925 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
node_modules
node_modules
dist
data
13 changes: 13 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=827846 to learn about workspace recommendations.
// Extension identifier format: ${publisher}.${name}. Example: vscode.csharp

// List of extensions which should be recommended for users of this workspace.
"recommendations": [

],
// List of extensions recommended by VS Code that should not be recommended for users of this workspace.
"unwantedRecommendations": [

]
}
10 changes: 5 additions & 5 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ FROM node:16-buster-slim AS umbrel-electrs-builder
# Create app directory
WORKDIR /app

# Copy 'yarn.lock' and 'package.json'
COPY yarn.lock package.json ./
# Copy 'package-lock.json' and 'package.json'
COPY package-lock.json package.json ./
COPY apps ./apps

# Install dependencies
RUN yarn install --production
RUN npm install

# Copy project files and folders to the current working directory (i.e. '/app')
# COPY . .
COPY . .

# RUN npm run build:frontend
RUN npm run build:frontend

# Final image
FROM node:16-buster-slim AS umbrel-electrs
Expand Down
2 changes: 2 additions & 0 deletions apps/backend/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const errorHandleMiddleware = require("middlewares/errorHandling.js");
const logger = require("utils/logger.js");

const ping = require("routes/ping.js");
const electrs = require("routes/v1/electrs.js");
const app = express();

// Handles CORS
Expand All @@ -33,6 +34,7 @@ app.use(morgan(logger.morganConfiguration));
app.use("/", express.static("../frontend/dist"));

app.use("/ping", ping);
app.use("/v1/electrs", electrs);

app.use(errorHandleMiddleware);
app.use((req, res) => {
Expand Down
34 changes: 34 additions & 0 deletions apps/backend/logic/system.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const constants = require("utils/const.js");
const NodeError = require("models/errors.js").NodeError;

async function getElectrumConnectionDetails() {
try {
const port = constants.ELECTRUM_PORT;

const torAddress = constants.ELECTRUM_HIDDEN_SERVICE;
const torConnectionString = `${torAddress}:${port}:t`;

const localAddress = constants.ELECTRUM_LOCAL_SERVICE;
const localConnectionString = `${torAddress}:${port}:t`;

return {
tor: {
address: torAddress,
port,
connectionString: torConnectionString,
},
local: {
address: localAddress,
port,
connectionString: localConnectionString,
},
};
} catch (error) {
console.log("error: ", error);
throw new NodeError("Unable to get Electrum hidden service url");
}
}

module.exports = {
getElectrumConnectionDetails,
};

This file was deleted.

This file was deleted.

2,960 changes: 0 additions & 2,960 deletions apps/backend/logs/api-2022-02-16.log

This file was deleted.

Empty file.
32 changes: 32 additions & 0 deletions apps/backend/models/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/* eslint-disable no-magic-numbers */
function NodeError(message, statusCode) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.statusCode = statusCode;
}
require('util').inherits(NodeError, Error);

function BitcoindError(message, error, statusCode) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.error = error;
this.statusCode = statusCode;
}
require('util').inherits(BitcoindError, Error);

function ValidationError(message, statusCode) {
Error.captureStackTrace(this, this.constructor);
this.name = this.constructor.name;
this.message = message;
this.statusCode = statusCode || 400;
}
require('util').inherits(ValidationError, Error);

module.exports = {
NodeError,
BitcoindError,
ValidationError
};

6 changes: 2 additions & 4 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@
"postcoverage": "codecov"
},
"dependencies": {
"axios": "^0.19.2",
"big.js": "^5.2.2",
"bitcoind-rpc": "^0.7.2",
"@lily-technologies/electrum-client": "^1.1.8",
"bitcoind-rpc": "^0.9.1",
"body-parser": "^1.18.2",
"camelize-keys": "^1.0.0",
"continuation-local-storage": "^3.2.1",
Expand All @@ -23,7 +22,6 @@
"express": "^4.16.3",
"module-alias": "^2.1.0",
"morgan": "^1.9.0",
"request-promise": "^4.2.2",
"uuid": "^3.3.2",
"winston": "^3.0.0-rc5",
"winston-daily-rotate-file": "^3.1.3"
Expand Down
43 changes: 43 additions & 0 deletions apps/backend/routes/v1/electrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const express = require("express");
const router = express.Router();
const electrsService = require("services/electrs");

const systemLogic = require("logic/system.js");
const safeHandler = require("utils/safeHandler");

router.get(
"/electrum-connection-details",
safeHandler(async (req, res) => {
const connectionDetails = await systemLogic.getElectrumConnectionDetails();
return res.status(200).json(connectionDetails);
})
);

router.get(
"/version",
safeHandler(async (req, res) => {
try {
const version = await electrsService.getVersion();
return res.status(200).json(version);
} catch (e) {
console.error("version error: ", e);
return res.status(500).json(e);
}
})
);

router.get(
"/syncPercent",
safeHandler(async (req, res) => {
try {
const syncPercent = await electrsService.syncPercent();

return res.status(200).json(syncPercent);
} catch (e) {
console.error("syncPercent error: ", e);
return res.status(500).json(e);
}
})
);

module.exports = router;
42 changes: 42 additions & 0 deletions apps/backend/services/bitcoind.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const camelizeKeys = require("camelize-keys");
const RpcClient = require("bitcoind-rpc");

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

const BITCOIND_RPC_PORT = process.env.RPC_PORT || 18443; // eslint-disable-line no-magic-numbers, max-len
const BITCOIND_HOST = process.env.BITCOIN_HOST || "172.28.0.2";
const BITCOIND_RPC_USER = process.env.RPC_USER || "umbrel";
const BITCOIND_RPC_PASSWORD =
process.env.RPC_PASSWORD || "7-9j7pEXcV2s4cM_3JKfk-30eEmei94PRmUaDpHId-s=";

const rpcClient = new RpcClient({
protocol: "http",
user: BITCOIND_RPC_USER, // eslint-disable-line object-shorthand
pass: BITCOIND_RPC_PASSWORD, // eslint-disable-line object-shorthand
host: BITCOIND_HOST,
port: BITCOIND_RPC_PORT
});

function promiseify(rpcObj, rpcFn, what) {
return new Promise((resolve, reject) => {
try {
rpcFn.call(rpcObj, (err, info) => {
if (err) {
reject(new BitcoindError(`Unable to obtain ${what}`, err));
} else {
resolve(camelizeKeys(info, "_"));
}
});
} catch (error) {
reject(error);
}
});
}

function getBlockChainInfo() {
return promiseify(rpcClient, rpcClient.getBlockchainInfo, "blockchain info");
}

module.exports = {
getBlockChainInfo
};
46 changes: 46 additions & 0 deletions apps/backend/services/electrs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const ElectrumClient = require("@lily-technologies/electrum-client");
const bitcoindService = require("services/bitcoind");

const ELECTRS_HOST = process.env.ELECTRS_HOST || "0.0.0.0";
const rpcClient = new ElectrumClient(50001, ELECTRS_HOST, "tcp");

async function getVersion() {
const initClient = await rpcClient.initElectrum({
client: "umbrel",
version: "1.4"
});

// versionInfo[0] comes in as electrs/0.9.4, so we parse
const version = initClient.versionInfo[0].substring(
initClient.versionInfo[0].indexOf("/") + 1
);
return version;
}

// This is a little hacky way of determining if electrs is sync'd to bitcoind
// see https://github.com/romanz/electrs/pull/543#issuecomment-973078262
async function syncPercent() {
// first, check if bitcoind isn't still IBD
const {
result: bitcoindResponse
} = await bitcoindService.getBlockChainInfo();
if (bitcoindResponse.initialblockdownload) {
return 0;
}

// if not IBD, then check bitcoind height to electrs height
const initClient = await rpcClient.initElectrum({
client: "umbrel",
version: "1.4"
});

const {
height: electrsHeight
} = await initClient.blockchainHeaders_subscribe();
return (electrsHeight / bitcoindResponse.blocks) * 100;
}

module.exports = {
getVersion,
syncPercent
};
18 changes: 9 additions & 9 deletions apps/backend/utils/const.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/* eslint-disable id-length */
module.exports = {
REQUEST_CORRELATION_NAMESPACE_KEY: 'umbrel-manager-request',
REQUEST_CORRELATION_ID_KEY: 'reqId',
DEVICE_HOSTNAME: process.env.DEVICE_HOSTNAME || 'umbrel.local',
BITCOIN_P2P_HIDDEN_SERVICE: process.env.BITCOIN_P2P_HIDDEN_SERVICE,
BITCOIN_P2P_PORT: process.env.BITCOIN_P2P_PORT || 8333,
BITCOIN_RPC_HIDDEN_SERVICE: process.env.BITCOIN_RPC_HIDDEN_SERVICE,
BITCOIN_RPC_PORT: process.env.BITCOIN_RPC_PORT || 8332,
BITCOIN_RPC_USER: process.env.BITCOIN_RPC_USER || 'umbrel',
BITCOIN_RPC_PASSWORD: process.env.BITCOIN_RPC_PASSWORD || 'moneyprintergobrrr',
REQUEST_CORRELATION_NAMESPACE_KEY: "umbrel-electrs-request",
REQUEST_CORRELATION_ID_KEY: "reqId",

ELECTRUM_HIDDEN_SERVICE:
process.env.ELECTRUM_HIDDEN_SERVICE || "/var/lib/tor/electrum/hostname",

ELECTRUM_LOCAL_SERVICE: process.env.ELECTRUM_LOCAL_SERVICE || "umbrel.local",

ELECTRUM_PORT: process.env.ELECTRUM_PORT || 50001,
};
7 changes: 0 additions & 7 deletions apps/frontend/dist/css/app.eac9b516.css

This file was deleted.

Binary file removed apps/frontend/dist/favicon.ico
Binary file not shown.
Binary file removed apps/frontend/dist/favicon.png
Binary file not shown.
28 changes: 0 additions & 28 deletions apps/frontend/dist/img/icon-app-electrs.231ead36.svg

This file was deleted.

7 changes: 0 additions & 7 deletions apps/frontend/dist/img/icon-block.27166e23.svg

This file was deleted.

5 changes: 0 additions & 5 deletions apps/frontend/dist/img/logo.5a50986c.svg

This file was deleted.

Loading

0 comments on commit cd1d3f8

Please sign in to comment.