Skip to content

Commit

Permalink
read solana keypair, convert to helium keypair (#942)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
michaeldjeffrey authored Feb 13, 2025
1 parent 4ca713c commit 6e7b65b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions solana/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -50,10 +51,13 @@ pub mod sender;
pub mod start_boost;

pub fn read_keypair_from_file<F: AsRef<Path>>(path: F) -> anyhow::Result<Keypair> {
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)]
Expand Down

0 comments on commit 6e7b65b

Please sign in to comment.