rustfmt
This commit is contained in:
parent
3ceaa33de0
commit
95af38a01d
@ -401,11 +401,10 @@ impl SignersContainer {
|
|||||||
|
|
||||||
/// Finds the signer with lowest ordering for a given id in the container.
|
/// Finds the signer with lowest ordering for a given id in the container.
|
||||||
pub fn find(&self, id: SignerId) -> Option<&Arc<dyn Signer>> {
|
pub fn find(&self, id: SignerId) -> Option<&Arc<dyn Signer>> {
|
||||||
self.0.iter()
|
self.0
|
||||||
|
.iter()
|
||||||
.filter(|(key, _)| key.id == id)
|
.filter(|(key, _)| key.id == id)
|
||||||
.min_by(|(k_a, _), (k_b, _)| {
|
.min_by(|(k_a, _), (k_b, _)| k_a.cmp(k_b))
|
||||||
k_a.cmp(k_b)
|
|
||||||
})
|
|
||||||
.map(|(_, v)| v)
|
.map(|(_, v)| v)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -530,14 +529,14 @@ impl Ord for SignersContainerKey {
|
|||||||
mod signers_container_tests {
|
mod signers_container_tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::descriptor;
|
use crate::descriptor;
|
||||||
use miniscript::ScriptContext;
|
|
||||||
use crate::keys::{DescriptorKey, ToDescriptorKey};
|
|
||||||
use bitcoin::util::bip32;
|
|
||||||
use bitcoin::secp256k1::All;
|
|
||||||
use std::str::FromStr;
|
|
||||||
use crate::descriptor::ToWalletDescriptor;
|
use crate::descriptor::ToWalletDescriptor;
|
||||||
use bitcoin::Network;
|
use crate::keys::{DescriptorKey, ToDescriptorKey};
|
||||||
|
use bitcoin::secp256k1::All;
|
||||||
|
use bitcoin::util::bip32;
|
||||||
use bitcoin::util::psbt::PartiallySignedTransaction;
|
use bitcoin::util::psbt::PartiallySignedTransaction;
|
||||||
|
use bitcoin::Network;
|
||||||
|
use miniscript::ScriptContext;
|
||||||
|
use std::str::FromStr;
|
||||||
|
|
||||||
// Signers added with the same ordering (like `Ordering::default`) created from `KeyMap`
|
// Signers added with the same ordering (like `Ordering::default`) created from `KeyMap`
|
||||||
// should be preserved and not overwritten.
|
// should be preserved and not overwritten.
|
||||||
@ -563,9 +562,21 @@ mod signers_container_tests {
|
|||||||
let signer2 = Arc::new(DummySigner);
|
let signer2 = Arc::new(DummySigner);
|
||||||
let signer3 = Arc::new(DummySigner);
|
let signer3 = Arc::new(DummySigner);
|
||||||
|
|
||||||
signers.add_external(SignerId::Fingerprint(b"cafe"[..].into()), SignerOrdering(1), signer1.clone());
|
signers.add_external(
|
||||||
signers.add_external(SignerId::Fingerprint(b"babe"[..].into()), SignerOrdering(2), signer2.clone());
|
SignerId::Fingerprint(b"cafe"[..].into()),
|
||||||
signers.add_external(SignerId::Fingerprint(b"feed"[..].into()), SignerOrdering(3), signer3.clone());
|
SignerOrdering(1),
|
||||||
|
signer1.clone(),
|
||||||
|
);
|
||||||
|
signers.add_external(
|
||||||
|
SignerId::Fingerprint(b"babe"[..].into()),
|
||||||
|
SignerOrdering(2),
|
||||||
|
signer2.clone(),
|
||||||
|
);
|
||||||
|
signers.add_external(
|
||||||
|
SignerId::Fingerprint(b"feed"[..].into()),
|
||||||
|
SignerOrdering(3),
|
||||||
|
signer3.clone(),
|
||||||
|
);
|
||||||
|
|
||||||
// Check that signers are sorted from lowest to highest ordering
|
// Check that signers are sorted from lowest to highest ordering
|
||||||
let signers = signers.signers();
|
let signers = signers.signers();
|
||||||
@ -591,14 +602,22 @@ mod signers_container_tests {
|
|||||||
signers.add_external(id2.clone(), SignerOrdering(2), signer2.clone());
|
signers.add_external(id2.clone(), SignerOrdering(2), signer2.clone());
|
||||||
signers.add_external(id3.clone(), SignerOrdering(3), signer3.clone());
|
signers.add_external(id3.clone(), SignerOrdering(3), signer3.clone());
|
||||||
|
|
||||||
assert!(matches!(signers.find(id1), Some(signer) if Arc::as_ptr(&signer1) == Arc::as_ptr(signer)));
|
assert!(
|
||||||
assert!(matches!(signers.find(id2), Some(signer) if Arc::as_ptr(&signer2) == Arc::as_ptr(signer)));
|
matches!(signers.find(id1), Some(signer) if Arc::as_ptr(&signer1) == Arc::as_ptr(signer))
|
||||||
assert!(matches!(signers.find(id3.clone()), Some(signer) if Arc::as_ptr(&signer3) == Arc::as_ptr(signer)));
|
);
|
||||||
|
assert!(
|
||||||
|
matches!(signers.find(id2), Some(signer) if Arc::as_ptr(&signer2) == Arc::as_ptr(signer))
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
matches!(signers.find(id3.clone()), Some(signer) if Arc::as_ptr(&signer3) == Arc::as_ptr(signer))
|
||||||
|
);
|
||||||
|
|
||||||
// The `signer4` has the same ID as `signer3` but lower ordering.
|
// The `signer4` has the same ID as `signer3` but lower ordering.
|
||||||
// It should be found by `id3` instead of `signer3`.
|
// It should be found by `id3` instead of `signer3`.
|
||||||
signers.add_external(id3.clone(), SignerOrdering(2), signer4.clone());
|
signers.add_external(id3.clone(), SignerOrdering(2), signer4.clone());
|
||||||
assert!(matches!(signers.find(id3), Some(signer) if Arc::as_ptr(&signer4) == Arc::as_ptr(signer)));
|
assert!(
|
||||||
|
matches!(signers.find(id3), Some(signer) if Arc::as_ptr(&signer4) == Arc::as_ptr(signer))
|
||||||
|
);
|
||||||
|
|
||||||
// Can't find anything with ID that doesn't exist
|
// Can't find anything with ID that doesn't exist
|
||||||
assert!(matches!(signers.find(id_nonexistent), None));
|
assert!(matches!(signers.find(id_nonexistent), None));
|
||||||
@ -607,7 +626,12 @@ mod signers_container_tests {
|
|||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct DummySigner;
|
struct DummySigner;
|
||||||
impl Signer for DummySigner {
|
impl Signer for DummySigner {
|
||||||
fn sign(&self, _psbt: &mut PartiallySignedTransaction, _input_index: Option<usize>, _secp: &SecpCtx) -> Result<(), SignerError> {
|
fn sign(
|
||||||
|
&self,
|
||||||
|
_psbt: &mut PartiallySignedTransaction,
|
||||||
|
_input_index: Option<usize>,
|
||||||
|
_secp: &SecpCtx,
|
||||||
|
) -> Result<(), SignerError> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user