-
Notifications
You must be signed in to change notification settings - Fork 7
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
feat: grpc client #31
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
03d500c
feat: grpc client
RequescoS e15bfb9
add some validation for slot range
RequescoS 4c3c6d9
fix test
RequescoS c5158fb
comments
RequescoS 60ded63
Merge branch 'main' into feat/grpc-client
RequescoS d14c7e8
merge
RequescoS 02b1624
error handling
RequescoS a8a9186
starting service
RequescoS 8f1342d
clippy
RequescoS 5811c27
chain_mutability
RequescoS ec12da0
add comment
RequescoS 4f8fbcc
add missing fields
RequescoS c4e7ed6
Merge branch 'main' into feat/grpc-client
RequescoS 0314bbd
comments
RequescoS b246184
comments
RequescoS 9695199
Merge branch 'main' into feat/grpc-client
RequescoS 7fd473c
merge
RequescoS 3bb7f6c
add saving offchain data
RequescoS b68769c
tests fix
RequescoS 433a27f
Merge branch 'main' into feat/grpc-client
RequescoS 294a910
merge
RequescoS File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::error::GrpcError; | ||
use crate::gapfiller::gap_filler_service_client::GapFillerServiceClient; | ||
use crate::gapfiller::RangeRequest; | ||
use async_trait::async_trait; | ||
use futures::StreamExt; | ||
use interface::asset_streaming_and_discovery::{ | ||
AssetDetailsConsumer, AssetDetailsStreamNonSync, AsyncError, PeerDiscovery, | ||
}; | ||
use std::str::FromStr; | ||
use tonic::transport::{Channel, Uri}; | ||
use tonic::{Code, Status}; | ||
|
||
pub struct Client { | ||
inner: GapFillerServiceClient<Channel>, | ||
} | ||
|
||
impl Client { | ||
pub async fn connect(peer_discovery: impl PeerDiscovery) -> Result<Self, GrpcError> { | ||
let url = Uri::from_str(peer_discovery.get_gapfiller_peer_addr().as_str()) | ||
.map_err(|e| GrpcError::UriCreate(e.to_string()))?; | ||
let channel = Channel::builder(url).connect().await?; | ||
|
||
Ok(Self { | ||
inner: GapFillerServiceClient::new(channel), | ||
}) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AssetDetailsConsumer for Client { | ||
async fn get_consumable_stream_in_range( | ||
&mut self, | ||
start_slot: u64, | ||
end_slot: u64, | ||
) -> Result<AssetDetailsStreamNonSync, AsyncError> { | ||
Ok(Box::pin( | ||
self.inner | ||
.get_assets_updated_within(RangeRequest { | ||
start_slot, | ||
end_slot, | ||
}) | ||
.await | ||
.map_err(|e| Box::new(e) as AsyncError)? | ||
.into_inner() | ||
.map(|stream| { | ||
stream | ||
.and_then(|asset_details| { | ||
asset_details | ||
.try_into() | ||
.map_err(|e: GrpcError| Status::new(Code::Internal, e.to_string())) | ||
}) | ||
.map_err(|e| Box::new(e) as AsyncError) | ||
}), | ||
)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use thiserror::Error; | ||
use tonic::transport::Error; | ||
|
||
#[derive(Error, Debug, PartialEq, Eq)] | ||
pub enum GrpcError { | ||
#[error("Pubkey from: {0:?}")] | ||
PubkeyFrom(Vec<u8>), | ||
#[error("Missing field: {0}")] | ||
MissingField(String), | ||
#[error("Cannot cast enum: {0} {1}")] | ||
EnumCast(String, String), | ||
#[error("UriCreate: {0}")] | ||
UriCreate(String), | ||
#[error("TonicTransport: {0}")] | ||
TonicTransport(String), | ||
} | ||
impl From<tonic::transport::Error> for GrpcError { | ||
fn from(value: Error) -> Self { | ||
Self::TonicTransport(value.to_string()) | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still open question if we need to add asset offchain data to this struct?