impl 1 task

master
plazmoid 1 week ago
commit 630416c6de
  1. 1
      .gitignore
  2. 6288
      sol-json-rpc-1/Cargo.lock
  3. 13
      sol-json-rpc-1/Cargo.toml
  4. 3
      sol-json-rpc-1/config.yaml
  5. 51
      sol-json-rpc-1/src/main.rs

1
.gitignore vendored

@ -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…
Cancel
Save