Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust client: add unary methods #122

Merged
merged 1 commit into from
May 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions examples/rust/src/bin/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,17 @@ use {
yellowstone_grpc_proto::prelude::{
subscribe_request_filter_accounts_filter::Filter as AccountsFilterDataOneof,
subscribe_request_filter_accounts_filter_memcmp::Data as AccountsFilterMemcmpOneof,
subscribe_update::UpdateOneof, SubscribeRequest, SubscribeRequestFilterAccounts,
SubscribeRequestFilterAccountsFilter, SubscribeRequestFilterAccountsFilterMemcmp,
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
SubscribeRequestFilterSlots, SubscribeRequestFilterTransactions, SubscribeUpdateAccount,
subscribe_update::UpdateOneof,
SubscribeRequest,
SubscribeRequestFilterAccounts,
SubscribeRequestFilterAccountsFilter,
SubscribeRequestFilterAccountsFilterMemcmp,
SubscribeRequestFilterBlocks,
SubscribeRequestFilterBlocksMeta,
SubscribeRequestFilterSlots,
SubscribeRequestFilterTransactions,
SubscribeUpdateAccount,
// PingRequest,
},
};

Expand Down Expand Up @@ -288,3 +295,17 @@ async fn main() -> anyhow::Result<()> {
.await
.map_err(Into::into)
}

// unary method
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be better support unary methods in arguments, not as commented code

// #[tokio::main]
// async fn main() -> anyhow::Result<()> {
// std::env::set_var("RUST_LOG", "info");
// env_logger::init();
//
// let args = Args::parse();
// let (endpoint, x_token) = (args.endpoint.clone(), args.x_token.clone());
// let mut client = GeyserGrpcClient::connect(endpoint, x_token, None)?;
// let response = client.ping(200).await;
// dbg!(&response);
// Ok(())
// }
32 changes: 31 additions & 1 deletion yellowstone-grpc-client/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use yellowstone_grpc_proto::geyser::{GetSlotResponse, PongResponse};
use yellowstone_grpc_proto::prelude::{GetBlockHeightResponse, GetLatestBlockhashResponse};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we have import from this crate down in this file (line 19)

use {
bytes::Bytes,
futures::{
Expand All @@ -15,7 +17,8 @@ use {
Request, Response, Status,
},
yellowstone_grpc_proto::prelude::{
geyser_client::GeyserClient, SubscribeRequest, SubscribeRequestFilterAccounts,
geyser_client::GeyserClient, GetBlockHeightRequest, GetLatestBlockhashRequest,
GetSlotRequest, PingRequest, SubscribeRequest, SubscribeRequestFilterAccounts,
SubscribeRequestFilterBlocks, SubscribeRequestFilterBlocksMeta,
SubscribeRequestFilterSlots, SubscribeRequestFilterTransactions, SubscribeUpdate,
},
Expand Down Expand Up @@ -117,6 +120,33 @@ impl<F: Interceptor> GeyserGrpcClient<F> {
.await?;
Ok(response)
}

pub async fn ping(&mut self, count: i32) -> GeyserGrpcClientResult<PongResponse> {
let message = PingRequest { count };
let request = tonic::Request::new(message);
let response = self.client.ping(request).await?;
Ok(response.into_inner())
}

pub async fn get_latest_blockhash(
&mut self,
) -> GeyserGrpcClientResult<GetLatestBlockhashResponse> {
let request = tonic::Request::new(GetLatestBlockhashRequest {});
let response = self.client.get_latest_blockhash(request).await?;
Ok(response.into_inner())
}

pub async fn get_block_height(&mut self) -> GeyserGrpcClientResult<GetBlockHeightResponse> {
let request = tonic::Request::new(GetBlockHeightRequest {});
let response = self.client.get_block_height(request).await?;
Ok(response.into_inner())
}

pub async fn get_slot(&mut self) -> GeyserGrpcClientResult<GetSlotResponse> {
let request = tonic::Request::new(GetSlotRequest {});
let response = self.client.get_slot(request).await?;
Ok(response.into_inner())
}
}

#[cfg(test)]
Expand Down