Skip to content

Commit f0493d5

Browse files
authored
Umbrel support (#141)
* Don't require BTC core connection * Docker: Don't clone, but use local repo * Add GitHub workflows * Allow to overwrite hostname * chore: update dependencies * Get tor URL from env
1 parent 76b289b commit f0493d5

13 files changed

Lines changed: 8347 additions & 979 deletions

File tree

.eslintrc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"plugins": [
44
"prettier"
55
],
6-
"extends": ["prettier"],
6+
"extends": ["plugin:prettier/recommended"],
77
"rules": {
88
"prettier/prettier": [
99
"warn",

.github/workflows/push.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Build on push
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
8+
env:
9+
DOCKER_CLI_EXPERIMENTAL: enabled
10+
11+
jobs:
12+
build:
13+
name: Build image
14+
runs-on: ubuntu-20.04
15+
strategy:
16+
fail-fast: false
17+
matrix:
18+
platform:
19+
- linux/amd64
20+
- linux/arm64
21+
steps:
22+
- name: Checkout project
23+
uses: actions/checkout@v2
24+
25+
26+
- name: Set env variables
27+
run: echo "BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed 's/\//-/g')" >> $GITHUB_ENV
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v1
31+
with:
32+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
33+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v1
37+
id: qemu
38+
39+
- name: Setup Docker buildx action
40+
uses: docker/setup-buildx-action@v1
41+
id: buildx
42+
43+
- name: Show available Docker buildx platforms
44+
run: echo ${{ steps.buildx.outputs.platforms }}
45+
46+
47+
- name: Run Docker buildx
48+
run: |
49+
docker buildx build \
50+
--cache-from "type=local,src=/tmp/.buildx-cache" \
51+
--cache-to "type=local,dest=/tmp/.buildx-cache" \
52+
--platform ${{matrix.platform}} \
53+
--tag ${{ secrets.DOCKER_CONTAINER_USERNAME }}/lndhub:$BRANCH \
54+
--output "type=registry" ./

.github/workflows/tag.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
name: Build on push
2+
3+
on:
4+
push:
5+
tags:
6+
- v[0-9]+.[0-9]+.[0-9]+
7+
- v[0-9]+.[0-9]+.[0-9]+-*
8+
9+
env:
10+
DOCKER_CLI_EXPERIMENTAL: enabled
11+
12+
jobs:
13+
build:
14+
name: Build image
15+
runs-on: ubuntu-20.04
16+
strategy:
17+
fail-fast: false
18+
matrix:
19+
platform:
20+
- linux/amd64
21+
- linux/arm64
22+
steps:
23+
- name: Checkout project
24+
uses: actions/checkout@v2
25+
26+
- name: Set env variables
27+
run: echo "TAG=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
28+
29+
- name: Login to Docker Hub
30+
uses: docker/login-action@v1
31+
with:
32+
username: ${{ secrets.DOCKER_HUB_USERNAME }}
33+
password: ${{ secrets.DOCKER_HUB_ACCESS_TOKEN }}
34+
35+
- name: Set up QEMU
36+
uses: docker/setup-qemu-action@v1
37+
id: qemu
38+
39+
- name: Setup Docker buildx action
40+
uses: docker/setup-buildx-action@v1
41+
id: buildx
42+
43+
- name: Show available Docker buildx platforms
44+
run: echo ${{ steps.buildx.outputs.platforms }}
45+
46+
47+
- name: Run Docker buildx
48+
run: |
49+
docker buildx build \
50+
--cache-from "type=local,src=/tmp/.buildx-cache" \
51+
--cache-to "type=local,dest=/tmp/.buildx-cache" \
52+
--platform ${{matrix.platform}} \
53+
--tag ${{ secrets.DOCKER_CONTAINER_USERNAME }}/lndhub:$TAG \
54+
--output "type=registry" ./
55+
- name: Run Docker buildx
56+
run: |
57+
docker buildx build \
58+
--cache-from "type=local,src=/tmp/.buildx-cache" \
59+
--cache-to "type=local,dest=/tmp/.buildx-cache" \
60+
--platform ${{matrix.platform}} \
61+
--tag ${{ secrets.DOCKER_CONTAINER_USERNAME }}/lndhub:latest \
62+
--output "type=registry" ./

Dockerfile

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,35 @@ RUN adduser --disabled-password \
66
--gecos "" \
77
"lndhub"
88

9-
FROM node:buster-slim AS builder
9+
FROM node:12-buster-slim AS builder
1010

1111
# These packages are required for building LNDHub
12-
RUN apt-get update && apt-get -y install git python3
13-
14-
# TODO: Switch to official images once my PR is merged
15-
RUN git clone https://github.com/AaronDewes/LndHub.git -b update-dependencies /lndhub
12+
RUN apt-get update && apt-get -y install python3
1613

1714
WORKDIR /lndhub
1815

16+
# Copy 'package-lock.json' and 'package.json'
17+
COPY package.json package-lock.json ./
18+
19+
# Install dependencies
1920
RUN npm i
2021

21-
FROM node:buster-slim
22+
# Copy project files and folders to the current working directory
23+
COPY . .
24+
25+
# Delete git data as it's not needed inside the container
26+
RUN rm -rf .git
27+
28+
FROM node:12-buster-slim
2229

2330
# Create a specific user so LNDHub doesn't run as root
2431
COPY --from=perms /etc/group /etc/passwd /etc/shadow /etc/
2532

2633
# Copy LNDHub with installed modules from builder
2734
COPY --from=builder /lndhub /lndhub
2835

29-
# Delete git data as it's not needed inside the container
30-
RUN rm -rf .git
31-
3236
# Create logs folder and ensure permissions are set correctly
3337
RUN mkdir /lndhub/logs && chown -R lndhub:lndhub /lndhub
34-
3538
USER lndhub
3639

3740
ENV PORT=3000

bitcoin.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
const config = require('./config');
33
let jayson = require('jayson/promise');
44
let url = require('url');
5-
let rpc = url.parse(config.bitcoind.rpc);
6-
rpc.timeout = 15000;
7-
module.exports = jayson.client.http(rpc);
5+
if (config.bitcoind) {
6+
let rpc = url.parse(config.bitcoind.rpc);
7+
rpc.timeout = 15000;
8+
module.exports = jayson.client.http(rpc);
9+
} else {
10+
module.exports = {};
11+
}

btc-decoder.js

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
const bitcoin = require('bitcoinjs-lib');
2+
const classify = require('bitcoinjs-lib/src/classify');
3+
4+
const decodeFormat = (tx) => ({
5+
txid: tx.getId(),
6+
version: tx.version,
7+
locktime: tx.locktime,
8+
});
9+
10+
const decodeInput = function (tx) {
11+
const result = [];
12+
tx.ins.forEach(function (input, n) {
13+
result.push({
14+
txid: input.hash.reverse().toString('hex'),
15+
n: input.index,
16+
script: bitcoin.script.toASM(input.script),
17+
sequence: input.sequence,
18+
});
19+
});
20+
return result;
21+
};
22+
23+
const decodeOutput = function (tx, network) {
24+
const format = function (out, n, network) {
25+
const vout = {
26+
satoshi: out.value,
27+
value: (1e-8 * out.value).toFixed(8),
28+
n: n,
29+
scriptPubKey: {
30+
asm: bitcoin.script.toASM(out.script),
31+
hex: out.script.toString('hex'),
32+
type: classify.output(out.script),
33+
addresses: [],
34+
},
35+
};
36+
switch (vout.scriptPubKey.type) {
37+
case 'pubkeyhash':
38+
case 'scripthash':
39+
vout.scriptPubKey.addresses.push(bitcoin.address.fromOutputScript(out.script, network));
40+
break;
41+
case 'witnesspubkeyhash':
42+
case 'witnessscripthash':
43+
const data = bitcoin.script.decompile(out.script)[1];
44+
vout.scriptPubKey.addresses.push(bitcoin.address.toBech32(data, 0, network.bech32));
45+
break;
46+
}
47+
return vout;
48+
};
49+
50+
const result = [];
51+
tx.outs.forEach(function (out, n) {
52+
result.push(format(out, n, network));
53+
});
54+
return result;
55+
};
56+
57+
class TxDecoder {
58+
constructor(rawTx, network = bitcoin.networks.bitcoin) {
59+
this.tx = bitcoin.Transaction.fromHex(rawTx);
60+
this.format = decodeFormat(this.tx);
61+
this.inputs = decodeInput(this.tx);
62+
this.outputs = decodeOutput(this.tx, network);
63+
}
64+
65+
decode() {
66+
const result = {};
67+
const self = this;
68+
Object.keys(self.format).forEach(function (key) {
69+
result[key] = self.format[key];
70+
});
71+
result.outputs = self.outputs;
72+
result.inputs = self.inputs;
73+
return result;
74+
}
75+
}
76+
77+
module.exports.decodeRawHex = (rawTx, network = bitcoin.networks.bitcoin) => {
78+
return new TxDecoder(rawTx, network).decode();
79+
};

0 commit comments

Comments
 (0)