From bbeeec13cb8816dabd9a71fed954c5ed03d1bfd8 Mon Sep 17 00:00:00 2001 From: Ramon Tayag Date: Sat, 20 Jan 2018 20:43:07 +0800 Subject: [PATCH] Restore from ELECTRUM_MASTER_PRIVATE_KEY or ELECTRUM_MASTER_PUBLIC_KEY --- README.md | 3 +++ docker-compose.yml | 2 ++ docker-entrypoint.sh | 13 +++++++++++++ 3 files changed, 18 insertions(+) diff --git a/README.md b/README.md index bf4e0f2..635d5a0 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,9 @@ curl --data-binary '{"id":"1","method":"listaddresses"}' http://electrum:electru Always link electrum daemon to containers or bind to localhost directly and not expose 7000 port for security reasons. +### 12 Factor +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. + ## API * [Electrum protocol specs](http://docs.electrum.org/en/latest/protocol.html) diff --git a/docker-compose.yml b/docker-compose.yml index 2718354..7cc7f25 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,3 +7,5 @@ services: environment: ELECTRUM_USER: electrum ELECTRUM_PASSWORD: electrumz + ELECTRUM_MASTER_PRIVATE_KEY: xprv9s21ZrQH143K2qhNXjGPHr6Rdz3h2N5dnt4sFspFnDqP8rPCXi5YPHq6hqQ2jSJb6XM4qwbfwMqxP5qsFRFRBKMPnE3WiAhFsBkVcMv2rYX + ELECTRUM_MASTER_PUBLIC_KEY: xpub661MyMwAqRbcFKmqdkoPez3AC1tBRpoVA6zU4GDsLZNN1eiM5FPnw69aZ6NbpahyLMsKeyjf2eqS64xSqYfsj9YWFWUpKtzbXmkLiAsRyCF diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index f87acb8..432ed3f 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -12,6 +12,19 @@ electrum setconfig rpcport 7000 # run application electrum daemon start +# restore from keys if available +if [ -n "$ELECTRUM_MASTER_PRIVATE_KEY" ]; +then + echo "Restoring and loading wallet from Master Private Key" + echo | electrum restore $ELECTRUM_MASTER_PRIVATE_KEY + electrum daemon load_wallet +elif [ -n "$ELECTRUM_MASTER_PUBLIC_KEY" ]; +then + echo "Restoring and loading wallet from Master Public Key" + electrum restore $ELECTRUM_MASTER_PUBLIC_KEY + electrum daemon load_wallet +fi + # wait forever while true; do tail -f /dev/null & wait ${!}