diff --git a/Cargo.lock b/Cargo.lock index 565193d525..7e6566e795 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4648,7 +4648,6 @@ name = "solana-stake-accounts" version = "1.2.0" dependencies = [ "clap", - "itertools 0.9.0", "solana-clap-utils", "solana-cli-config", "solana-client", @@ -4743,7 +4742,6 @@ dependencies = [ "dirs 2.0.2", "indexmap", "indicatif", - "itertools 0.9.0", "pickledb", "serde", "solana-clap-utils", diff --git a/sdk/src/signature.rs b/sdk/src/signature.rs index 7ccd721178..84bf86e0ab 100644 --- a/sdk/src/signature.rs +++ b/sdk/src/signature.rs @@ -3,6 +3,7 @@ use crate::{pubkey::Pubkey, transaction::TransactionError}; use generic_array::{typenum::U64, GenericArray}; use hmac::Hmac; +use itertools::Itertools; use rand::{rngs::OsRng, CryptoRng, RngCore}; use std::{ borrow::{Borrow, Cow}, @@ -155,6 +156,11 @@ impl std::fmt::Debug for dyn Signer { } } +/// Remove duplicates signers while preserving order. O(n²) +pub fn unique_signers(signers: Vec<&dyn Signer>) -> Vec<&dyn Signer> { + signers.into_iter().unique_by(|s| s.pubkey()).collect() +} + impl Signer for Keypair { /// Return the public key for the given keypair fn pubkey(&self) -> Pubkey { @@ -553,4 +559,18 @@ mod tests { let presigner2 = Presigner::new(&pubkey, &sig); assert_eq!(presigner, presigner2); } + + fn pubkeys(signers: &[&dyn Signer]) -> Vec { + signers.into_iter().map(|x| x.pubkey()).collect() + } + + #[test] + fn test_unique_signers() { + let alice = Keypair::new(); + let bob = Keypair::new(); + assert_eq!( + pubkeys(&unique_signers(vec![&alice, &bob, &alice])), + pubkeys(&[&alice, &bob]) + ); + } } diff --git a/stake-accounts/Cargo.toml b/stake-accounts/Cargo.toml index 89d200b2b4..60a1d3e457 100644 --- a/stake-accounts/Cargo.toml +++ b/stake-accounts/Cargo.toml @@ -10,7 +10,6 @@ homepage = "https://solana.com/" [dependencies] clap = "2.33.1" -itertools = "0.9.0" solana-clap-utils = { path = "../clap-utils", version = "1.2.0" } solana-cli-config = { path = "../cli-config", version = "1.2.0" } solana-client = { path = "../client", version = "1.2.0" } diff --git a/stake-accounts/src/main.rs b/stake-accounts/src/main.rs index a5590debcc..202ae6cd3c 100644 --- a/stake-accounts/src/main.rs +++ b/stake-accounts/src/main.rs @@ -6,7 +6,6 @@ use crate::arg_parser::parse_args; use crate::args::{ resolve_command, AuthorizeArgs, Command, MoveArgs, NewArgs, RebaseArgs, SetLockupArgs, }; -use itertools::Itertools; use solana_cli_config::Config; use solana_client::client_error::ClientError; use solana_client::rpc_client::RpcClient; @@ -14,7 +13,7 @@ use solana_sdk::{ message::Message, native_token::lamports_to_sol, pubkey::Pubkey, - signature::{Signature, Signer}, + signature::{unique_signers, Signature, Signer}, signers::Signers, transaction::Transaction, }; @@ -65,10 +64,6 @@ fn get_lockups( .collect() } -fn unique_signers(signers: Vec<&dyn Signer>) -> Vec<&dyn Signer> { - signers.into_iter().unique_by(|s| s.pubkey()).collect_vec() -} - fn process_new_stake_account( client: &RpcClient, args: &NewArgs>, diff --git a/tokens/Cargo.toml b/tokens/Cargo.toml index 1cbbc4a4c3..4c2021861f 100644 --- a/tokens/Cargo.toml +++ b/tokens/Cargo.toml @@ -16,7 +16,6 @@ csv = "1.1.3" dirs = "2.0.2" indexmap = "1.3.2" indicatif = "0.14.0" -itertools = "0.9.0" pickledb = "0.4.1" serde = { version = "1.0", features = ["derive"] } solana-clap-utils = { path = "../clap-utils", version = "1.2.0" } diff --git a/tokens/src/commands.rs b/tokens/src/commands.rs index 6d7a94d85d..c5b5f453c9 100644 --- a/tokens/src/commands.rs +++ b/tokens/src/commands.rs @@ -5,13 +5,12 @@ use console::style; use csv::{ReaderBuilder, Trim}; use indexmap::IndexMap; use indicatif::{ProgressBar, ProgressStyle}; -use itertools::Itertools; use pickledb::PickleDb; use serde::{Deserialize, Serialize}; use solana_sdk::{ message::Message, native_token::{lamports_to_sol, sol_to_lamports}, - signature::{Signature, Signer}, + signature::{unique_signers, Signature, Signer}, system_instruction, transport::TransportError, }; @@ -48,12 +47,6 @@ pub enum Error { PickleDbError(#[from] pickledb::error::Error), #[error("Transport error")] TransportError(#[from] TransportError), - #[error("Signature not found")] - SignatureNotFound, -} - -fn unique_signers(signers: Vec<&dyn Signer>) -> Vec<&dyn Signer> { - signers.into_iter().unique_by(|s| s.pubkey()).collect_vec() } fn merge_allocations(allocations: &[Allocation]) -> Vec { @@ -343,11 +336,11 @@ fn update_finalized_transactions( } }) .collect(); - let unconfirmed_signatures = unconfirmed_transactions + let unconfirmed_signatures: Vec<_> = unconfirmed_transactions .iter() .map(|tx| tx.signatures[0]) .filter(|sig| *sig != Signature::default()) // Filter out dry-run signatures - .collect_vec(); + .collect(); let transaction_statuses = client.get_signature_statuses(&unconfirmed_signatures)?; let recent_blockhashes = client.get_recent_blockhashes()?;