commit
630416c6de
5 changed files with 6356 additions and 0 deletions
@ -0,0 +1 @@ |
|||||||
|
**/target |
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,13 @@ |
|||||||
|
[package] |
||||||
|
name = "sol-json-rpc-1" |
||||||
|
version = "0.1.0" |
||||||
|
edition = "2024" |
||||||
|
|
||||||
|
[dependencies] |
||||||
|
config = "0.15.11" |
||||||
|
futures = "0.3.31" |
||||||
|
serde = { version = "1.0.219", features = ["derive"] } |
||||||
|
serde_json = "1.0.140" |
||||||
|
solana-client = "2.2.7" |
||||||
|
solana-sdk = "2.2.2" |
||||||
|
tokio = { version = "1.45.0", features = ["macros", "rt-multi-thread"] } |
@ -0,0 +1,3 @@ |
|||||||
|
accounts: |
||||||
|
- 83astBRguLMdt2h5U1Tpdq5tjFoJ6noeGwaY3mDLVcri |
||||||
|
solana_url: https://api.devnet.solana.com |
@ -0,0 +1,51 @@ |
|||||||
|
use std::{error::Error, str::FromStr, sync::Arc}; |
||||||
|
|
||||||
|
use config::Config; |
||||||
|
use futures::future::join_all; |
||||||
|
use serde::Deserialize; |
||||||
|
use solana_client::nonblocking::rpc_client::RpcClient; |
||||||
|
use solana_sdk::{ |
||||||
|
commitment_config::CommitmentConfig, native_token::LAMPORTS_PER_SOL, pubkey::Pubkey, |
||||||
|
}; |
||||||
|
|
||||||
|
#[derive(Deserialize)] |
||||||
|
struct Cfg { |
||||||
|
accounts: Vec<String>, |
||||||
|
solana_url: String, |
||||||
|
} |
||||||
|
|
||||||
|
#[tokio::main] |
||||||
|
async fn main() -> Result<(), Box<dyn Error>> { |
||||||
|
let config = { |
||||||
|
let config_parser = Config::builder() |
||||||
|
.add_source(config::File::with_name("config.yaml")) |
||||||
|
.build()?; |
||||||
|
|
||||||
|
config_parser.try_deserialize::<Cfg>()? |
||||||
|
}; |
||||||
|
let client = Arc::new(RpcClient::new_with_commitment( |
||||||
|
config.solana_url.clone(), |
||||||
|
CommitmentConfig::confirmed(), |
||||||
|
)); |
||||||
|
|
||||||
|
let mut fetchers = vec![]; |
||||||
|
for account in &config.accounts { |
||||||
|
let client = client.clone(); |
||||||
|
fetchers.push(async move { |
||||||
|
let pubkey = Pubkey::from_str(&account)?; |
||||||
|
let balance = client.get_balance(&pubkey).await?; |
||||||
|
Ok::<_, Box<dyn Error>>(balance as f64 / LAMPORTS_PER_SOL as f64) |
||||||
|
}); |
||||||
|
} |
||||||
|
|
||||||
|
let balances = join_all(fetchers) |
||||||
|
.await |
||||||
|
.into_iter() |
||||||
|
.collect::<Result<Vec<_>, _>>()?; |
||||||
|
|
||||||
|
for (acc, bal) in config.accounts.iter().zip(balances.iter()) { |
||||||
|
println!("{acc}: {bal}"); |
||||||
|
} |
||||||
|
|
||||||
|
Ok(()) |
||||||
|
} |
Loading…
Reference in new issue