rust-bitcoin / rust-bitcoincore-rpc

Rust RPC client library for the Bitcoin Core JSON-RPC API.
338 stars 250 forks source link

`RpcApi::create_wallet()` not working with Core v0.23.0 #225

Open rajarshimaitra opened 2 years ago

rajarshimaitra commented 2 years ago

We found in the BDK test module that RpcApi::create_wallet() isn't working as expected with core v0.23.0.. https://github.com/bitcoindevkit/bdk/issues/598

The same call that was creating a legacy wallet for core v0.22.0 and before, is now creating a descriptor wallet in v0.23.0.

The workaround fix for now is to make the manual call() with "createwallet" command as done in this PR https://github.com/bitcoindevkit/bdk/pull/613.

I also noticed that the create_wallet() arg list here (including defaults) are not consistent with bitcoin-cli creatwallet args as per v0.23.0.

$ bitcoin-cli help createwallet
createwallet "wallet_name" ( disable_private_keys blank "passphrase" avoid_reuse descriptors load_on_startup external_signer )

Creates and loads a new wallet.

Arguments:
1. wallet_name             (string, required) The name for the new wallet. If this is a path, the wallet will be created at the path location.
2. disable_private_keys    (boolean, optional, default=false) Disable the possibility of private keys (only watchonlys are possible in this mode).
3. blank                   (boolean, optional, default=false) Create a blank wallet. A blank wallet has no keys or HD seed. One can be set using sethdseed.
4. passphrase              (string, optional) Encrypt the wallet with this passphrase.
5. avoid_reuse             (boolean, optional, default=false) Keep track of coin reuse, and treat dirty and clean coins differently with privacy considerations in mind.
6. descriptors             (boolean, optional, default=true) Create a native descriptor wallet. The wallet will use descriptors internally to handle address creation
7. load_on_startup         (boolean, optional) Save wallet name to persistent settings and load on startup. True to add wallet to startup list, false to remove, null to leave unchanged.
8. external_signer         (boolean, optional, default=false) Use an external signer such as a hardware wallet. Requires -signer to be configured. Wallet creation will fail if keys cannot be fetched. Requires disable_private_keys and descriptors set to true.

It takes 8 args, but the function is passing in 9 args..

So most probably something is going wrong in parsing the args, and createwallet is not reading the descriptor flag. And as per v0.23.0 descriptors are default wallets in core.

BowTiedGroundHog commented 2 years ago

It seems I ran into something very much like this while testing BDK 0.23 against bitcoind 0.23.0, when trying to create a wallet and get addresses:

    let core_config = RpcConfig {
         url: "127.0.0.1:18443".to_string(),
         auth: rpc_auth,
         network: bdk::bitcoin::Network::Regtest,
         wallet_name: "test".to_string(),
         sync_params: None,
    };

    let core_rpc = RpcBlockchain::from_config(&core_config).unwrap();
    println!("{:#?}", core_rpc.get_blockchain_info().unwrap());

    let core_address = core_rpc.get_new_address(None, None).unwrap();

Which appears to create the wallet, but then returns this error on get_new_address:

"Error: This wallet has no available keys"