Skip to content

Commit

Permalink
api: fix fee_average (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid authored Dec 4, 2024
1 parent 3ef8583 commit d97c05b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 18 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
2 changes: 1 addition & 1 deletion solfees-be/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 13 additions & 3 deletions solfees-be/src/bin/solfees-ws-client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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::<RpcSuccess>(&text) else {
error!("failed to parse message: {text}");
continue;
};
let Ok(output) = serde_json::from_value::<SlotsSubscribeOutput>(result) else {
error!("failed to parse result from message: {text}");
continue;
};
info!("new message: {output:?}");
}
#[allow(unreachable_code)]
Ok::<(), anyhow::Error>(())
Expand Down
10 changes: 7 additions & 3 deletions solfees-be/src/rpc_solana.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,11 @@ impl From<Vec<u64>> for CollectedFees {
impl CollectedFees {
fn new(mut fees: Vec<u64>) -> Self {
fees.sort_unstable();
let average = fees.iter().map(|fee| *fee as f64).sum::<f64>() / fees.len() as f64;
let average = if fees.is_empty() {
0f64
} else {
fees.iter().map(|fee| *fee as f64).sum::<f64>() / fees.len() as f64
};
Self { fees, average }
}

Expand Down Expand Up @@ -1622,9 +1626,9 @@ impl TryFrom<ReqParamsSlotsSubscribeConfig> 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,
Expand Down

0 comments on commit d97c05b

Please sign in to comment.