descriptors: remove as_inner method

We'll change the semantic of the descriptor, so we need to make sure
nothing accesses it with the old semantic.
This commit is contained in:
Antoine Poinsot 2022-10-21 13:12:23 +02:00
parent 846d924792
commit f985fd7879
No known key found for this signature in database
GPG Key ID: E13FC145CD3F4304
2 changed files with 13 additions and 12 deletions

View File

@ -2,7 +2,7 @@ use crate::descriptors::InheritanceDescriptor;
use std::{net::SocketAddr, path::PathBuf, str::FromStr, time::Duration};
use miniscript::{bitcoin::Network, DescriptorPublicKey, ForEachKey};
use miniscript::bitcoin::Network;
use serde::{de, Deserialize, Deserializer, Serialize, Serializer};
@ -203,14 +203,7 @@ impl Config {
Network::Bitcoin => Network::Bitcoin,
_ => Network::Testnet,
};
let unexpected_net = self.main_descriptor.as_inner().for_each_key(|xpub| {
if let DescriptorPublicKey::XPub(xpub) = xpub {
xpub.xkey.network != expected_network
} else {
false
}
});
if unexpected_net {
if !self.main_descriptor.all_xpubs_net_is(expected_network) {
return Err(ConfigError::Unexpected(format!(
"Our bitcoin network is {} but one xpub is not for network {}",
self.bitcoin_config.network, expected_network

View File

@ -9,7 +9,8 @@ use miniscript::{
descriptor, hash256,
miniscript::{decode::Terminal, Miniscript},
policy::{Liftable, Semantic as SemanticPolicy},
translate_hash_clone, MiniscriptKey, ScriptContext, ToPublicKey, TranslatePk, Translator,
translate_hash_clone, ForEachKey, MiniscriptKey, ScriptContext, ToPublicKey, TranslatePk,
Translator,
};
use std::{collections::BTreeMap, convert::TryFrom, error, fmt, str, sync};
@ -315,8 +316,15 @@ impl InheritanceDescriptor {
)))
}
pub fn as_inner(&self) -> &descriptor::Descriptor<descriptor::DescriptorPublicKey> {
&self.0
/// Whether all xpubs contained in this descriptor are for the passed expected network.
pub fn all_xpubs_net_is(&self, expected_net: bitcoin::Network) -> bool {
self.0.for_each_key(|xpub| {
if let descriptor::DescriptorPublicKey::XPub(xpub) = xpub {
xpub.xkey.network == expected_net
} else {
false
}
})
}
/// Derive this descriptor at a given index.