btcsuite / btcwallet

A secure bitcoin wallet daemon written in Go (golang)
ISC License
1.13k stars 582 forks source link

BIP 49/84 segwit receive addresses cannot be used when `btcwallet` is ran as a daemon #762

Open AlexSSD7 opened 3 years ago

guggero commented 3 years ago

Yes: https://github.com/btcsuite/btcwallet/search?q=bip49&type=code https://github.com/btcsuite/btcwallet/search?q=bip84&type=code

AlexSSD7 commented 3 years ago

Oh, ok. Why only legacy addresses are being generated then?

guggero commented 3 years ago

You probably need to specify the key scope to use: https://github.com/btcsuite/btcwallet/blob/master/waddrmgr/scoped_manager.go#L154

AlexSSD7 commented 3 years ago

How to do that? (I'm running the daemon via CLI, not calling it from the code FYI)

guggero commented 3 years ago

I'm not very familiar with the CLI. What command are you using exactly?

AlexSSD7 commented 3 years ago

./btcwallet --testnet --btcdusername xxx --btcdpassword xxx -u xxx -P xxx

AlexSSD7 commented 3 years ago

getnewaddress RPC method generates a legacy address, not P2SH segwit or native bech32 address.

{
  "jsonrpc": "1.0",
  "result": "n12UeNcL4ruCiHbmgEgieAwXVbFNZrobQh",
  "error": null,
  "id": 1
}
guggero commented 3 years ago

Yes, you're right. It looks like the functionality to generate SegWit addresses was only added to the internal DB but never exposed to the RPC interface.

AlexSSD7 commented 3 years ago

Oh, okay. Thank you.

Also I had no idea that I can use btcwallet programmatically without running the actual CLI daemon.