-
Notifications
You must be signed in to change notification settings - Fork 45
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
Add Spending Policy API #612
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.
Nice! Thanks!!
A couple comments that are just notes and don't require any action, and then one question and two nits, but nothing that blocks me approving this or us merging as is:
ACK 4925a8d
Side question:
- I see you checked
I've added tests for the new feature
in the PR template does that mean you are planning on adding a test (I didn't see one in current code)? Not even saying it's needed (and I'm assuming you tested on an external application since you opened Spending Policy Required: External error on tx builder finish #605 ). Note: I didn't test on an external app during this PR review.
@@ -401,6 +401,9 @@ interface Wallet { | |||
|
|||
string descriptor_checksum(KeychainKind keychain); | |||
|
|||
[Throws=DescriptorError] | |||
Policy? policies(KeychainKind keychain); |
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.
@@ -441,6 +444,10 @@ interface Wallet { | |||
|
|||
interface Update {}; | |||
|
|||
interface Policy { | |||
string id(); |
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.
Is this the only field you need/want for your use case? Just curious really, since we can expose other fields later if needed obv.
Regardless, looks good https://docs.rs/bdk_wallet/latest/bdk_wallet/descriptor/policy/struct.Policy.html
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.
Other fields have been exposed now.
@@ -456,6 +463,8 @@ interface TxBuilder { | |||
|
|||
TxBuilder add_utxo(OutPoint outpoint); | |||
|
|||
TxBuilder policy_path(record<string, sequence<u64>> policy_path, KeychainKind keychain); |
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 think this is our first use of record
https://mozilla.github.io/uniffi-rs/0.27/udl/builtin_types.html in the UDL
Looks good https://docs.rs/bdk_wallet/latest/bdk_wallet/tx_builder/struct.TxBuilder.html#method.policy_path
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.
Yes, thanks!
use bdk_wallet::AddressInfo as BdkAddressInfo; | ||
use bdk_wallet::Balance as BdkBalance; | ||
use bdk_wallet::KeychainKind; | ||
use bdk_wallet::LocalOutput as BdkLocalOutput; | ||
use bdk_wallet::Update as BdkUpdate; | ||
|
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.
nit: I think we can keep this blank line since we seem to break these use
in groups
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.
Sure
bdk-ffi/src/wallet.rs
Outdated
@@ -154,8 +161,7 @@ impl Wallet { | |||
|
|||
pub(crate) fn sign( | |||
&self, | |||
psbt: Arc<Psbt>, | |||
// sign_options: Option<SignOptions>, |
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.
nit: might be nice to keep this on a separate line, but at the same time not any sort of blocker to approving this PR (and we might just remove the whole commented line before 1.0 beta anyway on bdk-ffi)
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.
Done!
I'm trying to understand this How do I know which path (u32) to choose if I'm not given the whole tree and options to choose from? I see that the Thresh {
items: Vec<Policy>,
threshold: usize,
}, Should we expose this field too so that users can query the satifiable item(s)? I'm just not clear on this API and I want to make sure we get you what you need. Follow upI tried using one of the multisig examples in the BIP-383 test vectors: wsh(multi(2,xprv9s21ZrQH143K31xYSDQpPDxsXRTUcvj2iNHm5NUtrGiGG5e2DtALGdso3pGz6ssrdK4PFmM8NSpSBHNqPqm55Qn3LqFtT2emdEXVYsCzC2U/2147483647/0,xprv9vHkqa6EV4sPZHYqZznhT2NPtPCjKuDKGY38FBWLvgaDx45zo9WQRUT3dKYnjwih2yJD9mkrocEZXo1ex8G81dwSM1fwqWpWkeS3v86pgKt/1/2/*,xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi/10/20/30/40/*)) And I get this as a Policy {
id: "lrvxqx7c",
item: Multisig {
keys: [Fingerprint(bd16bee5), Fingerprint(5a61ff8e), Fingerprint(3442193e)],
threshold: 2
},
satisfaction: Partial {
n: 3,
m: 2,
items: [],
sorted: Some(false),
conditions: {}
},
contribution: PartialComplete {
n: 3,
m: 2,
items: [0, 1, 2],
sorted: Some(false),
conditions: {
[0, 1]: {Condition { csv: None, timelock: None }},
[0, 2]: {Condition { csv: None, timelock: None }},
[1, 2]: {Condition { csv: None, timelock: None }}
}
}
} Is the vector you'd want to provide to the @afilini we might need your input here just to make sure we expose the correct behaviour and options. |
Thanks @thunderbiscuit I have exposed other fields as well now. |
I have now exposed this field |
@thunderbiscuit |
@thunderbiscuit Yes this is what we need. An integration test has been added here for the use case using the new exposed API: |
Thanks for the work @BitcoinZavior! I squashed and rebased. Merging now. |
For some reason I can't force push to your branch. But I added your commit in #626. |
Merged in #629. Thanks for the work @BitcoinZavior! |
Awesome work @BitcoinZavior !!! |
Description
Fixes the follwoing bug:
Encountering a Spending policy required: External error when attempting to build a transaction using a multi-sig descriptor. Currently, bdk-ffi does not provide a policy_path() in txBuilder, which is necessary for specifying the correct policy path during transaction creation.
The PR fix has the following changes:
Changelog notice
### Fixes
Enhancements
Checklists
All Submissions:
cargo fmt
andcargo clippy
before committingNew Features:
Bugfixes:
Fixes Spending Policy Required: External error on tx builder finish #605