Skip to content

Commit 528ece4

Browse files
committed
Restore from ELECTRUM_MASTER_PRIVATE_KEY or ELECTRUM_MASTER_PUBLIC_KEY
1 parent 845edc6 commit 528ece4

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ curl --data-binary '{"id":"1","method":"listaddresses"}' http://electrum:electru
4141

4242
Always link electrum daemon to containers or bind to localhost directly and not expose 7000 port for security reasons.
4343

44+
### 12 Factor
45+
You may also restore the wallet from a Master Private Key or Master Public Key by setting `ELECTRUM_MASTER_PRIVATE_KEY` or `ELECTRUM_MASTER_PUBLIC_KEY` env vars. This is useful in a setup like Kubernetes.
46+
4447
## API
4548

4649
* [Electrum protocol specs](http://docs.electrum.org/en/latest/protocol.html)

docker-compose.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ services:
44
build: .
55
ports:
66
- "7000:7000"
7-
command: run.sh
7+
command: /run.sh
88
environment:
99
ELECTRUM_RPCUSER: electrum
1010
ELECTRUM_RPCPASSWORD: electrumz
11+
ELECTRUM_MASTER_PRIVATE_KEY: xprv9s21ZrQH143K2qhNXjGPHr6Rdz3h2N5dnt4sFspFnDqP8rPCXi5YPHq6hqQ2jSJb6XM4qwbfwMqxP5qsFRFRBKMPnE3WiAhFsBkVcMv2rYX
12+
ELECTRUM_MASTER_PUBLIC_KEY: xpub661MyMwAqRbcFKmqdkoPez3AC1tBRpoVA6zU4GDsLZNN1eiM5FPnw69aZ6NbpahyLMsKeyjf2eqS64xSqYfsj9YWFWUpKtzbXmkLiAsRyCF

run.sh

+15-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,21 @@ electrum setconfig rpcpassword ${ELECTRUM_RPCPASSWORD}
1010
electrum setconfig rpcport 7777
1111

1212
# run application
13-
electrum daemon start && socat -v TCP-LISTEN:7000,fork TCP:127.0.0.1:7777
13+
electrum daemon start
14+
15+
if [ -n "$ELECTRUM_MASTER_PRIVATE_KEY" ];
16+
then
17+
echo "Restoring and loading wallet from Master Private Key"
18+
echo | electrum restore $ELECTRUM_MASTER_PRIVATE_KEY
19+
electrum daemon load_wallet
20+
elif [ -n "$ELECTRUM_MASTER_PUBLIC_KEY" ];
21+
then
22+
echo "Restoring and loading wallet from Master Public Key"
23+
electrum restore $ELECTRUM_MASTER_PUBLIC_KEY
24+
electrum daemon load_wallet
25+
fi
26+
27+
socat -v TCP-LISTEN:7000,fork TCP:127.0.0.1:7777
1428

1529
# wait forever
1630
while true; do

0 commit comments

Comments
 (0)