Skip to content
This repository has been archived by the owner on Aug 2, 2024. It is now read-only.

Commit

Permalink
🔨 errors primitives crate
Browse files Browse the repository at this point in the history
  • Loading branch information
EvolveArt committed Aug 1, 2023
1 parent 3d46785 commit cb73179
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 49 deletions.
2 changes: 1 addition & 1 deletion crates/client/rpc/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use jsonrpsee::types::error::{CallError, ErrorObject};
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::errors::StarknetRpcApiError;

pub struct TxError(pub StarknetRpcApiError);

Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ use log::error;
use mc_rpc_core::utils::get_block_by_block_hash;
use mc_transaction_pool::ChainApi;
use mp_starknet::block::Block;
use mp_starknet::errors::StarknetRpcApiError;
use mp_starknet::execution::types::Felt252Wrapper;
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::traits::hash::HasherT;
use mp_starknet::traits::ThreadSafeCopy;
use mp_starknet::transaction::types::{EventWrapper, TransactionReceiptWrapper};
Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ pub use mc_rpc_core::StarknetRpcApiServer;
use mc_storage::OverrideHandle;
use mc_transaction_pool::{ChainApi, Pool};
use mp_starknet::crypto::merkle_patricia_tree::merkle_tree::ProofNode;
use mp_starknet::errors::StarknetRpcApiError;
use mp_starknet::execution::types::Felt252Wrapper;
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::traits::hash::HasherT;
use mp_starknet::traits::ThreadSafeCopy;
use mp_starknet::transaction::types::{
Expand Down
2 changes: 1 addition & 1 deletion crates/client/rpc/src/madara_backend_client.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use mc_rpc_core::utils::get_block_by_block_hash;
use mp_starknet::block::Block;
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::errors::StarknetRpcApiError;
use sc_client_api::backend::{Backend, StorageProvider};
use sp_api::BlockId;
use sp_blockchain::HeaderBackend;
Expand Down
2 changes: 1 addition & 1 deletion crates/pallets/starknet/src/runtime_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

use blockifier::execution::contract_class::ContractClass;
use mp_starknet::crypto::hash::Hasher;
use mp_starknet::errors::StarknetRpcApiError;
use mp_starknet::execution::types::{ClassHashWrapper, ContractAddressWrapper, Felt252Wrapper, StorageKeyWrapper};
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::transaction::types::{EventWrapper, Transaction, TxType};
use sp_api::BlockT;
pub extern crate alloc;
Expand Down
44 changes: 44 additions & 0 deletions crates/primitives/starknet/src/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
use thiserror_no_std::Error;

#[allow(missing_docs)]
#[derive(Error, Clone, Copy, Debug, scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)]
pub enum StarknetRpcApiError {
#[error("Failed to write transaction")]
FailedToReceiveTxn = 1,
#[error("Contract not found")]
ContractNotFound = 20,
#[error("Invalid message selector")]
InvalidMessageSelector = 21,
#[error("Invalid call data")]
InvalidCallData = 22,
#[error("Block not found")]
BlockNotFound = 24,
#[error("Transaction hash not found")]
TxnHashNotFound = 25,
#[error("Invalid transaction index in a block")]
InvalidTxnIndex = 27,
#[error("Class hash not found")]
ClassHashNotFound = 28,
#[error("Class already declared")]
ClassAlreadyDeclared = 51,
#[error("Requested page size is too big")]
PageSizeTooBig = 31,
#[error("There are no blocks")]
NoBlocks = 32,
#[error("The supplied continuation token is invalid or unknown")]
InvalidContinuationToken = 33,
#[error("Contract error")]
ContractError = 40,
#[error("Invalid contract class")]
InvalidContractClass = 50,
#[error("Too many storage keys requested")]
ProofLimitExceeded = 10000_isize,
#[error("Too many keys provided in a filter")]
TooManyKeysInFilter = 34,
#[error("Internal server error")]
InternalServerError = 500_isize,
#[error("Failed to fetch pending transactions")]
FailedToFetchPendingTransactions = 38,
#[error("Unimplemented method")]
UnimplementedMethod = 501_isize,
}
3 changes: 3 additions & 0 deletions crates/primitives/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ pub mod fees;
/// Sequencer address inherent data.
pub mod sequencer_address;

/// Starknet Errors types
pub mod errors;

/// Tests.
#[cfg(test)]
pub mod tests;
43 changes: 0 additions & 43 deletions crates/primitives/starknet/src/starknet_serde/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,49 +28,6 @@ fn string_to_felt(hex_str: &str) -> Result<Felt252Wrapper, String> {
}
}

#[allow(missing_docs)]
#[derive(Error, Clone, Copy, Debug, scale_codec::Encode, scale_codec::Decode, scale_info::TypeInfo)]
pub enum StarknetRpcApiError {
#[error("Failed to write transaction")]
FailedToReceiveTxn = 1,
#[error("Contract not found")]
ContractNotFound = 20,
#[error("Invalid message selector")]
InvalidMessageSelector = 21,
#[error("Invalid call data")]
InvalidCallData = 22,
#[error("Block not found")]
BlockNotFound = 24,
#[error("Transaction hash not found")]
TxnHashNotFound = 25,
#[error("Invalid transaction index in a block")]
InvalidTxnIndex = 27,
#[error("Class hash not found")]
ClassHashNotFound = 28,
#[error("Class already declared")]
ClassAlreadyDeclared = 51,
#[error("Requested page size is too big")]
PageSizeTooBig = 31,
#[error("There are no blocks")]
NoBlocks = 32,
#[error("The supplied continuation token is invalid or unknown")]
InvalidContinuationToken = 33,
#[error("Contract error")]
ContractError = 40,
#[error("Invalid contract class")]
InvalidContractClass = 50,
#[error("Too many storage keys requested")]
ProofLimitExceeded = 10000_isize,
#[error("Too many keys provided in a filter")]
TooManyKeysInFilter = 34,
#[error("Internal server error")]
InternalServerError = 500_isize,
#[error("Failed to fetch pending transactions")]
FailedToFetchPendingTransactions = 38,
#[error("Unimplemented method")]
UnimplementedMethod = 501_isize,
}

// Deserialization and Conversion for JSON Transactions, Events, and CallEntryPoints
/// Struct for deserializing CallEntryPoint from JSON
#[derive(Debug, Serialize, Deserialize)]
Expand Down
12 changes: 11 additions & 1 deletion crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ pub use frame_support::{construct_runtime, parameter_types, StorageValue};
pub use frame_system::Call as SystemCall;
use frame_system::EventRecord;
use mp_starknet::crypto::hash::Hasher;
use mp_starknet::errors::StarknetRpcApiError;
use mp_starknet::execution::types::{ClassHashWrapper, ContractAddressWrapper, Felt252Wrapper, StorageKeyWrapper};
use mp_starknet::starknet_serde::StarknetRpcApiError;
use mp_starknet::transaction::types::{
DeclareTransaction, DeployAccountTransaction, EventWrapper, InvokeTransaction, Transaction, TxType,
};
Expand Down Expand Up @@ -329,6 +329,16 @@ impl_runtime_apis! {
if error == PalletError::<Runtime>::ContractNotFound.into() {
return StarknetRpcApiError::ContractNotFound;
}
if error == PalletError::<Runtime>::ClassHashAlreadyDeclared.into() {
return StarknetRpcApiError::ClassAlreadyDeclared;
}
if error == PalletError::<Runtime>::ContractClassHashUnknown.into() {
return StarknetRpcApiError::ClassHashNotFound;
}
if error == PalletError::<Runtime>::InvalidContractClass.into() {
return StarknetRpcApiError::InvalidContractClass;
}

StarknetRpcApiError::ContractError
}
}
Expand Down

0 comments on commit cb73179

Please sign in to comment.