Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ anyhow = { version = "1.0.98", optional = true }
bdk_file_store = { version = "0.21.1", optional = true }
bip39 = { version = "2.0", optional = true }
tempfile = { version = "3.20.0", optional = true }
bitcoin-payment-instructions = { version = "0.5.0", optional = true}

[features]
default = ["std"]
Expand All @@ -39,6 +40,7 @@ keys-bip39 = ["bip39"]
rusqlite = ["bdk_chain/rusqlite"]
file_store = ["bdk_file_store"]
test-utils = ["std", "anyhow", "tempfile"]
bip353 = ["bitcoin-payment-instructions"]

[dev-dependencies]
anyhow = "1"
Expand Down
58 changes: 58 additions & 0 deletions src/wallet/dns_tx_builder.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// Bitcoin Dev Kit
// Written in 2020 by Alekos Filini <alekos.filini@gmail.com>
//
// Copyright (c) 2020-2021 Bitcoin Dev Kit Developers
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.

use core::ops::{Deref, DerefMut};

use bitcoin::Amount;
use bitcoin_payment_instructions::{hrn_resolution::HrnResolver, PaymentInstructions};

use crate::tx_builder::TxBuilder;

/// A transaction builder with BIP 353 DNS payment instructions support
#[derive(Debug)]
pub struct TxBuilderDns<'a, Cs, R> {
pub(crate) tx_builder: TxBuilder<'a, Cs>,
pub(crate) resolver: R,
}

impl<'a, Cs, R> Deref for TxBuilderDns<'a, Cs, R> {
type Target = TxBuilder<'a, Cs>;
fn deref(&self) -> &Self::Target {
&self.tx_builder
}
}

impl<'a, Cs, R> DerefMut for TxBuilderDns<'a, Cs, R> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.tx_builder
}
}

impl<'a, Cs, R: HrnResolver> TxBuilderDns<'a, Cs, R> {
/// Chose the resolver to use
pub fn resolver<Rs: HrnResolver>(self, resolver: Rs) -> TxBuilderDns<'a, Cs, Rs> {
TxBuilderDns {
tx_builder: self.tx_builder,
resolver,
}
}

// Add a recipient with human_readable_name to the internal list
// The human readable name is in the form ₿user@domain or user@domain
pub fn add_recipient(
&mut self,
human_readable_name: &str,
amount: Amount,
) -> Result<&mut Self, &str> {

Ok(self)
}
}
21 changes: 20 additions & 1 deletion src/wallet/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,19 @@ mod params;
mod persisted;
pub mod signer;
pub mod tx_builder;

#[cfg(feature = "bip353")]
pub mod dns_tx_builder;
#[cfg(feature = "bip353")]
use core::{net::SocketAddr, str::FromStr};
#[cfg(feature = "bip353")]
use bitcoin_payment_instructions::dns_resolver::DNSHrnResolver;

pub(crate) mod utils;

use crate::collections::{BTreeMap, HashMap, HashSet};
#[cfg(feature = "bip353")]
use crate::dns_tx_builder::TxBuilderDns;
use crate::{collections::{BTreeMap, HashMap, HashSet}};
use crate::descriptor::{
check_wallet_descriptor, error::Error as DescriptorError, policy::BuildSatisfaction,
DerivedDescriptor, DescriptorMeta, ExtendedDescriptor, ExtractPolicy, IntoWalletDescriptor,
Expand Down Expand Up @@ -1342,6 +1352,15 @@ impl Wallet {
}
}

#[cfg(feature = "bip353")]
/// Build tx with default dns resolver
pub fn build_tx_with_dns(&mut self) -> TxBuilderDns<'_, DefaultCoinSelectionAlgorithm, DNSHrnResolver> {
TxBuilderDns {
tx_builder: self.build_tx(),
resolver: DNSHrnResolver(SocketAddr::from_str("8.8.8.8:53").unwrap())
}
}

pub(crate) fn create_tx<Cs: coin_selection::CoinSelectionAlgorithm>(
&mut self,
coin_selection: Cs,
Expand Down
2 changes: 2 additions & 0 deletions src/wallet/tx_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ pub(crate) struct TxParams {
pub(crate) bumping_fee: Option<PreviousFee>,
pub(crate) current_height: Option<absolute::LockTime>,
pub(crate) allow_dust: bool,
#[cfg(feature = "bip353")]
pub(crate) supports_proof_of_payment_callbacks: bool
}

#[derive(Clone, Copy, Debug)]
Expand Down