-
Notifications
You must be signed in to change notification settings - Fork 318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
docs(wallet): add example usage of descriptor and plan #1559
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working on this! It looks good and it's a great addition.
I guess you could rename the commits to the standard Conventional Commits, to something like: docs(wallet): add example usage of descriptor and plan
and maybe squash the clippy fixes into a single commit.
93f1d17
to
c256fd0
Compare
All done, thanks for the suggestions, and if there's anything else needed just let me know. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work on this. My initial thoughts are that we should try to narrow the scope to a few concepts including the descriptor, plan, and psbt.
It would be nice if the vault was a bdk Wallet
which we can simulate funding by just inserting a transaction into it (no need for get_funded_wallet
or TxBuilder
, and you can just hardcode a receive address for spending out of the vault).
We can use the Psbt::sign
API and just pass in the xpriv instead of using sign_ecdsa
.
Maybe add more println
s and assertions along the way if you think that would help. Another future enhancement would be to use the wallet to create a psbt, but I think more needs to be done in the library to fully utilize the Plan
construct. Having this example helps demonstrate how that could be implemented.
Ok great, happy to get rid of the ecdsa signing (I did it this way only because the only code example I could see that seemed as if it'd work came from the rust-miniscript repository). I'll try using And I will switch to using a Do the transaction inputs, outputs, and witness appear to be set up correctly? I'll keep working on it in a series of commits in my fork, and we can squash it down at the end once the example looks good. This is my first attempt with bdk so I'm very happy to receive feedback about how to structure things. |
b7134d1
to
002d1f6
Compare
Ok, updated with the following:
|
I think it's looking good. I put some ideas for extra improvements in this commit ValuedMammal/bdk@60601f1 that include
|
Looking quite a bit nicer now. Is it possible for you to squash merge it into the main bdk repo when ready? I've tied myself in a few git knots in my branch/repo, missed squashing your PR to my PR branch. |
8cca5fe
to
c5564f4
Compare
Ok, all squashed in place now, sorry for the noise. |
c5564f4
to
b948cb4
Compare
// Format an output which spends some of the funds in the vault | ||
let txout = TxOut { | ||
script_pubkey: emergency_wallet | ||
.next_unused_address(KeychainKind::External) | ||
.script_pubkey(), | ||
value: Amount::from_sat(750), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I realized we're not sending any change back to the vault, so in this case the majority of funds would be lost to fees. If we want to keep it to 1-input 1-output for simplicity we could just send all the original funds (76_000
) minus some reasonable amount for fees.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. I've added a 500 sat fee subtraction and sent the rest of the change back to the emergency_wallet
's change address.
b948cb4
to
1f68cb6
Compare
It looks like the API for The old API took a pub struct Update {
pub last_active_indices: BTreeMap<KeychainKind, u32>,
pub graph: TxGraph<ConfirmationBlockTime>,
pub chain: Option<CheckPoint>,
} The new API is basically the same but has a pub struct Update {
pub last_active_indices: BTreeMap<KeychainKind, u32>,
pub tx_update: TxUpdate<ConfirmationBlockTime>,
pub chain: Option<CheckPoint>,
} I can't see how to get access to Am I missing an easy way to get access to bdk_core from the wallet? Or is there a way to easily change this for a fake wallet funding transaction so that it doesn't depend on fn deposit_transaction(wallet: &mut Wallet, tx: Transaction) -> OutPoint {
use bdk_chain::{ConfirmationBlockTime, TxGraph};
use bdk_wallet::Update;
let txid = tx.compute_txid();
let vout = 0;
let mut graph = TxGraph::<ConfirmationBlockTime>::new([tx]);
let _ = graph.insert_seen_at(txid, 42);
wallet
.apply_update(Update {
graph,
..Default::default()
})
.unwrap();
OutPoint { txid, vout }
} |
You could try rebasing on current master to pick up the Note after #1425 you might also need to add |
633e96a
to
1f68cb6
Compare
1f68cb6
to
ec7342d
Compare
I've synced my branch with the bdk master and fixed compilation on top of that. Should be ready for review now. |
Description
Example usage of a vault policy, descriptor, and spend plan with a BDK wallet.
Changelog notice
docs(wallet): add example usage of descriptor and plan
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes: