Skip to content

Commit

Permalink
Add a safe client function that augments the follower API with downlo…
Browse files Browse the repository at this point in the history
…ading the transactions information (MystenLabs#1446)

Co-authored-by: George Danezis <[email protected]>
  • Loading branch information
gdanezis and George Danezis authored Apr 22, 2022
1 parent e312802 commit b364f13
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions sui_core/src/safe_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,47 @@ impl<C> SafeClient<C> {
}
}

impl<C> SafeClient<C>
where
C: AuthorityAPI + Send + Sync + Clone + 'static,
{
/// Uses the follower API and augments each digest received with a full transactions info structure.
pub async fn handle_transaction_info_request_to_transaction_info(
&self,
request: BatchInfoRequest,
) -> Result<
impl futures::Stream<Item = Result<(u64, TransactionInfoResponse), SuiError>> + '_,
SuiError,
> {
let new_stream = self
.handle_batch_stream(request)
.await
.map_err(|err| SuiError::GenericAuthorityError {
error: format!("Stream error: {:?}", err),
})?
.filter_map(|item| {
let _client = self.clone();
async move {
match &item {
Ok(BatchInfoResponseItem(UpdateItem::Batch(_signed_batch))) => None,
Ok(BatchInfoResponseItem(UpdateItem::Transaction((seq, digest)))) => {
// Download the full transaction info
let transaction_info_request = TransactionInfoRequest::from(*digest);
let res = _client
.handle_transaction_info_request(transaction_info_request)
.await
.map(|v| (*seq, v));
Some(res)
}
Err(err) => Some(Err(err.clone())),
}
}
});

Ok(new_stream)
}
}

#[async_trait]
impl<C> AuthorityAPI for SafeClient<C>
where
Expand Down

0 comments on commit b364f13

Please sign in to comment.