From 6e7b65b2751dd71bb77863df68c383e2553d6c3d Mon Sep 17 00:00:00 2001 From: Michael Jeffrey Date: Thu, 13 Feb 2025 11:02:02 -0700 Subject: [PATCH] read solana keypair, convert to helium keypair (#942) There's currently no way to go directly from a solana Keypair to a helium-lib Keypair, except through a bytes translation. We should add the conversion to helium-lib. We need to be using helium-lib Keypairs because all the functions that construct transactions expect it. --- solana/src/lib.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/solana/src/lib.rs b/solana/src/lib.rs index a42824b56..961bc7438 100644 --- a/solana/src/lib.rs +++ b/solana/src/lib.rs @@ -1,6 +1,7 @@ use solana_client::{client_error::ClientError, rpc_client::SerializableTransaction}; use solana_sdk::pubkey::ParsePubkeyError; -use std::{fs::File, io::Read, path::Path, time::SystemTimeError}; +use solana_sdk::signature::read_keypair_file; +use std::{path::Path, time::SystemTimeError}; pub use helium_lib::{ dao::SubDao, @@ -50,10 +51,13 @@ pub mod sender; pub mod start_boost; pub fn read_keypair_from_file>(path: F) -> anyhow::Result { - let mut file = File::open(path.as_ref())?; - let mut sk_buf = [0u8; 64]; - file.read_exact(&mut sk_buf)?; - Ok(Keypair::try_from(&sk_buf)?) + let path = path.as_ref(); + let keypair = read_keypair_file(path).map_err(|_e| { + let path = path.display().to_string(); + SolanaRpcError::FailedToReadKeypairError(path) + })?; + let bytes = keypair.to_bytes(); + Ok(Keypair::try_from(&bytes)?) } #[derive(thiserror::Error, Debug)]