From d97c05b9bd752a6bce42eade823df673772b78fb Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Wed, 4 Dec 2024 18:38:58 -0500 Subject: [PATCH] api: fix fee_average (#24) --- CHANGELOG.md | 4 ++++ Cargo.lock | 14 +++++++------- deny.toml | 8 ++++---- solfees-be/Cargo.toml | 2 +- solfees-be/src/bin/solfees-ws-client.rs | 16 +++++++++++++--- solfees-be/src/rpc_solana.rs | 10 +++++++--- 6 files changed, 36 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c90b623..7357822 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,10 @@ The minor version will be incremented upon a breaking change and the patch versi ### Breaking +## [3.0.1] - 2024-12-04 + +- api: fix fee_average ([#24](https://github.com/solana-stream-solutions/solfees/pull/24)) + ## [3.0.0] - 2024-11-24 ### Breaking diff --git a/Cargo.lock b/Cargo.lock index 47de501..5f004af 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3232,7 +3232,7 @@ dependencies = [ "num-bigint 0.4.6", "percent-encoding", "pin-project-lite", - "rustls 0.23.16", + "rustls 0.23.19", "rustls-native-certs 0.7.3", "rustls-pemfile 2.2.0", "rustls-pki-types", @@ -3465,9 +3465,9 @@ dependencies = [ [[package]] name = "rustls" -version = "0.23.16" +version = "0.23.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eee87ff5d9b36712a58574e12e9f0ea80f915a5b0ac518d322b24a465617925e" +checksum = "934b404430bb06b3fae2cba809eb45a1ab1aecd64491213d7c3301b88393f8d1" dependencies = [ "log", "once_cell", @@ -4636,7 +4636,7 @@ dependencies = [ [[package]] name = "solfees-be" -version = "3.0.0" +version = "3.0.1" dependencies = [ "anyhow", "bincode", @@ -5219,7 +5219,7 @@ version = "0.26.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0c7bc40d0e5a97695bb96e27995cd3a08538541b0a846f65bba7a359f36700d4" dependencies = [ - "rustls 0.23.16", + "rustls 0.23.19", "rustls-pki-types", "tokio", ] @@ -5643,9 +5643,9 @@ dependencies = [ [[package]] name = "url" -version = "2.5.3" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d157f1b96d14500ffdc1f10ba712e780825526c03d9a49b4d0324b0d9113ada" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", diff --git a/deny.toml b/deny.toml index 5267d25..1ed2ba5 100644 --- a/deny.toml +++ b/deny.toml @@ -15,11 +15,11 @@ ignore = [ # Advisory: https://rustsec.org/advisories/RUSTSEC-2022-0093 "RUSTSEC-2022-0093", - # proc-macro-error 1.0.4 - # Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0370 - "RUSTSEC-2024-0370", - # atty 0.2.14 # Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0375 "RUSTSEC-2024-0375", + + # derivative 2.2.0 + # Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0388 + "RUSTSEC-2024-0388", ] diff --git a/solfees-be/Cargo.toml b/solfees-be/Cargo.toml index 2c31471..1a93617 100644 --- a/solfees-be/Cargo.toml +++ b/solfees-be/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "solfees-be" -version = "3.0.0" +version = "3.0.1" authors = { workspace = true } edition = { workspace = true } description = "Backend of solfees.io" diff --git a/solfees-be/src/bin/solfees-ws-client.rs b/solfees-be/src/bin/solfees-ws-client.rs index 97557c5..e532f76 100644 --- a/solfees-be/src/bin/solfees-ws-client.rs +++ b/solfees-be/src/bin/solfees-ws-client.rs @@ -2,15 +2,17 @@ use { anyhow::Context, clap::Parser, futures::{future::TryFutureExt, stream::StreamExt}, + jsonrpc_core::Success as RpcSuccess, serde::Serialize, + solfees_be::rpc_solana::SlotsSubscribeOutput, tokio_tungstenite::{connect_async, tungstenite::protocol::Message}, - tracing::info, + tracing::{error, info}, }; #[derive(Debug, Clone, Parser)] #[clap(author, version, about)] struct Args { - #[clap(short, long, default_value_t = String::from("wss://api.solfees.io/api/solana/solfees/ws"))] + #[clap(short, long, default_value_t = String::from("wss://api.solfees.io/api/solfees/ws"))] endpoint: String, /// Select transactions where mentioned accounts are readWrite @@ -78,7 +80,15 @@ async fn main() -> anyhow::Result<()> { Some(Err(error)) => anyhow::bail!(error), None => anyhow::bail!("stream finished"), }; - info!("new message: {text}"); + let Ok(RpcSuccess { result, .. }) = serde_json::from_str::(&text) else { + error!("failed to parse message: {text}"); + continue; + }; + let Ok(output) = serde_json::from_value::(result) else { + error!("failed to parse result from message: {text}"); + continue; + }; + info!("new message: {output:?}"); } #[allow(unreachable_code)] Ok::<(), anyhow::Error>(()) diff --git a/solfees-be/src/rpc_solana.rs b/solfees-be/src/rpc_solana.rs index 1cf26f7..50bb4ec 100644 --- a/solfees-be/src/rpc_solana.rs +++ b/solfees-be/src/rpc_solana.rs @@ -1517,7 +1517,11 @@ impl From> for CollectedFees { impl CollectedFees { fn new(mut fees: Vec) -> Self { fees.sort_unstable(); - let average = fees.iter().map(|fee| *fee as f64).sum::() / fees.len() as f64; + let average = if fees.is_empty() { + 0f64 + } else { + fees.iter().map(|fee| *fee as f64).sum::() / fees.len() as f64 + }; Self { fees, average } } @@ -1622,9 +1626,9 @@ impl TryFrom for SlotSubscribeFilter { } } -#[derive(Debug, Serialize)] +#[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] -enum SlotsSubscribeOutput { +pub enum SlotsSubscribeOutput { #[serde(rename_all = "camelCase")] Status { slot: Slot,