Rename KeypairUtil to Signer (#8360)

automerge
This commit is contained in:
Tyera Eulberg
2020-02-20 14:28:55 -07:00
committed by GitHub
parent ec5c02cb7f
commit ab361a8073
108 changed files with 138 additions and 140 deletions

View File

@ -10,7 +10,7 @@ use crate::{
poh_config::PohConfig,
pubkey::Pubkey,
rent::Rent,
signature::{Keypair, KeypairUtil},
signature::{Keypair, Signer},
system_program::{self, solana_system_program},
};
use bincode::{deserialize, serialize};
@ -176,7 +176,7 @@ impl GenesisConfig {
#[cfg(test)]
mod tests {
use super::*;
use crate::signature::{Keypair, KeypairUtil};
use crate::signature::{Keypair, Signer};
use std::path::PathBuf;
fn make_tmp_path(name: &str) -> PathBuf {

View File

@ -253,7 +253,7 @@ mod tests {
use super::*;
use crate::{
instruction::AccountMeta,
signature::{Keypair, KeypairUtil},
signature::{Keypair, Signer},
};
#[test]

View File

@ -128,7 +128,7 @@ impl FromStr for Signature {
}
}
pub trait KeypairUtil {
pub trait Signer {
fn pubkey(&self) -> Pubkey {
self.try_pubkey().unwrap_or_default()
}
@ -139,7 +139,7 @@ pub trait KeypairUtil {
fn try_sign_message(&self, message: &[u8]) -> Result<Signature, Box<dyn error::Error>>;
}
impl KeypairUtil for Keypair {
impl Signer for Keypair {
/// Return the public key for the given keypair
fn pubkey(&self) -> Pubkey {
Pubkey::new(self.0.public.as_ref())
@ -160,7 +160,7 @@ impl KeypairUtil for Keypair {
impl<T> PartialEq<T> for Keypair
where
T: KeypairUtil,
T: Signer,
{
fn eq(&self, other: &T) -> bool {
self.pubkey() == other.pubkey()
@ -189,7 +189,7 @@ enum PresignerError {
VerificationFailure,
}
impl KeypairUtil for Presigner {
impl Signer for Presigner {
fn try_pubkey(&self) -> Result<Pubkey, Box<dyn error::Error>> {
Ok(self.pubkey)
}
@ -205,7 +205,7 @@ impl KeypairUtil for Presigner {
impl<T> PartialEq<T> for Presigner
where
T: KeypairUtil,
T: Signer,
{
fn eq(&self, other: &T) -> bool {
self.pubkey() == other.pubkey()
@ -427,7 +427,7 @@ mod tests {
let data = [1u8];
let sig = keypair.sign_message(&data);
// KeypairUtil
// Signer
assert_eq!(keypair.try_pubkey().unwrap(), pubkey);
assert_eq!(keypair.pubkey(), pubkey);
assert_eq!(keypair.try_sign_message(&data).unwrap(), sig);
@ -445,7 +445,7 @@ mod tests {
let data = [1u8];
let sig = keypair.sign_message(&data);
// KeypairUtil
// Signer
let presigner = Presigner::new(&pubkey, &sig);
assert_eq!(presigner.try_pubkey().unwrap(), pubkey);
assert_eq!(presigner.pubkey(), pubkey);

View File

@ -1,6 +1,6 @@
use crate::{
pubkey::Pubkey,
signature::{KeypairUtil, Signature},
signature::{Signature, Signer},
};
pub trait Signers {
@ -22,35 +22,35 @@ macro_rules! default_keypairs_impl {
);
}
impl<T: KeypairUtil> Signers for [&T] {
impl<T: Signer> Signers for [&T] {
default_keypairs_impl!();
}
impl Signers for [Box<dyn KeypairUtil>] {
impl Signers for [Box<dyn Signer>] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for [&T; 0] {
impl<T: Signer> Signers for [&T; 0] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for [&T; 1] {
impl<T: Signer> Signers for [&T; 1] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for [&T; 2] {
impl<T: Signer> Signers for [&T; 2] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for [&T; 3] {
impl<T: Signer> Signers for [&T; 3] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for [&T; 4] {
impl<T: Signer> Signers for [&T; 4] {
default_keypairs_impl!();
}
impl<T: KeypairUtil> Signers for Vec<&T> {
impl<T: Signer> Signers for Vec<&T> {
default_keypairs_impl!();
}
@ -60,7 +60,7 @@ mod tests {
use std::error;
struct Foo;
impl KeypairUtil for Foo {
impl Signer for Foo {
fn try_pubkey(&self) -> Result<Pubkey, Box<dyn error::Error>> {
Ok(Pubkey::default())
}
@ -70,7 +70,7 @@ mod tests {
}
struct Bar;
impl KeypairUtil for Bar {
impl Signer for Bar {
fn try_pubkey(&self) -> Result<Pubkey, Box<dyn error::Error>> {
Ok(Pubkey::default())
}
@ -81,14 +81,14 @@ mod tests {
#[test]
fn test_dyn_keypairs_compile() {
let xs: Vec<Box<dyn KeypairUtil>> = vec![Box::new(Foo {}), Box::new(Bar {})];
let xs: Vec<Box<dyn Signer>> = vec![Box::new(Foo {}), Box::new(Bar {})];
assert_eq!(
xs.sign_message(b""),
vec![Signature::default(), Signature::default()],
);
// Same as above, but less compiler magic.
let xs_ref: &[Box<dyn KeypairUtil>] = &xs;
let xs_ref: &[Box<dyn Signer>] = &xs;
assert_eq!(
Signers::sign_message(xs_ref, b""),
vec![Signature::default(), Signature::default()],

View File

@ -3,7 +3,7 @@
use crate::{
hash::Hash,
pubkey::Pubkey,
signature::{Keypair, KeypairUtil},
signature::{Keypair, Signer},
system_instruction,
transaction::Transaction,
};

View File

@ -334,7 +334,7 @@ mod tests {
use crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, KeypairUtil},
signature::{Keypair, Signer},
system_instruction,
};
use bincode::{deserialize, serialize, serialized_size};