From 9ca09afff61dd504247b72cc3e49c8999939f41a Mon Sep 17 00:00:00 2001 From: skoupidi Date: Thu, 14 Nov 2024 16:29:36 +0200 Subject: [PATCH] contrib/localnet/darkfid-single-node: automated wallet stuff --- .../localnet/darkfid-single-node/README.md | 15 +++++--------- contrib/localnet/darkfid-single-node/clean.sh | 1 + .../darkfid-single-node/init-wallet.sh | 10 ++++++++++ .../darkfid-single-node/wallet-balance.sh | 14 +++++++++++++ doc/src/testnet/node.md | 20 +++++++------------ 5 files changed, 37 insertions(+), 23 deletions(-) create mode 100755 contrib/localnet/darkfid-single-node/init-wallet.sh create mode 100755 contrib/localnet/darkfid-single-node/wallet-balance.sh diff --git a/contrib/localnet/darkfid-single-node/README.md b/contrib/localnet/darkfid-single-node/README.md index 4a7ea8afb68f..7736be0a0c49 100644 --- a/contrib/localnet/darkfid-single-node/README.md +++ b/contrib/localnet/darkfid-single-node/README.md @@ -8,17 +8,13 @@ If we want to test wallet stuff, we must generate a testing wallet and pass its address to the `darkfid` config, so the wallet gets the block rewards the node produces. We generate a wallet, set it as the default -and grab its address: +and set its address as the `recipient` field in +`darkfid.toml`, using the porvided automated script: ``` -% ../../../drk -c drk.toml wallet --initialize -% ../../../drk -c drk.toml wallet --keygen -% ../../../drk -c drk.toml wallet --default-address 1 -% ../../../drk -c drk.toml wallet --address +% ./init-wallet.sh ``` -Then we replace the `recipient` field in `darkfid.toml` -config with the output of the last command, start -`darkfid` and wait until its initialized: +Then start `darkfid` and wait until its initialized: ``` % ./tmux_sessions.sh ``` @@ -26,8 +22,7 @@ config with the output of the last command, start After some blocks have been generated we will see some `DRK` in our test wallet. ``` -% ../../../drk -c drk.toml scan -% ../../../drk -c drk.toml wallet --balance +% ./wallet-balance.sh ``` See the user guide in the book for more info. diff --git a/contrib/localnet/darkfid-single-node/clean.sh b/contrib/localnet/darkfid-single-node/clean.sh index 4ed61bb98ac6..d626ffd5fa50 100755 --- a/contrib/localnet/darkfid-single-node/clean.sh +++ b/contrib/localnet/darkfid-single-node/clean.sh @@ -1,2 +1,3 @@ #!/bin/sh rm -rf darkfid drk +sed -i -e "s|recipient =.*|recipient = \"9vw6WznKk7xEFQwwXhJWMMdjUPi3cXL8NrFKQpKifG1U\"|g" darkfid.toml diff --git a/contrib/localnet/darkfid-single-node/init-wallet.sh b/contrib/localnet/darkfid-single-node/init-wallet.sh new file mode 100755 index 000000000000..b0f18ba7f0a8 --- /dev/null +++ b/contrib/localnet/darkfid-single-node/init-wallet.sh @@ -0,0 +1,10 @@ +#!/bin/sh + +# Path to `drk` binary +DRK="../../../drk -c drk.toml" + +$DRK wallet --initialize +$DRK wallet --keygen +$DRK wallet --default-address 1 +wallet=$($DRK wallet --address) +sed -i -e "s|9vw6WznKk7xEFQwwXhJWMMdjUPi3cXL8NrFKQpKifG1U|$wallet|g" darkfid.toml diff --git a/contrib/localnet/darkfid-single-node/wallet-balance.sh b/contrib/localnet/darkfid-single-node/wallet-balance.sh new file mode 100755 index 000000000000..2bba982a549a --- /dev/null +++ b/contrib/localnet/darkfid-single-node/wallet-balance.sh @@ -0,0 +1,14 @@ +#!/bin/sh + +# Path to `drk` binary +DRK="../../../drk -c drk.toml" + +while true; do + if $DRK ping 2> /dev/null; then + break + fi + sleep 1 +done + +$DRK scan +$DRK wallet --balance diff --git a/doc/src/testnet/node.md b/doc/src/testnet/node.md index cd5e7abbbdbb..02dde6370bfa 100644 --- a/doc/src/testnet/node.md +++ b/doc/src/testnet/node.md @@ -147,20 +147,14 @@ wallet CLI: $ make darkfid minerd drk ``` -Enter the localnet folder, generate a wallet, set it as the -default one and grab its address: +Enter the localnet folder, and initialize a wallet: ``` $ cd contrib/localnet/darkfid-single-node/ -$ ../../../drk -c drk.toml wallet --initialize -$ ../../../drk -c drk.toml wallet --keygen -$ ../../../drk -c drk.toml wallet --default-address 1 -$ ../../../drk -c drk.toml wallet --address +$ ./init-wallet.sh ``` -Then we replace the `recipient` field in `darkfid.toml` -config, existing in the folder, with the output of the last -command, start `darkfid` and wait until its initialized: +Then start `darkfid` and wait until its initialized: ``` $ ./tmux_sessions.sh @@ -168,12 +162,12 @@ $ ./tmux_sessions.sh After some blocks have been generated we will see some `DRK` in our test wallet. -On a different shell, navigate to `contrib/localnet/darkfid-single-node` -folder again and scan for new blocks +On a different shell(or tmux pane in the session), +navigate to `contrib/localnet/darkfid-single-node` +folder again and check wallet balance ``` -$ ../../../drk -c drk.toml scan -$ ../../../drk -c drk.toml wallet --balance +$ ./wallet-balance.sh ``` Don't forget that when using this local node, all operations