-
Notifications
You must be signed in to change notification settings - Fork 192
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implement a reader and writer interface
- Loading branch information
0xfirefist
committed
May 16, 2024
1 parent
23f8d02
commit a9a098a
Showing
1 changed file
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use { | ||
anyhow::{ | ||
Error, | ||
Result, | ||
}, | ||
axum::async_trait, | ||
}; | ||
|
||
pub type ChainBlockNumber = u64; | ||
|
||
#[derive(Clone, Debug)] | ||
pub struct RequestWithCallbackData { | ||
pub sequence_number: u64, | ||
/// The random number submitted by the user while requesting a callback. | ||
pub user_random_number: [u8; 32], | ||
} | ||
|
||
#[async_trait] | ||
pub trait ChainReader: Send + Sync { | ||
/// Returns data of all the requests with callback made on chain between | ||
/// the given block numbers. | ||
async fn get_requests_with_callback_data( | ||
&self, | ||
from_block: ChainBlockNumber, | ||
to_block: ChainBlockNumber, | ||
) -> Result<Vec<RequestWithCallbackData>>; | ||
|
||
/// Returns the latest block which we consider to be included into the chain and | ||
/// is safe from reorgs. | ||
async fn get_latest_safe_block(&self) -> Result<ChainBlockNumber>; | ||
} | ||
|
||
pub enum RevealError { | ||
HashChainRevealFailed(Error), | ||
ContractError(Error), | ||
RpcError(Error), | ||
} | ||
|
||
#[async_trait] | ||
pub trait ChainWriter: Send + Sync + ChainReader { | ||
/// Fulfill the given request on chain with the given provider revelation. | ||
async fn reveal_with_callback( | ||
&self, | ||
request_with_callback_data: RequestWithCallbackData, | ||
provider_revelation: [u8; 32], | ||
) -> Result<(), RevealError>; | ||
} |