Rename KeypairUtil to Signer (#8360) (#8366)

automerge
This commit is contained in:
mergify[bot]
2020-02-20 16:30:43 -08:00
committed by GitHub
parent 29cdfd6bc9
commit 02877814fa
107 changed files with 218 additions and 208 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

@@ -249,8 +249,10 @@ impl Message {
#[cfg(test)]
mod tests {
use super::*;
use crate::instruction::AccountMeta;
use crate::signature::{Keypair, KeypairUtil};
use crate::{
instruction::AccountMeta,
signature::{Keypair, Signer},
};
#[test]
fn test_message_unique_program_ids() {

View File

@@ -131,7 +131,7 @@ impl FromStr for Signature {
}
}
pub trait KeypairUtil {
pub trait Signer {
fn pubkey(&self) -> Pubkey {
self.try_pubkey().unwrap_or_default()
}
@@ -142,7 +142,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())
@@ -163,7 +163,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()
@@ -192,7 +192,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)
}
@@ -208,7 +208,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()
@@ -430,7 +430,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);
@@ -448,7 +448,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

@@ -331,10 +331,12 @@ impl Transaction {
#[cfg(test)]
mod tests {
use super::*;
use crate::hash::hash;
use crate::instruction::AccountMeta;
use crate::signature::{Keypair, KeypairUtil};
use crate::system_instruction;
use crate::{
hash::hash,
instruction::AccountMeta,
signature::{Keypair, Signer},
system_instruction,
};
use bincode::{deserialize, serialize, serialized_size};
use std::mem::size_of;