Merge pull request #153 from blockworks-foundation/keypair_file_location_macos_fix

Keypair file location macos fix
This commit is contained in:
Aniket Prajapati 2023-06-23 19:58:23 +05:30 committed by GitHub
commit c0aca913f0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 5 deletions

View File

@ -19,4 +19,5 @@ rand = "0.8.5"
rand_chacha = "0.3.1" rand_chacha = "0.3.1"
futures = { workspace = true } futures = { workspace = true }
dashmap = { workspace = true } dashmap = { workspace = true }
lazy_static = "1.4.0"

View File

@ -13,21 +13,30 @@ use solana_sdk::{
transaction::Transaction, transaction::Transaction,
}; };
use std::{str::FromStr, time::Duration}; use std::{str::FromStr, time::Duration};
use std::path::PathBuf;
use lazy_static::lazy_static;
use tokio::time::Instant; use tokio::time::Instant;
const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr"; const MEMO_PROGRAM_ID: &str = "MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr";
const WAIT_LIMIT_IN_SECONDS: u64 = 60; const WAIT_LIMIT_IN_SECONDS: u64 = 60;
lazy_static! {
static ref USER_KEYPAIR: PathBuf = {
dirs::home_dir().unwrap()
.join(".config")
.join("solana")
.join("id.json")
};
}
pub struct BenchHelper; pub struct BenchHelper;
impl BenchHelper { impl BenchHelper {
pub async fn get_payer() -> anyhow::Result<Keypair> { pub async fn get_payer() -> anyhow::Result<Keypair> {
let mut config_dir = dirs::config_dir().context("Unable to get path to user config dir")?;
config_dir.push("solana"); let payer = tokio::fs::read_to_string(USER_KEYPAIR.as_path())
config_dir.push("id.json");
let payer = tokio::fs::read_to_string(config_dir.to_str().unwrap())
.await .await
.context("Error reading payer file")?; .context("Error reading payer file")?;
let payer: Vec<u8> = serde_json::from_str(&payer)?; let payer: Vec<u8> = serde_json::from_str(&payer)?;