//! ```
use std::cmp::Ordering;
-use std::collections::BTreeMap;
+use std::collections::HashMap;
use std::fmt;
-use std::ops::Bound::Included;
use std::sync::Arc;
use bitcoin::blockdata::opcodes;
return Err(SignerError::InputIndexOutOfRange);
}
+ println!("Partial sigs: {:?}", psbt.inputs[input_index].partial_sigs);
+
let pubkey = self.public_key(&secp);
if psbt.inputs[input_index].partial_sigs.contains_key(&pubkey) {
return Ok(());
/// The default value is `100`. Signers with an ordering above that will be called later,
/// and they will thus see the partial signatures added to the transaction once they get to sign
/// themselves.
-#[derive(Debug, Clone, PartialOrd, PartialEq, Ord, Eq)]
+#[derive(Debug, Clone, Hash, PartialOrd, PartialEq, Ord, Eq)]
pub struct SignerOrdering(pub usize);
impl std::default::Default for SignerOrdering {
}
}
-#[derive(Debug, Clone)]
+#[derive(Debug, Clone, Hash, Eq, PartialEq)]
struct SignersContainerKey {
id: SignerId,
ordering: SignerOrdering,
/// Container for multiple signers
#[derive(Debug, Default, Clone)]
-pub struct SignersContainer(BTreeMap<SignersContainerKey, Arc<dyn Signer>>);
+pub struct SignersContainer(HashMap<SignersContainerKey, Arc<dyn Signer>>);
impl SignersContainer {
pub fn as_key_map(&self, secp: &SecpCtx) -> KeyMap {
let mut container = SignersContainer::new();
for (_, secret) in keymap {
- match secret {
+ let previous = match secret {
DescriptorSecretKey::SinglePriv(private_key) => container.add_external(
SignerId::from(
private_key
Arc::new(xprv),
),
};
+
+ if let Some(previous) = previous {
+ println!("This signer was replaced: {:?}", previous)
+ }
}
container
ordering: SignerOrdering,
signer: Arc<dyn Signer>,
) -> Option<Arc<dyn Signer>> {
- self.0.insert((id, ordering).into(), signer)
+
+ println!("Adding external signer ID = {:?}", id);
+ let key = (id, ordering).into();
+ println!("With a key: {:?}", key);
+ let res = self.0.insert(key, signer);
+ println!("After insertion, len = {}", self.0.values().len());
+ res
}
/// Removes a signer from the container and returns it
/// Returns the list of signers in the container, sorted by lowest to highest `ordering`
pub fn signers(&self) -> Vec<&Arc<dyn Signer>> {
- self.0.values().collect()
+ let mut items = self.0.iter().collect::<Vec<_>>();
+ items.sort_by(|(a, _), (b, _)| (*a).cmp(*b));
+
+ items.into_iter().map(|(_, v)| v).collect()
}
/// Finds the signer with lowest ordering for a given id in the container.
pub fn find(&self, id: SignerId) -> Option<&Arc<dyn Signer>> {
- self.0
- .range((
- Included(&(id.clone(), SignerOrdering(0)).into()),
- Included(&(id, SignerOrdering(usize::MAX)).into()),
- ))
+ self.0.iter()
+ .filter(|(key, _)| key.id == id)
+ .min_by(|(k_a, _), (k_b, _)| {
+ k_a.cmp(k_b)
+ })
.map(|(_, v)| v)
- .next()
}
}
self.ordering.cmp(&other.ordering)
}
}
-
-impl PartialEq for SignersContainerKey {
- fn eq(&self, other: &Self) -> bool {
- self.ordering == other.ordering
- }
-}
-
-impl Eq for SignersContainerKey {}