bitcoindevkit / bdk-cli

A CLI wallet library and REPL tool to demo and test the BDK library
Other
108 stars 64 forks source link

bdk-cli not showing a balance on mainnet #145

Closed Rob1Ham closed 1 year ago

Rob1Ham commented 1 year ago

Describe the bug

BDK-CLI is not returning an accurate balance for a main net wallet.

To Reproduce
Using BDK-CLI for some testing on mainnet, I ran the following commands:

export TEST_DESCRIPTOR= wsh(or_d(thresh(1,pk([03250086/84h/0h/0h]xpub6BemYiVNp19a1H1WoK8m1eNjyEp1Xjs3Mc1FkBBCFHNBg8fmPgX53FbizyPEWVriwRvGhe28o378PLoPbm6wdjh3pZMH1C979npmsZUxc6j/0/*)),and_v(v:thresh(1,pk([9f6105e5/48h/0h/0h/2h]xpub6Dh3YvQbBwZScoZrDaRoaDJwZNYTzm5LSo4UpunUhq2FAWQL8fhwFpWRhTMj3ReXm8BZr4hH6XwgHd18EieLyhYGYGGT7gMJgmV2ThK8f2x/0/*)),older(30))))#w9erpraz

bdk-cli % bdk-cli --network bitcoin wallet -w quicktest -d $TEST_DESCRIPTOR sync
{}
bdk-cli --network bitcoin wallet -w quicktest  -d $TEST_DESCRIPTOR get_new_address
{
  "address": "bc1qhgvzuuetc6dac2veqad8cjdzcz8dkgywn7dhetkp5cs3y58qugks2x0h9e"
}
bdk-cli --network bitcoin wallet -w quicktest -d $TEST_DESCRIPTOR get_balance
{
  "satoshi": {
    "confirmed": 0,
    "immature": 0,
    "trusted_pending": 0,
    "untrusted_pending": 0
  }
}

It can be seen though that address bc1qhgvzuuetc6dac2veqad8cjdzcz8dkgywn7dhetkp5cs3y58qugks2x0h9e has coins here.

Expected behavior

Given the current balanace of the utxo, i'd expect an output of:

{
  "satoshi": {
    "confirmed": 28392,
    "immature": 0,
    "trusted_pending": 0,
    "untrusted_pending": 0
  }
}

Build environment

notmandatory commented 1 year ago

This is a gap in our documentation for doing on-chain transactions with bdk-cli. The default electrum server URL points to Blockstream's testnet endpoint (ssl://electrum.blockstream.info:60002). To get your on-chain wallet balance you need to use the Blockstream (ssl://electrum.blockstream.info:60002) or any other mainnet electrum url:

$ bdk-cli --network bitcoin wallet -w quicktest -d $TEST_DESCRIPTOR -s ssl://electrum.blockstream.info:50002 sync      
{}
$ bdk-cli --network bitcoin wallet -w quicktest -d $TEST_DESCRIPTOR -s ssl://electrum.blockstream.info:50002 get_balance
{
  "satoshi": 28392
}