bdk icon indicating copy to clipboard operation
bdk copied to clipboard

README example is wrong

Open LLFourn opened this issue 2 years ago • 5 comments

use bdk::{bitcoin::Network, wallet::{AddressIndex, Wallet}};

fn main() {
    // a type that implements `Persist`
    let db = ();

    let descriptor = "wpkh(tprv8ZgxMBicQKsPdy6LMhUtFHAgpocR8GC6QmwMSFpZs7h6Eziw3SpThFfczTDh5rW2krkqffa11UpX3XkeTTB2FvzZKWXqPY54Y6Rq4AQ5R8L/84'/0'/0'/0/*)";
    let mut wallet = Wallet::new(descriptor, None, db, Network::Testnet).expect("should create");

    // get a new address (this increments revealed derivation index)
    println!("revealed address: {}", wallet.get_address(AddressIndex::New));
    println!("staged changes: {:?}", wallet.staged());
    // persist changes
    wallet.commit().expect("must save");
}

This indicates two things that are not helpful:

  1. You should do Wallet::new when you don't want persistence. We have a method for creating a wallet without persistence. If we want to show them how to use actual persistence then let's use that method.
  2. You do not need to call commit after doing get_address to persist the changes -- it does it automatically (in fact staged should be empty which indicates to me no one has run this example :sweat_smile:) . There's also no point in committing anyway since the db is explicitly () so it's confusing.

LLFourn avatar Jul 20 '23 03:07 LLFourn

+1

Kinda related, we should also remove this part:

For a release timeline see the bdk_core_staging repo where a lot of the component work is being done. The plan is that everything in the bdk_core_staging repo will be moved into the crates directory here.

And link to the actual roadmap https://github.com/orgs/bitcoindevkit/projects/14/views/1?filterQuery=

danielabrozzoni avatar Jul 21 '23 13:07 danielabrozzoni

Moved to beta.0 since this isn't an API change, just an examples / docs cleanup.

notmandatory avatar Dec 05 '23 06:12 notmandatory

It's a pretty important one though? Broken outdated READMEs often put people off trying stuff.

LLFourn avatar Dec 06 '23 01:12 LLFourn

I agree the README example is important, and probably not too hard to fix we just have lots of higher priority stuff in the queue to code/review. As long as it's fixed before we make any big beta announcements I'd prefer to keep it in the beta milestone.

notmandatory avatar Dec 07 '23 04:12 notmandatory

I am aware this is in need of a refresh. Leaving a few extra notes here:

  • Some links are either broken or point to non-existent types
  • If the intention is to demonstrate wallet persistence, we could find another method that would require the user to commit their own changes (not sure if there is a practical example of this)
  • The example descriptor mixes a mainnet derivation path with Testnet network (evidently a pet peeve of mine)

ValuedMammal avatar Jan 17 '24 20:01 ValuedMammal