Skip to content

Commit

Permalink
Restore from ELECTRUM_MASTER_PRIVATE_KEY or ELECTRUM_MASTER_PUBLIC_KEY
Browse files Browse the repository at this point in the history
  • Loading branch information
ramontayag committed Jan 20, 2018
1 parent 845edc6 commit 528ece4
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,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)
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ services:
build: .
ports:
- "7000:7000"
command: run.sh
command: /run.sh
environment:
ELECTRUM_RPCUSER: electrum
ELECTRUM_RPCPASSWORD: electrumz
ELECTRUM_MASTER_PRIVATE_KEY: xprv9s21ZrQH143K2qhNXjGPHr6Rdz3h2N5dnt4sFspFnDqP8rPCXi5YPHq6hqQ2jSJb6XM4qwbfwMqxP5qsFRFRBKMPnE3WiAhFsBkVcMv2rYX
ELECTRUM_MASTER_PUBLIC_KEY: xpub661MyMwAqRbcFKmqdkoPez3AC1tBRpoVA6zU4GDsLZNN1eiM5FPnw69aZ6NbpahyLMsKeyjf2eqS64xSqYfsj9YWFWUpKtzbXmkLiAsRyCF
16 changes: 15 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,21 @@ electrum setconfig rpcpassword ${ELECTRUM_RPCPASSWORD}
electrum setconfig rpcport 7777

# run application
electrum daemon start && socat -v TCP-LISTEN:7000,fork TCP:127.0.0.1:7777
electrum daemon start

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

socat -v TCP-LISTEN:7000,fork TCP:127.0.0.1:7777

# wait forever
while true; do
Expand Down

0 comments on commit 528ece4

Please sign in to comment.