Browse Source

Added UI, cleaned up

master
reid 3 years ago
parent
commit
f511442b65
  1. 47
      Dockerfile
  2. 4
      bin/append-to-hosts.sh
  3. 16
      docker-compose.yaml
  4. 132
      index/index.html
  5. 18
      nginx.conf
  6. 4
      rpc/mainnet-start.sh
  7. 10
      rpc/server.js

47
Dockerfile

@ -1,44 +1,17 @@
# NodeJS Builder container FROM debian:buster-slim
FROM buildpack-deps:bullseye-curl as nodejs-builder
RUN apt-get update && \
apt-get install -y xz-utils python && \
rm -rf /var/lib/apt/lists/*
RUN curl https://nodejs.org/dist/v14.18.1/node-v14.18.1-linux-arm64.tar.xz --output node-v14.18.1-linux-arm64.tar.xz
RUN tar xvf node-v14.18.1-linux-arm64.tar.xz
# urbit-bitcoin-rpc Builder container
FROM buildpack-deps:bullseye as urbit-rpc-builder
ADD https://api.github.com/repos/urbit/urbit-bitcoin-rpc/git/refs/heads/master version.json
RUN git clone -b master https://github.com/urbit/urbit-bitcoin-rpc.git urbit-bitcoin-rpc
# urbit-bitcoin-node container
FROM debian:bullseye-slim
# These buildargs can be set during container build time with --build-arg UID=[uid]
ARG UID=1000 ARG UID=1000
ARG GID=1000 ARG GID=1000
ARG USERNAME=user ARG username=umbrel
RUN apt-get update && apt-get install -y curl
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash
RUN apt-get update && apt-get --no-install-recommends intall -y curl wget vim gnupg procps nginx apt-utils sudo nodejs git sudo
RUN apt-get update && \ ADD https://api.github.com/repos/urbit/urbit-bitcoin-rpc/git/refs/heads/master version.json
apt-get install -y iproute2 sudo && \ RUN git clone -b master https://github.com/urbit/urbit-bitcoin-rpc.git urbit-bitcoin-rpc
rm -rf /var/lib/apt/lists/*
# Allow the new user write access to /etc/hosts
RUN groupadd -g $GID -o $USERNAME && \
useradd -m -u $UID -g $GID -o -d /home/$USERNAME -s /bin/bash $USERNAME && \
echo "$USERNAME ALL=(ALL:ALL) NOPASSWD: /usr/bin/append-to-hosts" | tee -a /etc/sudoers
# Copy files from the builder containers
COPY --from=nodejs-builder /node-v14.18.1-linux-arm64/ /usr/local/
COPY --from=urbit-rpc-builder /urbit-bitcoin-rpc/* /
COPY --from=urbit-rpc-builder /urbit-bitcoin-rpc/src /src
# Overwrite two files in the dist with our local slightly modified versions
ADD /rpc/mainnet-start.sh /mainnet-start.sh ADD /rpc/mainnet-start.sh /mainnet-start.sh
ADD /rpc/server.js /src/server.js ADD /rpc/server.js /src/server.js
ADD nginx.conf /etc/nginx/conf.d/nginx.conf
RUN npm install express RUN npm install express
RUN npm audit fix RUN npm audit fix
@ -48,7 +21,3 @@ USER $USERNAME
EXPOSE 50002 EXPOSE 50002
ENTRYPOINT ["/mainnet-start.sh"] ENTRYPOINT ["/mainnet-start.sh"]

4
bin/append-to-hosts.sh

@ -1,4 +0,0 @@
#!/usr/bin/env bash
# edit hosts as non-root
echo "$@" >> /etc/hosts

16
docker-compose.yaml

@ -6,12 +6,12 @@ services:
restart: on-failure restart: on-failure
stop_grace_period: 1m stop_grace_period: 1m
ports: ports:
- 50002:50002 - 55555:50002
environment: environment:
$ELECTRUM_IP: $ELECTRUM_IP ELECTRUM_IP: $ELECTRUM_IP
$ELECTRUM_PORT: $ELECTRUM_PORT ELECTRUM_PORT: $ELECTRUM_PORT
$BITCOIN_IP: $BITCOIN_IP BITCOIN_IP: $BITCOIN_IP
$BITCOIN_RPC_PORT: $BITCOIN_RPC_PORT BITCOIN_RPC_PORT: $BITCOIN_RPC_PORT
$BITCOIN_RPC_USER: $BITCOIN_RPC_USER BITCOIN_RPC_USER: $BITCOIN_RPC_USER
$BITCOIN_RPC_PASS: $BITCOIN_RPC_PASS BITCOIN_RPC_PASS: $BITCOIN_RPC_PASS
$BITCOIN_RPC_AUTH: $BITCOIN_RPC_AUTH BITCOIN_RPC_AUTH: $BITCOIN_RPC_AUTH

132
index/index.html

@ -0,0 +1,132 @@
<!doctype html>
<head>
<title>Urbit Bitcoin Connector</title>
<style>
body {
font-family: monospace;
max-width: 40em;
}
.box {
border: 1px solid black;
margin: 1em;
padding: 1em;
}
.indent {
margin-left: 1em;
}
.list {
list-style-type: none;
}
.bold {
font-weight: bold;
}
.wrap: {
overflow: hidden;
position: relative;
}
.bg-img {
background-image:url('/logo.png');
background-size: contain;
align: left;
background-repeat:no-repeat;
}
.title {
border: 2px solid black;
margin: 1em;
padding: 1em;
text-align: center;
}
h1 {
color: #ffffff;
text-shadow: 1px 0 0 #000, 0 -1px 0 #000, 0 1px 0 #000, -1px 0 0 #000;
}
#submit {
background-color: #fff;
-moz-border-radius: 2px;
-webkit-border-radius: 2px;
border-style: outset;
border-radius: 2px solid #000;
border-color: #000;
color: #000;
font-family: monospace;
font-size: 14px;
text-decoration: underline;
cursor: pointer;
border:none;
}
pre code {
display: block;
background: #D3D3D3;
white-space: pre;
-webkit-overflow-scrolling: touch;
overflow-x: auto;
max-width: 100%;
min-width: 100px;
padding: 0;
}
</style>
</head>
<body>
<div class="wrap">
<div class="bg-img">
<div class="title">
<h1>Urbit Bitcoin Connector</h1>
</div></div></div>
<div>
<div class="box">
<p><b>This app will allow you to connect your Urbit's Bitcoin wallet to your Umbrel.</b></p>
<p>Urbit's Bitcoin wallet talks to the blockchain like this:</p>
<p><pre><code>[%btc-wallet] <--> [%btc-provider] <--> [Full node]</code></pre></p>
<p>You need to connect %btc-wallet to a configured provider before you can use it. %btc-wallet and %btc-provider may or may not be on the same ship.</p>
</div></div>
<div><div class="box">
<p><b>Connecting your ship</b></p>
<p>First configure your provider:</p>
<p><ul>
<li>Open the dojo on your ship ('Terminal')</li>
<li>Enter the following commands:</li>
</ul>
<pre><code>dojo> |rein %bitcoin [& %btc-provider]
dojo> =network %main
dojo> :btc-provider +bitcoin!btc-provider/command [%set-credentials api-url='http://127.0.0.1:55555' network]</code></pre>
You should see a new block announcement in the dojo. (If your ship is on another host, change the IP address.)</p>
<p><ul><li>Next, go to your Bitcoin wallet in your Urbit's web UI.</li>
<li>Configure your provider by entering the @p (ship name) of the provider you just configured.</li>
<li>Enter your xPub from <a href="https://bridge.urbit.org">Bridge</a> or an <a href="https://blog.blockonomics.co/how-to-find-your-xpub-key-with-these-8-popular-bitcoin-wallets-ce8ea665ffdc">external wallet</a>.
</div></div>
<div><div class="box">
<p><b>Whitelisting clients</b></p>
<p>By default, only your provider's @p will be whitelisted for use. You can whitelist any other ship or groups of ships using the following commands.</p>
<pre><code>:: Individual ships ::
dojo> :btc-provider +bitcoin!btc-provider/command [%add-whitelist [%users users=(sy ~[~wallet-hodler])]]
:: Group members (provider ship must be a member) ::
dojo> :btc-provider +bitcoin!btc-provider/command [%add-whitelist [%groups groups=(sy ~[[~sampel %group-name]])]]
:: %kids ::
dojo> :btc-provider +bitcoin!btc-provider/command [%add-whitelist %kids ~]
:: Public whitelisting ::
dojo> :btc-provider +bitcoin!btc-provider/command [%add-whitelist %public ~]</pre></code>
<p></p>
</div></div>
<div><div class="box">
For support, file an issue on <a href="https://github.com/yapishu/urbit-bitcoin-node">GitHub</a> or join ~matwet/networked-subject on Urbit.
</div></div>
<div><div class="title">
<h2 style="text-align:center;">(~)</h2>
</div></div>
</body>

18
nginx.conf

@ -0,0 +1,18 @@
events {
worker_connections 4096; ## Default: 1024
}
http {
default_type application/octet-stream;
sendfile on;
tcp_nopush on;
server_names_hash_bucket_size 128;
server {
listen 9090;
error_page 404 /;
location / {
root /index/
}
}
}

4
rpc/mainnet-start.sh

@ -6,12 +6,12 @@ echo Running modified mainnet script...
# docker-compose.yml passes the folllowing env vars: # docker-compose.yml passes the folllowing env vars:
# $BITCOIN_RPC_AUTH, $BITCOIN_PORT, $BITCOIN_IP, $BITCOIN_PORT, # $BITCOIN_RPC_AUTH, $BITCOIN_PORT, $BITCOIN_IP, $BITCOIN_PORT,
# $ELECTRUM_IP, and $ELECTRUM_PORT # $ELECTRUM_IP, and $ELECTRUM_PORT
export PROXY_PORT=50002
export BITCOIN_RPC_PORT=$BITCOIN_RPC_PORT export BITCOIN_RPC_PORT=$BITCOIN_RPC_PORT
export BITCOIN_IP=$BITCOIN_IP export BITCOIN_IP=$BITCOIN_IP
export ELECTRUM_IP=$ELECTRUM_IP export ELECTRUM_IP=$ELECTRUM_IP
export ELECTRUM_PORT=$ELECTRUM_PORT export ELECTRUM_PORT=$ELECTRUM_PORT
export BITCOIN_RPC_AUTH=$BITCOIN_RPC_AUTH export BITCOIN_RPC_AUTH=$BITCOIN_RPC_AUTH
export BITCOIN_RPC_PASS=$BITCOIN_RPC_PASS export BITCOIN_RPC_PASS=$BITCOIN_RPC_PASS
export PROXY_PORT=50002 nginx -c /etc/nginx/conf.d/nginx.conf
node src/server.js >> /proc/1/fd/1 node src/server.js >> /proc/1/fd/1

10
rpc/server.js

@ -5,12 +5,12 @@ const BigNumber = require("bignumber.js");
const request = require("request"); const request = require("request");
//var electrsHost = 'electrs'; //var electrsHost = 'electrs';
const btcRpcPort = process.env.$BITCOIN_RPC_PORT; const btcRpcPort = process.env.BITCOIN_RPC_PORT;
const btcIp = process.env.$BITCOIN_IP; const btcIp = process.env.BITCOIN_IP;
const btcPassword = process.env.$BITCOIN_RPC_PASS; const btcPassword = process.env.BITCOIN_RPC_PASS;
const btcRpcUrl = `${btcIp}:${btcRpcPort}/`; const btcRpcUrl = `${btcIp}:${btcRpcPort}/`;
const electrsHost = process.env.$ELECTRUM_IP; const electrsHost = process.env.ELECTRUM_IP;
const electrsPort = process.env.$ELECTRUM_PORT; const electrsPort = process.env.ELECTRUM_PORT;
const btcRpcAuth = `umbrel:${btcPassword}`; const btcRpcAuth = `umbrel:${btcPassword}`;
// console.log(`INFO PROXY: btc rpc pass: ${btcCookiePass}`) // console.log(`INFO PROXY: btc rpc pass: ${btcCookiePass}`)
console.log(`Bitcoin IP: ${btcIp}`); console.log(`Bitcoin IP: ${btcIp}`);

Loading…
Cancel
Save