Skip to content

Commit 421dddb

Browse files
committed
build(nix): update develop environment to work with bdk-cli v3.0.0
bdk-cli new release added a configuration file to set wallet parameters and removed the flags from cli. This change broke some of the wrapper commands designed for use inside the development environment, forcing the current update. As the new configuration format is a toml file, this change adds the `dasel` tool to the nix environment to be able to rewrite auth keys on the bdk file on each environment restart.
1 parent 2f28d19 commit 421dddb

3 files changed

Lines changed: 36 additions & 40 deletions

File tree

doc/tabconf7/flake.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

doc/tabconf7/flake.nix

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
paths = with pkgs;
6060
[
6161
jq
62+
dasel
6263
podman
6364
qrencode
6465
xclip
@@ -95,8 +96,6 @@
9596
export RPC_PASS=$(cat $BITCOIN_DATA_DIR/signet/.cookie | cut -d ':' -f2)
9697
export RPC_URL="http://127.0.0.1:38332/"
9798
export TR_XPRV=$(cat ".tr_xprv")
98-
export EXT_DESCRIPTOR=$(cat "$BDK_DATA_DIR/.external_descriptor")
99-
export INT_DESCRIPTOR=$(cat "$BDK_DATA_DIR/.internal_descriptor")
10099
export EXTRA_PEER=$(bitcoin-cli --datadir=$BITCOIN_DATA_DIR --chain=signet getpeerinfo | jq -r 'map(select(.servicesnames[] | contains ("COMPACT"))) | .[0].addr' | cut -sd ":" -f1)
101100
'';
102101
};
@@ -125,7 +124,7 @@
125124
126125
cat > "$EXTRA_SCRIPTS/signet-bdk" <<'EOF'
127126
#!/usr/bin/env bash
128-
bdk-cli --datadir "$BDK_DATA_DIR" --network signet wallet -w signet -e "$EXT_DESCRIPTOR" -i "$INT_DESCRIPTOR" -c rpc -u http://localhost:38332/ "$BITCOIN_DATA_DIR/signet/.cookie" -d sqlite "$@"
127+
bdk-cli --datadir "$BDK_DATA_DIR" wallet -w signet "$@"
129128
EOF
130129
131130
chmod +x "$EXTRA_SCRIPTS/signet-bdk"
@@ -164,12 +163,16 @@
164163
export RPC_PASS=$(cat $BITCOIN_DATA_DIR/signet/.cookie | cut -d ':' -f2)
165164
export RPC_URL="http://127.0.0.1:38332/"
166165
167-
if [ ! -f "$BDK_DATA_DIR/.external_descriptor" ] || [ ! -f "$BDK_DATA_DIR/.internal_descriptor" ]; then
166+
IS_SIGNET_WALLET_AVAILABLE=$(bdk-cli --datadir "$BDK_DATA_DIR" wallets | jq -r 'any(.wallets[].name; . == "signet")')
167+
if [ $IS_SIGNET_WALLET_AVAILABLE == "true" ]; then
168+
dasel -i toml --root 'wallets.signet.rpc_user = $RPC_USER' < .bdk/config.toml > .bdk/config.toml.tmp && mv .bdk/config.toml.tmp .bdk/config.toml
169+
dasel -i toml --root 'wallets.signet.rpc_password = $RPC_PASS' < .bdk/config.toml > .bdk/config.toml.tmp && mv .bdk/config.toml.tmp .bdk/config.toml
170+
else
168171
rm -rf $BDK_DATA_DIR/signet
169-
rm -rf $BDK_DATA_DIR/regtest
170172
XPRV=$(bdk-cli --datadir $BDK_DATA_DIR --network signet key generate | jq -r '.xprv')
171-
echo "tr($XPRV/86h/1h/0h/0/*)" > "$BDK_DATA_DIR/.external_descriptor"
172-
echo "tr($XPRV/86h/1h/0h/1/*)" > "$BDK_DATA_DIR/.internal_descriptor"
173+
EXT_DESCRIPTOR=$(echo "tr($XPRV/86h/1h/0h/0/*)")
174+
INT_DESCRIPTOR=$(echo "tr($XPRV/86h/1h/0h/1/*)")
175+
bdk-cli --datadir "$BDK_DATA_DIR" --network signet wallet -w signet config -e "$EXT_DESCRIPTOR" -i "$INT_DESCRIPTOR" -c rpc -u $RPC_URL $BITCOIN_DATA_DIR/signet/.cookie -d sqlite
173176
fi
174177
175178
if [ ! -f ".tr_xprv" ]; then
@@ -183,8 +186,7 @@
183186
just init
184187
185188
export TR_XPRV=$(cat ".tr_xprv")
186-
export EXT_DESCRIPTOR=$(cat "$BDK_DATA_DIR/.external_descriptor")
187-
export INT_DESCRIPTOR=$(cat "$BDK_DATA_DIR/.internal_descriptor")
189+
188190
export EXTRA_PEER=$(bitcoin-cli --datadir=$BITCOIN_DATA_DIR --chain=signet getpeerinfo | jq -r 'map(select(.servicesnames[] | contains ("COMPACT"))) | .[0].addr' | cut -sd ":" -f1)
189191
190192
trap "bitcoin-cli --datadir=$BITCOIN_DATA_DIR --chain=signet stop && just stop" EXIT

doc/tabconf7/justfile

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ regtest-sp COMMAND *ARGS:
2828
[doc("Send a command to bdk-cli on regtest")]
2929
regtest-bdk COMMAND *ARGS:
3030
#!/usr/bin/env bash
31-
export EXT_DESCRIPTOR=$(cat "{{bdk_data_dir}}/.external_descriptor")
32-
export INT_DESCRIPTOR=$(cat "{{bdk_data_dir}}/.internal_descriptor")
33-
bdk-cli --datadir "{{bdk_data_dir}}" --network regtest wallet -w regtest -e "$EXT_DESCRIPTOR" -i "$INT_DESCRIPTOR" -c rpc -u http://localhost:18443/ $(just local_cookie_path) -d sqlite {{COMMAND}} {{ARGS}}
31+
bdk-cli --datadir "{{bdk_data_dir}}" --network regtest wallet -w regtest {{COMMAND}} {{ARGS}}
3432
3533
[group("Podman")]
3634
[doc("Set up VM to run containers")]
@@ -229,7 +227,8 @@ startcontainer: (create "false" "1.0.0")
229227
podman --connection sptabconf7 start RegtestBitcoinEnv
230228
231229
_clean_regtest_bdk:
232-
rm -rf {{bdk_data_dir}}/regtest
230+
rm -rf "{{bdk_data_dir}}/regtest"
231+
dasel -i toml --root "wallets.regtest = null" < .bdk/config.toml > .bdk/config.toml.tmp && mv .bdk/config.toml.tmp .bdk/config.toml
233232
234233
_clean_regtest_sp:
235234
#!/usr/bin/env bash
@@ -355,13 +354,6 @@ envpath:
355354
cookie:
356355
just podcmd "cat $(just envpath)/regtest/.cookie | cut -d ':' -f2"
357356
358-
[group("Bitcoin Core")]
359-
[doc("Write the current session cookie to file and return path")]
360-
local_cookie_path:
361-
#!/usr/bin/env bash
362-
just podcmd "cat $(just envpath)/regtest/.cookie" > .regtest_cookie
363-
echo ".regtest_cookie"
364-
365357
[group("Bitcoin Core")]
366358
[doc("Mine a block, or mine <BLOCKS> number of blocks")]
367359
mine BLOCKS="1" ADDRESS="bcrt1q6gau5mg4ceupfhtyywyaj5ge45vgptvawgg3aq":
@@ -470,13 +462,15 @@ sendto ADDRESS:
470462
471463
_init_regtest_bdk:
472464
#!/usr/bin/env bash
473-
mkdir -p {{bdk_data_dir}}
474-
if [ ! -f "{{bdk_data_dir}}/.external_descriptor" ] || [ ! -f "{{bdk_data_dir}}/.internal_descriptor" ]; then
475-
rm -rf {{bdk_data_dir}}/signet
476-
rm -rf {{bdk_data_dir}}/regtest
477-
XPRV=$(bdk-cli --datadir {{bdk_data_dir}} --network signet key generate | jq -r '.xprv')
478-
echo "tr($XPRV/86h/1h/0h/0/*)" > "{{bdk_data_dir}}/.external_descriptor"
479-
echo "tr($XPRV/86h/1h/0h/1/*)" > "{{bdk_data_dir}}/.internal_descriptor"
465+
regtest_wallet_created=$(bdk-cli --datadir "{{bdk_data_dir}}" wallets | jq -r 'any(.wallets[].name; . == "regtest")')
466+
if [ $regtest_wallet_created == "false" ]; then
467+
mkdir -p "{{bdk_data_dir}}"
468+
rm -rf "{{bdk_data_dir}}/regtest"
469+
COOKIE=$(just podcmd "cat $(just envpath)/regtest/.cookie")
470+
XPRV=$(bdk-cli --datadir "{{bdk_data_dir}}" --network regtest key generate | jq -r '.xprv')
471+
EXT_DESCRIPTOR=$(echo "tr($XPRV/86h/1h/0h/0/*)")
472+
INT_DESCRIPTOR=$(echo "tr($XPRV/86h/1h/0h/1/*)")
473+
bdk-cli --datadir "{{bdk_data_dir}}" --network regtest wallet -w regtest config -e "$EXT_DESCRIPTOR" -i "$INT_DESCRIPTOR" -c rpc -u http://localhost:18443/ -a "$COOKIE" -d sqlite
480474
fi
481475
482476
_init_regtest_sp:

0 commit comments

Comments
 (0)