-
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
Changes from 3 commits
61104c6
c6c5eb9
4925a8d
1479893
c79b378
d22510f
437fcd0
2eff412
a4f9a00
e0251b4
2b8592e
269b301
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -401,6 +401,9 @@ interface Wallet { | |
|
||
string descriptor_checksum(KeychainKind keychain); | ||
|
||
[Throws=DescriptorError] | ||
Policy? policies(KeychainKind keychain); | ||
|
||
Balance balance(); | ||
|
||
[Throws=CannotConnectError] | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Other fields have been exposed now. |
||
}; | ||
|
||
interface TxBuilder { | ||
constructor(); | ||
|
||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. I think this is our first use of 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 commentThe reason will be displayed to describe this comment to others. Learn more. Yes, thanks! |
||
|
||
TxBuilder change_policy(ChangeSpendPolicy change_policy); | ||
|
||
TxBuilder do_not_spend_change(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,12 +15,12 @@ use bdk_wallet::chain::tx_graph::CanonicalTx as BdkCanonicalTx; | |
use bdk_wallet::chain::{ | ||
ChainPosition as BdkChainPosition, ConfirmationBlockTime as BdkConfirmationBlockTime, | ||
}; | ||
use bdk_wallet::descriptor::Policy as BdkPolicy; | ||
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 commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure |
||
use std::sync::{Arc, Mutex}; | ||
|
||
#[derive(Debug)] | ||
|
@@ -237,3 +237,22 @@ pub struct KeychainAndIndex { | |
pub keychain: KeychainKind, | ||
pub index: u32, | ||
} | ||
|
||
/// Descriptor spending policy | ||
#[derive(Debug, PartialEq, Eq, Clone)] | ||
pub struct Policy(BdkPolicy); | ||
impl From<BdkPolicy> for Policy { | ||
fn from(value: BdkPolicy) -> Self { | ||
Policy(value) | ||
} | ||
} | ||
impl From<Policy> for BdkPolicy { | ||
fn from(value: Policy) -> Self { | ||
value.0 | ||
} | ||
} | ||
impl Policy { | ||
pub fn id(&self) -> String { | ||
self.0.id.clone() | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
use crate::bitcoin::{Psbt, Transaction}; | ||
use crate::descriptor::Descriptor; | ||
use crate::error::{ | ||
CalculateFeeError, CannotConnectError, CreateWithPersistError, LoadWithPersistError, | ||
SignerError, SqliteError, TxidParseError, | ||
CalculateFeeError, CannotConnectError, CreateWithPersistError, DescriptorError, | ||
LoadWithPersistError, SignerError, SqliteError, TxidParseError, | ||
}; | ||
use crate::store::Connection; | ||
use crate::types::{ | ||
AddressInfo, Balance, CanonicalTx, FullScanRequestBuilder, KeychainAndIndex, LocalOutput, | ||
SentAndReceivedValues, SyncRequestBuilder, Update, | ||
Policy, SentAndReceivedValues, SyncRequestBuilder, Update, | ||
}; | ||
|
||
use bitcoin_ffi::{Amount, FeeRate, OutPoint, Script}; | ||
|
@@ -139,6 +139,13 @@ impl Wallet { | |
self.get_wallet().descriptor_checksum(keychain) | ||
} | ||
|
||
pub fn policies(&self, keychain: KeychainKind) -> Result<Option<Arc<Policy>>, DescriptorError> { | ||
self.get_wallet() | ||
.policies(keychain) | ||
.map_err(DescriptorError::from) | ||
.map(|e| e.map(|p| Arc::new(p.into()))) | ||
} | ||
|
||
pub fn network(&self) -> Network { | ||
self.get_wallet().network() | ||
} | ||
|
@@ -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 commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
psbt: Arc<Psbt>, // sign_options: Option<SignOptions>, | ||
) -> Result<bool, SignerError> { | ||
let mut psbt = psbt.0.lock().unwrap(); | ||
self.get_wallet() | ||
|
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.
Looks good https://docs.rs/bdk_wallet/latest/bdk_wallet/struct.Wallet.html#method.policies