Skip to content

Instantly share code, notes, and snippets.

@notmandatory
Last active July 15, 2024 16:52
Show Gist options
  • Save notmandatory/6fa85dd942089833629bdb40d2b54858 to your computer and use it in GitHub Desktop.
Save notmandatory/6fa85dd942089833629bdb40d2b54858 to your computer and use it in GitHub Desktop.
BDK rpc cli setup and testing

Some notes on my manual rpc cli setup and testing:

  1. start bitcoind in regtest mode
mkdir /tmp/bitcoind
bitcoind -datadir=/tmp/bitcoind -regtest -server -fallbackfee=0.0002 -rpcallowip=0.0.0.0/0 -rpcbind=0.0.0.0 -blockfilterindex=1 --peerblockfilters=1 -daemon
  1. create bitcoind test wallet and generate blocks
bitcoin-cli -datadir=/tmp/bitcoind -regtest createwallet "test"
CORE_ADDRESS=$(bitcoin-cli -datadir=/tmp/bitcoind -regtest getnewaddress)
bitcoin-cli -datadir=/tmp/bitcoind -regtest generatetoaddress 155 $CORE_ADDRESS
  1. setup env for example_bitcoind_rpc_polling
cd example-crates/example_bitcoind_rpc_polling
export BITCOIN_NETWORK=regtest
export RPC_URL=127.0.0.1:18443
export RPC_COOKIE=/tmp/bitcoind/regtest/.cookie
export DESCRIPTOR="wpkh(tprv8ZgxMBicQKsPeahLBQMDWRatCzmT1T1HkqyXj7y6GZsrMyp9Ndy6Wgj9hJ4jPsAb3soNi9UzCiEnfDkVHRredhdYrXhDW9mCdWo2wXswv3G/*)"
  1. get new rpc wallet deposit address
cargo run -- address new
  1. send btc to rpc wallet
bitcoin-cli -datadir=/tmp/bitcoind -regtest sendtoaddress "<rpc wallet address>" 0.1
  1. verify balance recieved by rpc wallet
cargo run -- balance # should be no balance yet
cargo run -- sync
cargo run -- balance # should see the expected balance as unconfirmed
  1. create block and verify confirmed balance
bitcoin-cli -datadir=/tmp/bitcoind -regtest generatetoaddress 1 $CORE_ADDRESS
cargo run -- balance # balance still unconfirmed
cargo run -- sync
cargo run -- balance # balance is now confirmed 🥳 
  1. create address at index 1000. Note: this started at ~400ms to went up to ~800ms per address, we should add a address peek <index#> cli command to make this sort of testing easier. Should also figure out why the time to generate a new address grows.
for i in $(seq 0 1000);
do
   cargo run -- address new
done
  1. rename the wallet database
mv .bdk_example_rpc.db old.bdk_example_rpc.db
  1. send btc to address at index 1001 (should be outside lookahead range)
cargo run -- sync
cargo run -- balance
bitcoin-cli -datadir=/tmp/bitcoind -regtest sendtoaddress "<rpc wallet address at index 1000>" 0.001
cargo run -- sync
cargo run -- balance # balances should be found only on address at index 0
  1. create new address at index 1
cargo run -- address new
cargo run -- sync
cargo run -- balance # balance should now include confirmed index 0 and unconfirm index 1000 amounts
  1. create block and verify confirmed balance
bitcoin-cli -datadir=/tmp/bitcoind -regtest generatetoaddress 1 $CORE_ADDRESS
cargo run -- sync
cargo run -- balance # balance is now confirmed 🎉
  1. confirm utxos at index 0 and 1001
cargo run -- txout list
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment