sdk: impl `Signer` for all containers (#32181)
* impl signer for all containers * trivial fixes --------- Co-authored-by: hanako mumei <81144685+2501babe@users.noreply.github.com>
This commit is contained in:
parent
adc17fd1e0
commit
ba7d892ebb
|
@ -2346,7 +2346,7 @@ mod tests {
|
||||||
Arc::new(validator_keypair),
|
Arc::new(validator_keypair),
|
||||||
&validator_ledger_path,
|
&validator_ledger_path,
|
||||||
&voting_keypair.pubkey(),
|
&voting_keypair.pubkey(),
|
||||||
Arc::new(RwLock::new(vec![voting_keypair.clone()])),
|
Arc::new(RwLock::new(vec![voting_keypair])),
|
||||||
vec![LegacyContactInfo::try_from(&leader_node.info).unwrap()],
|
vec![LegacyContactInfo::try_from(&leader_node.info).unwrap()],
|
||||||
&config,
|
&config,
|
||||||
true, // should_check_duplicate_instance
|
true, // should_check_duplicate_instance
|
||||||
|
|
|
@ -14,6 +14,7 @@ use {
|
||||||
error,
|
error,
|
||||||
fs::{self, File, OpenOptions},
|
fs::{self, File, OpenOptions},
|
||||||
io::{Read, Write},
|
io::{Read, Write},
|
||||||
|
ops::Deref,
|
||||||
path::Path,
|
path::Path,
|
||||||
},
|
},
|
||||||
thiserror::Error,
|
thiserror::Error,
|
||||||
|
@ -93,6 +94,29 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<Container: Deref<Target = impl Signer>> Signer for Container {
|
||||||
|
#[inline]
|
||||||
|
fn pubkey(&self) -> Pubkey {
|
||||||
|
self.deref().pubkey()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_pubkey(&self) -> Result<Pubkey, SignerError> {
|
||||||
|
self.deref().try_pubkey()
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sign_message(&self, message: &[u8]) -> Signature {
|
||||||
|
self.deref().sign_message(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, SignerError> {
|
||||||
|
self.deref().try_sign_message(message)
|
||||||
|
}
|
||||||
|
|
||||||
|
fn is_interactive(&self) -> bool {
|
||||||
|
self.deref().is_interactive()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl PartialEq for dyn Signer {
|
impl PartialEq for dyn Signer {
|
||||||
fn eq(&self, other: &dyn Signer) -> bool {
|
fn eq(&self, other: &dyn Signer) -> bool {
|
||||||
self.pubkey() == other.pubkey()
|
self.pubkey() == other.pubkey()
|
||||||
|
@ -188,4 +212,41 @@ mod tests {
|
||||||
pubkeys(&[&alice, &bob])
|
pubkeys(&[&alice, &bob])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_containers() {
|
||||||
|
use std::{rc::Rc, sync::Arc};
|
||||||
|
|
||||||
|
struct Foo<S: Signer> {
|
||||||
|
#[allow(unused)]
|
||||||
|
signer: S,
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo(_s: impl Signer) {}
|
||||||
|
|
||||||
|
let _arc_signer = Foo {
|
||||||
|
signer: Arc::new(Keypair::new()),
|
||||||
|
};
|
||||||
|
foo(Arc::new(Keypair::new()));
|
||||||
|
|
||||||
|
let _rc_signer = Foo {
|
||||||
|
signer: Rc::new(Keypair::new()),
|
||||||
|
};
|
||||||
|
foo(Rc::new(Keypair::new()));
|
||||||
|
|
||||||
|
let _ref_signer = Foo {
|
||||||
|
signer: &Keypair::new(),
|
||||||
|
};
|
||||||
|
foo(&Keypair::new());
|
||||||
|
|
||||||
|
let _box_signer = Foo {
|
||||||
|
signer: Box::new(Keypair::new()),
|
||||||
|
};
|
||||||
|
foo(Box::new(Keypair::new()));
|
||||||
|
|
||||||
|
let _signer = Foo {
|
||||||
|
signer: Keypair::new(),
|
||||||
|
};
|
||||||
|
foo(Keypair::new());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue