Skip to content
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

Use AddressCompat to display address #67

Merged
merged 1 commit into from
Jan 18, 2023
Merged
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
13 changes: 8 additions & 5 deletions descriptors/src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,11 @@
// If not, see <https://opensource.org/licenses/Apache-2.0>.

use bitcoin::secp256k1::{Secp256k1, Verification};
use bitcoin::{Address, Network, Script};
use bitcoin::{Network, Script};
#[cfg(feature = "miniscript")]
use bitcoin_hd::{DerivationAccount, DerivePatternError};
use bitcoin_hd::{DeriveError, UnhardenedIndex};
use bitcoin_scripts::address::AddressCompat;

#[cfg(not(feature = "miniscript"))]
pub mod miniscript {
Expand Down Expand Up @@ -59,7 +60,7 @@ pub trait Descriptor<Key> {
secp: &Secp256k1<C>,
pat: impl AsRef<[UnhardenedIndex]>,
regtest: bool,
) -> Result<Address, DeriveError>;
) -> Result<AddressCompat, DeriveError>;

/// Creates scriptPubkey for specific derive pattern in pre-taproot
/// descriptors
Expand All @@ -84,6 +85,7 @@ mod ms {
use bitcoin::XOnlyPublicKey;
use bitcoin_hd::account::DerivePublicKey;
use bitcoin_hd::{DeriveError, SegmentIndexes};
use bitcoin_scripts::address::{AddressCompat, AddressNetwork};
use miniscript::{translate_hash_fail, ForEachKey, TranslatePk, Translator};

use super::*;
Expand Down Expand Up @@ -215,10 +217,11 @@ mod ms {
secp: &Secp256k1<C>,
pat: impl AsRef<[UnhardenedIndex]>,
regtest: bool,
) -> Result<Address, DeriveError> {
let network = self.network(regtest)?;
) -> Result<AddressCompat, DeriveError> {
let network = AddressNetwork::from(self.network(regtest)?);
let spk = Descriptor::script_pubkey_pretr(self, secp, pat)?;
Address::from_script(&spk, network).map_err(|_| DeriveError::NoAddressForDescriptor)
AddressCompat::from_script(&spk.into(), network)
.ok_or(DeriveError::NoAddressForDescriptor)
}

#[inline]
Expand Down
5 changes: 4 additions & 1 deletion src/bin/btc-cold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ use bitcoin::{consensus, Address, Network};
use bitcoin_blockchain::locks::LockTime;
use bitcoin_hd::DeriveError;
use bitcoin_onchain::UtxoResolverError;
use bitcoin_scripts::address::AddressCompat;
use bitcoin_scripts::taproot::DfsPath;
use bitcoin_scripts::PubkeyScript;
use clap::Parser;
Expand Down Expand Up @@ -526,7 +527,9 @@ impl Args {
count += utxo_set.len();

let derive_term = format!("{}/{}", case, index);
if let Ok(address) = Address::from_script(&script, network) {
if let Some(address) =
AddressCompat::from_script(&script.clone().into(), network.into())
{
println!(
"\n {} address {}:",
derive_term.bright_white(),
Expand Down