-
Notifications
You must be signed in to change notification settings - Fork 44
feat(sdk)!: provide request execution information #2259
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
Merged
Merged
Changes from 15 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
7a77ccf
feat(sdk): provide request execution information
shumkov b85f52e
test: fix compilation errors
shumkov 6de23ab
refactor: rename `unwrap` to `into_inner`
shumkov fba6ef8
refactor: rename response to inner
shumkov 8af6776
test: increase timeout to pass the test
shumkov 8e278e3
fix: `into_inner` doesn't need `CanRetry` bound
shumkov 5af8822
fix: errored address is none
shumkov 8269c1f
Merge branch 'v1.4-dev' into feat/sdk/execution_info
shumkov a9a96a0
chore: don't use empty uri
shumkov 920b50d
docs: fix usage example
shumkov 067db87
refactor: remove unused import
shumkov c684b3f
chore: update test vectors
shumkov 9da89a8
chore: more test vectors
shumkov 034bdb2
test(sdk): regenerate test vectors
lklimek 1bc31a9
refactor: re-export specific types
shumkov 8c5518f
fix: compilation error
shumkov de7bab3
docs: add missing docs
shumkov bca5dac
Merge branch 'v1.4-dev' into feat/sdk/execution_info
shumkov File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,66 @@ | ||
| use crate::transport::{TransportClient, TransportRequest}; | ||
| use crate::{Address, CanRetry, DapiClientError, RequestSettings}; | ||
| use dapi_grpc::mock::Mockable; | ||
| use dapi_grpc::tonic::async_trait; | ||
| use std::fmt::Debug; | ||
|
|
||
| #[async_trait] | ||
| /// DAPI client executor trait. | ||
| pub trait DapiRequestExecutor { | ||
| /// Execute request using this DAPI client. | ||
| async fn execute<R>( | ||
| &self, | ||
| request: R, | ||
| settings: RequestSettings, | ||
| ) -> ExecutionResult<R::Response, DapiClientError<<R::Client as TransportClient>::Error>> | ||
| where | ||
| R: TransportRequest + Mockable, | ||
| R::Response: Mockable, | ||
| <R::Client as TransportClient>::Error: Mockable; | ||
| } | ||
|
|
||
| /// Error happened during request execution. | ||
| #[derive(Debug, Clone, thiserror::Error, Eq, PartialEq)] | ||
| #[error("{inner}")] | ||
shumkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| pub struct ExecutionError<E> { | ||
| /// The cause of error | ||
| pub inner: E, | ||
| /// How many times the request was retried | ||
| pub retries: usize, | ||
| /// The address of the node that was used for the request | ||
| pub address: Option<Address>, | ||
| } | ||
|
|
||
| impl<E> ExecutionError<E> { | ||
| /// Unwrap the error cause | ||
| pub fn into_inner(self) -> E { | ||
| self.inner | ||
| } | ||
| } | ||
|
|
||
| impl<E: CanRetry> CanRetry for ExecutionError<E> { | ||
| fn can_retry(&self) -> bool { | ||
| self.inner.can_retry() | ||
| } | ||
| } | ||
|
|
||
| /// Request execution response. | ||
| #[derive(Debug, Clone, Eq, PartialEq)] | ||
| pub struct ExecutionResponse<R> { | ||
| /// The response from the request | ||
| pub inner: R, | ||
| /// How many times the request was retried | ||
| pub retries: usize, | ||
| /// The address of the node that was used for the request | ||
| pub address: Address, | ||
| } | ||
shumkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| impl<R> ExecutionResponse<R> { | ||
| /// Unwrap the response | ||
| pub fn into_inner(self) -> R { | ||
| self.inner | ||
| } | ||
| } | ||
|
|
||
| /// Result of request execution | ||
| pub type ExecutionResult<R, E> = Result<ExecutionResponse<R>, ExecutionError<E>>; | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.