Skip to content

Commit d97c05b

Browse files
authored
api: fix fee_average (#24)
1 parent 3ef8583 commit d97c05b

File tree

6 files changed

+36
-18
lines changed

6 files changed

+36
-18
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ The minor version will be incremented upon a breaking change and the patch versi
1616

1717
### Breaking
1818

19+
## [3.0.1] - 2024-12-04
20+
21+
- api: fix fee_average ([#24](https://github.com/solana-stream-solutions/solfees/pull/24))
22+
1923
## [3.0.0] - 2024-11-24
2024

2125
### Breaking

Cargo.lock

+7-7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

deny.toml

+4-4
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ ignore = [
1515
# Advisory: https://rustsec.org/advisories/RUSTSEC-2022-0093
1616
"RUSTSEC-2022-0093",
1717

18-
# proc-macro-error 1.0.4
19-
# Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0370
20-
"RUSTSEC-2024-0370",
21-
2218
# atty 0.2.14
2319
# Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0375
2420
"RUSTSEC-2024-0375",
21+
22+
# derivative 2.2.0
23+
# Advisory: https://rustsec.org/advisories/RUSTSEC-2024-0388
24+
"RUSTSEC-2024-0388",
2525
]

solfees-be/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "solfees-be"
3-
version = "3.0.0"
3+
version = "3.0.1"
44
authors = { workspace = true }
55
edition = { workspace = true }
66
description = "Backend of solfees.io"

solfees-be/src/bin/solfees-ws-client.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,17 @@ use {
22
anyhow::Context,
33
clap::Parser,
44
futures::{future::TryFutureExt, stream::StreamExt},
5+
jsonrpc_core::Success as RpcSuccess,
56
serde::Serialize,
7+
solfees_be::rpc_solana::SlotsSubscribeOutput,
68
tokio_tungstenite::{connect_async, tungstenite::protocol::Message},
7-
tracing::info,
9+
tracing::{error, info},
810
};
911

1012
#[derive(Debug, Clone, Parser)]
1113
#[clap(author, version, about)]
1214
struct Args {
13-
#[clap(short, long, default_value_t = String::from("wss://api.solfees.io/api/solana/solfees/ws"))]
15+
#[clap(short, long, default_value_t = String::from("wss://api.solfees.io/api/solfees/ws"))]
1416
endpoint: String,
1517

1618
/// Select transactions where mentioned accounts are readWrite
@@ -78,7 +80,15 @@ async fn main() -> anyhow::Result<()> {
7880
Some(Err(error)) => anyhow::bail!(error),
7981
None => anyhow::bail!("stream finished"),
8082
};
81-
info!("new message: {text}");
83+
let Ok(RpcSuccess { result, .. }) = serde_json::from_str::<RpcSuccess>(&text) else {
84+
error!("failed to parse message: {text}");
85+
continue;
86+
};
87+
let Ok(output) = serde_json::from_value::<SlotsSubscribeOutput>(result) else {
88+
error!("failed to parse result from message: {text}");
89+
continue;
90+
};
91+
info!("new message: {output:?}");
8292
}
8393
#[allow(unreachable_code)]
8494
Ok::<(), anyhow::Error>(())

solfees-be/src/rpc_solana.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,11 @@ impl From<Vec<u64>> for CollectedFees {
15171517
impl CollectedFees {
15181518
fn new(mut fees: Vec<u64>) -> Self {
15191519
fees.sort_unstable();
1520-
let average = fees.iter().map(|fee| *fee as f64).sum::<f64>() / fees.len() as f64;
1520+
let average = if fees.is_empty() {
1521+
0f64
1522+
} else {
1523+
fees.iter().map(|fee| *fee as f64).sum::<f64>() / fees.len() as f64
1524+
};
15211525
Self { fees, average }
15221526
}
15231527

@@ -1622,9 +1626,9 @@ impl TryFrom<ReqParamsSlotsSubscribeConfig> for SlotSubscribeFilter {
16221626
}
16231627
}
16241628

1625-
#[derive(Debug, Serialize)]
1629+
#[derive(Debug, Serialize, Deserialize)]
16261630
#[serde(rename_all = "camelCase")]
1627-
enum SlotsSubscribeOutput {
1631+
pub enum SlotsSubscribeOutput {
16281632
#[serde(rename_all = "camelCase")]
16291633
Status {
16301634
slot: Slot,

0 commit comments

Comments
 (0)