-
Notifications
You must be signed in to change notification settings - Fork 188
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(katana): add
torii_getTransactions
rpc (#1529)
- Loading branch information
Showing
18 changed files
with
716 additions
and
52 deletions.
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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
pub mod dev; | ||
pub mod katana; | ||
pub mod starknet; | ||
pub mod torii; | ||
|
||
/// List of APIs supported by Katana. | ||
#[derive(Debug, Copy, Clone)] | ||
pub enum ApiKind { | ||
Starknet, | ||
Katana, | ||
Torii, | ||
Dev, | ||
} |
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,11 @@ | ||
use jsonrpsee::core::RpcResult; | ||
use jsonrpsee::proc_macros::rpc; | ||
use katana_rpc_types::transaction::{TransactionsPage, TransactionsPageCursor}; | ||
|
||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "torii"))] | ||
#[cfg_attr(feature = "client", rpc(client, server, namespace = "torii"))] | ||
pub trait ToriiApi { | ||
#[method(name = "getTransactions")] | ||
async fn get_transactions(&self, cursor: TransactionsPageCursor) | ||
-> RpcResult<TransactionsPage>; | ||
} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
pub mod katana; | ||
pub mod starknet; | ||
pub mod torii; |
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,70 @@ | ||
use futures::channel::mpsc::Receiver; | ||
use jsonrpsee::core::Error; | ||
use jsonrpsee::types::error::CallError; | ||
use jsonrpsee::types::ErrorObject; | ||
use katana_core::sequencer_error::SequencerError; | ||
use katana_primitives::receipt::Receipt; | ||
use katana_primitives::transaction::TxWithHash; | ||
use katana_provider::error::ProviderError; | ||
|
||
use crate::transaction::TransactionsPageCursor; | ||
|
||
#[derive(Debug, thiserror::Error)] | ||
#[repr(i32)] | ||
pub enum ToriiApiError { | ||
#[error("Block not found")] | ||
BlockNotFound, | ||
#[error("Transaction index out of bounds")] | ||
TransactionOutOfBounds, | ||
#[error("Transaction not found")] | ||
TransactionNotFound, | ||
#[error("Transaction receipt not found")] | ||
TransactionReceiptNotFound, | ||
#[error("Transactions not ready")] | ||
TransactionsNotReady { | ||
rx: Receiver<Vec<(TxWithHash, Receipt)>>, | ||
cursor: TransactionsPageCursor, | ||
}, | ||
#[error("Long poll expired")] | ||
ChannelDisconnected, | ||
#[error("An unexpected error occured: {reason}")] | ||
UnexpectedError { reason: String }, | ||
} | ||
|
||
impl ToriiApiError { | ||
fn code(&self) -> i32 { | ||
match self { | ||
ToriiApiError::BlockNotFound => 24, | ||
ToriiApiError::TransactionOutOfBounds => 34, | ||
ToriiApiError::TransactionNotFound => 35, | ||
ToriiApiError::TransactionReceiptNotFound => 36, | ||
ToriiApiError::TransactionsNotReady { .. } => 37, | ||
ToriiApiError::ChannelDisconnected => 42, | ||
ToriiApiError::UnexpectedError { .. } => 63, | ||
} | ||
} | ||
} | ||
|
||
impl From<ProviderError> for ToriiApiError { | ||
fn from(value: ProviderError) -> Self { | ||
ToriiApiError::UnexpectedError { reason: value.to_string() } | ||
} | ||
} | ||
|
||
impl From<SequencerError> for ToriiApiError { | ||
fn from(value: SequencerError) -> Self { | ||
match value { | ||
SequencerError::BlockNotFound(_) => ToriiApiError::BlockNotFound, | ||
err => ToriiApiError::UnexpectedError { reason: err.to_string() }, | ||
} | ||
} | ||
} | ||
|
||
impl From<ToriiApiError> for Error { | ||
fn from(err: ToriiApiError) -> Self { | ||
let code = err.code(); | ||
let message = err.to_string(); | ||
let err = ErrorObject::owned(code, message, None::<()>); | ||
Error::Call(CallError::Custom(err)) | ||
} | ||
} |
Oops, something went wrong.