Skip to content

Commit

Permalink
client: add GeyserGrpcBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
fanatid committed Mar 30, 2024
1 parent 9981285 commit b187007
Show file tree
Hide file tree
Showing 11 changed files with 344 additions and 197 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ The minor version will be incremented upon a breaking change and the patch versi

### Breaking

- client: add `GeyserGrpcBuilder` ([#307](https://github.com/rpcpool/yellowstone-grpc/pull/307))

## 2024-03-20

- yellowstone-grpc-client-1.14.0+solana.1.18.7
Expand Down
5 changes: 2 additions & 3 deletions Cargo.lock

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

6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[workspace]
resolver = "2"
members = [
"examples/rust", # 1.12.0+solana.1.18.7
"yellowstone-grpc-client", # 1.14.0+solana.1.18.7
"examples/rust", # 1.13.0+solana.1.18.7
"yellowstone-grpc-client", # 1.15.0+solana.1.18.7
"yellowstone-grpc-geyser", # 1.13.0+solana.1.18.7
"yellowstone-grpc-proto", # 1.13.0+solana.1.18.7
"yellowstone-grpc-tools", # 1.0.0-rc.10+solana.1.18.7
Expand Down Expand Up @@ -66,7 +66,7 @@ tonic-health = "0.10.2"
tracing = "0.1.37"
tracing-subscriber = "0.3.17"
vergen = "8.2.1"
yellowstone-grpc-client = { path = "yellowstone-grpc-client", version = "=1.14.0+solana.1.18.7" }
yellowstone-grpc-client = { path = "yellowstone-grpc-client", version = "=1.15.0+solana.1.18.7" }
yellowstone-grpc-proto = { path = "yellowstone-grpc-proto", version = "=1.13.0+solana.1.18.7" }

[profile.release]
Expand Down
2 changes: 1 addition & 1 deletion examples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-client-simple"
version = "1.12.0+solana.1.18.7"
version = "1.13.0+solana.1.18.7"
authors = { workspace = true }
edition = { workspace = true }
homepage = { workspace = true }
Expand Down
47 changes: 23 additions & 24 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@ use {
solana_transaction_status::{EncodedTransactionWithStatusMeta, UiTransactionEncoding},
std::{collections::HashMap, env, fmt, fs::File, sync::Arc, time::Duration},
tokio::sync::Mutex,
yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError},
yellowstone_grpc_proto::{
prelude::{
subscribe_request_filter_accounts_filter::Filter as AccountsFilterDataOneof,
subscribe_request_filter_accounts_filter_memcmp::Data as AccountsFilterMemcmpOneof,
subscribe_update::UpdateOneof, CommitmentLevel, SubscribeRequest,
SubscribeRequestAccountsDataSlice, SubscribeRequestFilterAccounts,
SubscribeRequestFilterAccountsFilter, SubscribeRequestFilterAccountsFilterMemcmp,
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
SubscribeRequestFilterEntry, SubscribeRequestFilterSlots,
SubscribeRequestFilterTransactions, SubscribeRequestPing, SubscribeUpdateAccount,
SubscribeUpdateTransaction,
},
tonic::service::Interceptor,
yellowstone_grpc_client::{GeyserGrpcClient, GeyserGrpcClientError, Interceptor},
yellowstone_grpc_proto::prelude::{
subscribe_request_filter_accounts_filter::Filter as AccountsFilterDataOneof,
subscribe_request_filter_accounts_filter_memcmp::Data as AccountsFilterMemcmpOneof,
subscribe_update::UpdateOneof, CommitmentLevel, SubscribeRequest,
SubscribeRequestAccountsDataSlice, SubscribeRequestFilterAccounts,
SubscribeRequestFilterAccountsFilter, SubscribeRequestFilterAccountsFilterMemcmp,
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
SubscribeRequestFilterEntry, SubscribeRequestFilterSlots,
SubscribeRequestFilterTransactions, SubscribeRequestPing, SubscribeUpdateAccount,
SubscribeUpdateTransaction,
},
};

Expand Down Expand Up @@ -53,6 +50,17 @@ impl Args {
fn get_commitment(&self) -> Option<CommitmentLevel> {
Some(self.commitment.unwrap_or_default().into())
}

async fn connect(&self) -> anyhow::Result<GeyserGrpcClient<impl Interceptor>> {
GeyserGrpcClient::build_from_shared(self.endpoint.clone())?
.x_token(self.x_token.clone())?
.connect_timeout(Duration::from_secs(10))
.timeout(Duration::from_secs(10))
.connect()
.await?
.build()
.map_err(Into::into)
}
}

#[derive(Debug, Clone, Copy, Default, ValueEnum)]
Expand Down Expand Up @@ -450,16 +458,7 @@ async fn main() -> anyhow::Result<()> {
drop(zero_attempts);

let commitment = args.get_commitment();
let mut client = GeyserGrpcClient::connect_with_timeout(
args.endpoint,
args.x_token,
None,
Some(Duration::from_secs(10)),
Some(Duration::from_secs(10)),
false,
)
.await
.map_err(|e| backoff::Error::transient(anyhow::Error::new(e)))?;
let mut client = args.connect().await.map_err(backoff::Error::transient)?;
info!("Connected");

match &args.action {
Expand Down
6 changes: 5 additions & 1 deletion examples/rust/src/bin/subscribe-ping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ async fn main() -> anyhow::Result<()> {

let args = Args::parse();

let mut client = GeyserGrpcClient::connect(args.endpoint, args.x_token, None)?;
let mut client = GeyserGrpcClient::build_from_shared(args.endpoint)?
.x_token(args.x_token)?
.connect()
.await?
.build()?;
let (mut subscribe_tx, mut stream) = client.subscribe().await?;

futures::try_join!(
Expand Down
6 changes: 5 additions & 1 deletion examples/rust/src/bin/tx-blocktime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,11 @@ async fn main() -> anyhow::Result<()> {

let args = Args::parse();

let mut client = GeyserGrpcClient::connect(args.endpoint, args.x_token, None)?;
let mut client = GeyserGrpcClient::build_from_shared(args.endpoint)?
.x_token(args.x_token)?
.connect()
.await?
.build()?;
let (mut subscribe_tx, mut stream) = client.subscribe().await?;

let commitment: CommitmentLevel = args.commitment.unwrap_or_default().into();
Expand Down
3 changes: 1 addition & 2 deletions yellowstone-grpc-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "yellowstone-grpc-client"
version = "1.14.0+solana.1.18.7"
version = "1.15.0+solana.1.18.7"
authors = { workspace = true }
edition = { workspace = true }
description = "Yellowstone gRPC Geyser Simple Client"
Expand All @@ -13,7 +13,6 @@ publish = true
[dependencies]
bytes = { workspace = true }
futures = { workspace = true }
http = { workspace = true }
thiserror ={ workspace = true }
tonic = { workspace = true, features = ["tls", "tls-roots"] }
tonic-health = { workspace = true }
Expand Down
Loading

0 comments on commit b187007

Please sign in to comment.