forked from MystenLabs/sui
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move AuthorityClient to a separate file
- Loading branch information
Showing
5 changed files
with
115 additions
and
96 deletions.
There are no files selected for viewing
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,100 @@ | ||
// Copyright (c) Facebook, Inc. and its affiliates. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use async_trait::async_trait; | ||
use fastx_network::network::NetworkClient; | ||
use fastx_types::{error::FastPayError, messages::*, serialize::*}; | ||
|
||
#[async_trait] | ||
pub trait AuthorityAPI { | ||
/// Initiate a new order to a FastPay or Primary account. | ||
async fn handle_order(&mut self, order: Order) -> Result<OrderInfoResponse, FastPayError>; | ||
|
||
/// Confirm an order to a FastPay or Primary account. | ||
async fn handle_confirmation_order( | ||
&mut self, | ||
order: ConfirmationOrder, | ||
) -> Result<OrderInfoResponse, FastPayError>; | ||
|
||
/// Handle Account information requests for this account. | ||
async fn handle_account_info_request( | ||
&self, | ||
request: AccountInfoRequest, | ||
) -> Result<AccountInfoResponse, FastPayError>; | ||
|
||
/// Handle Object information requests for this account. | ||
async fn handle_object_info_request( | ||
&self, | ||
request: ObjectInfoRequest, | ||
) -> Result<ObjectInfoResponse, FastPayError>; | ||
|
||
/// Handle Object information requests for this account. | ||
async fn handle_order_info_request( | ||
&self, | ||
request: OrderInfoRequest, | ||
) -> Result<OrderInfoResponse, FastPayError>; | ||
} | ||
|
||
#[derive(Clone)] | ||
pub struct AuthorityClient(NetworkClient); | ||
|
||
impl AuthorityClient { | ||
pub fn new(network_client: NetworkClient) -> Self { | ||
Self(network_client) | ||
} | ||
} | ||
|
||
#[async_trait] | ||
impl AuthorityAPI for AuthorityClient { | ||
/// Initiate a new transfer to a FastPay or Primary account. | ||
async fn handle_order(&mut self, order: Order) -> Result<OrderInfoResponse, FastPayError> { | ||
let response = self.0.send_recv_bytes(serialize_order(&order)).await?; | ||
deserialize_order_info(response) | ||
} | ||
|
||
/// Confirm a transfer to a FastPay or Primary account. | ||
async fn handle_confirmation_order( | ||
&mut self, | ||
order: ConfirmationOrder, | ||
) -> Result<OrderInfoResponse, FastPayError> { | ||
let response = self | ||
.0 | ||
.send_recv_bytes(serialize_cert(&order.certificate)) | ||
.await?; | ||
deserialize_order_info(response) | ||
} | ||
|
||
async fn handle_account_info_request( | ||
&self, | ||
request: AccountInfoRequest, | ||
) -> Result<AccountInfoResponse, FastPayError> { | ||
let response = self | ||
.0 | ||
.send_recv_bytes(serialize_account_info_request(&request)) | ||
.await?; | ||
deserialize_account_info(response) | ||
} | ||
|
||
async fn handle_object_info_request( | ||
&self, | ||
request: ObjectInfoRequest, | ||
) -> Result<ObjectInfoResponse, FastPayError> { | ||
let response = self | ||
.0 | ||
.send_recv_bytes(serialize_object_info_request(&request)) | ||
.await?; | ||
deserialize_object_info(response) | ||
} | ||
|
||
/// Handle Object information requests for this account. | ||
async fn handle_order_info_request( | ||
&self, | ||
request: OrderInfoRequest, | ||
) -> Result<OrderInfoResponse, FastPayError> { | ||
let response = self | ||
.0 | ||
.send_recv_bytes(serialize_order_info_request(&request)) | ||
.await?; | ||
deserialize_order_info(response) | ||
} | ||
} |
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