Skip to content

Commit

Permalink
feat: bump starknet-rs commit e72cc -> 0.5.0 (#543)
Browse files Browse the repository at this point in the history
* fix starknet_getEvents hurl

* cargo upd

* bump up in process

* bumping...now it compiles

* update starknet errors resolving. Add error log entry on starkent error

* updated tests

* propagating err

* clean up

* add_deploy_transaction removed

* update tests

* clean up again

* bump to 0.5.0

* clean up again
  • Loading branch information
tonypony220 authored Sep 28, 2023
1 parent 658e7fb commit 9fbb0a8
Show file tree
Hide file tree
Showing 18 changed files with 451 additions and 775 deletions.
527 changes: 204 additions & 323 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ beerus-core = { path = "./crates/beerus-core" }
# Helios revision is supposed to be changed by the corresponding tag once the revision is released. Next expected tag: 0.5.0.
helios = { git = "https://github.com/a16z/helios", rev = "f63e4142c8c8094cdf94cf8d1ef1cb637a7eac98" }

#TODO: update with version tag instead of hash rev when available
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "e72cc0a4b3ea67c7691ebec58300da3c21f0abb2" }
starknet = { git = "https://github.com/xJonathanLEI/starknet-rs", tag = "starknet/v0.5.0" }

ethers = "2.0.2"
eyre = "0.6.8"
log = "0.4.17"
Expand Down
2 changes: 1 addition & 1 deletion crates/beerus-core/examples/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use env_logger::Env;
use eyre::Result;
use starknet::{
core::types::FieldElement,
providers::jsonrpc::models::{BlockId, FunctionCall},
core::types::{BlockId, FunctionCall},
};
use std::str::FromStr;

Expand Down
24 changes: 11 additions & 13 deletions crates/beerus-core/src/lightclient/beerus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,14 @@ use eyre::Result as EyreResult;
use helios::types::{BlockTag, CallOpts};
#[cfg(feature = "std")]
use log::{debug, error, info, warn};
use starknet::providers::jsonrpc::JsonRpcError;
use starknet::{
core::types::FieldElement,
providers::jsonrpc::models::{
BlockHashAndNumber, BlockId, BlockStatus, BlockTag as StarknetBlockTag, BlockWithTxHashes,
BlockWithTxs, BroadcastedTransaction, DeclareTransaction, DeployAccountTransaction,
DeployTransaction, FeeEstimate, FunctionCall, InvokeTransaction, L1HandlerTransaction,
MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs, MaybePendingTransactionReceipt,
Transaction,
},
use starknet::core::types::{
BlockHashAndNumber, BlockId, BlockStatus, BlockTag as StarknetBlockTag, BlockWithTxHashes,
BlockWithTxs, BroadcastedTransaction, DeclareTransaction, DeployAccountTransaction,
DeployTransaction, FeeEstimate, FieldElement, FunctionCall, InvokeTransaction,
L1HandlerTransaction, MaybePendingBlockWithTxHashes, MaybePendingBlockWithTxs,
MaybePendingTransactionReceipt, Transaction,
};
use starknet::providers::jsonrpc::JsonRpcError;

/// Enum representing the different synchronization status of the light client.
#[derive(Debug, Clone, PartialEq)]
Expand Down Expand Up @@ -409,7 +406,7 @@ impl BeerusLightClient {
///
/// # Returns
///
/// Returns a `Result` containing the fee estimate as a `FeeEstimate` if the operation was successful,
/// Returns a `Result` containing the fee estimate as a `Vec<FeeEstimate>` if the operation was successful,
/// or an `Err` containing a `JsonRpcError` if the operation failed.
///
/// # Errors
Expand All @@ -421,7 +418,7 @@ impl BeerusLightClient {
block_id: &BlockId,
) -> Result<FeeEstimate, JsonRpcError> {
self.starknet_lightclient
.estimate_fee(request, block_id)
.estimate_fee_single(request, block_id)
.await
}

Expand Down Expand Up @@ -813,6 +810,7 @@ impl BeerusLightClient {
InvokeTransaction::V1(v1_tx) => v1_tx.transaction_hash,
},
Transaction::Declare(tx) => match tx {
DeclareTransaction::V0(v0_tx) => v0_tx.transaction_hash,
DeclareTransaction::V1(v1_tx) => v1_tx.transaction_hash,
DeclareTransaction::V2(v2_tx) => v2_tx.transaction_hash,
},
Expand All @@ -830,7 +828,7 @@ impl BeerusLightClient {
.collect();
let block_with_tx_hashes = BlockWithTxHashes {
transactions: tx_hashes,
status: block.status.clone(),
status: block.status,
block_hash: block.block_hash,
parent_hash: block.parent_hash,
block_number: block.block_number,
Expand Down
144 changes: 45 additions & 99 deletions crates/beerus-core/src/lightclient/starknet/errors.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
use ethers::providers::ProviderError;
use reqwest::Error as ReqwestError;
use starknet::providers::jsonrpc::models::ErrorCode;
use starknet::providers::jsonrpc::{JsonRpcClientError, JsonRpcError, RpcError};
use ethers::providers::ProviderError as EthersProviderError;
use starknet::core::types::StarknetError;
use starknet::providers::{
jsonrpc::{HttpTransportError, JsonRpcClientError, JsonRpcError, RpcError},
MaybeUnknownErrorCode, ProviderError as StarknetProviderError, StarknetErrorWithMessage,
};

pub struct JsonRpcClientErrorWrapper(JsonRpcClientError<ReqwestError>);
pub struct JsonRpcClientErrorWrapper(StarknetProviderError<JsonRpcClientError<HttpTransportError>>);
#[derive(Debug, thiserror::Error)]
#[error("unable to map JsonRpcErrorClient type to JsonRpcError type")]
pub struct JsonRpcClientConversionError {
message: String,
pub message: String,
}

pub struct StarknetErrorCodeWrapper {
Expand All @@ -18,75 +20,11 @@ impl TryFrom<JsonRpcClientErrorWrapper> for JsonRpcError {
type Error = JsonRpcClientConversionError;
fn try_from(err: JsonRpcClientErrorWrapper) -> Result<Self, Self::Error> {
match err.0 {
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::BlockNotFound)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::BlockNotFound).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::ContractError)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::ContractError).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::NoBlocks)) => Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::NoBlocks).code,
message: err.0.to_string(),
}),
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::ContractNotFound)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::ContractNotFound).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::ClassHashNotFound)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::ClassHashNotFound).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::InvalidContinuationToken)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::InvalidContinuationToken).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::InvalidCallData)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::InvalidCallData).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::FailedToReceiveTransaction)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::FailedToReceiveTransaction)
.code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::InvalidMessageSelector)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::InvalidMessageSelector).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::TransactionHashNotFound)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::TransactionHashNotFound).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::PageSizeTooBig)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::PageSizeTooBig).code,
message: err.0.to_string(),
})
}
JsonRpcClientError::RpcError(RpcError::Code(ErrorCode::InvalidTransactionIndex)) => {
Ok(JsonRpcError {
code: StarknetErrorCodeWrapper::from(ErrorCode::InvalidTransactionIndex).code,
message: err.0.to_string(),
StarknetProviderError::StarknetError(err) => {
let msg = err.message.clone();
Ok(Self {
code: StarknetErrorCodeWrapper::from(err).code,
message: msg,
})
}
_ => Err(JsonRpcClientConversionError {
Expand All @@ -97,45 +35,53 @@ impl TryFrom<JsonRpcClientErrorWrapper> for JsonRpcError {
}
}

impl From<ProviderError> for JsonRpcClientErrorWrapper {
fn from(err: ProviderError) -> Self {
JsonRpcClientErrorWrapper(JsonRpcClientError::RpcError(RpcError::Unknown(
JsonRpcError {
impl From<EthersProviderError> for JsonRpcClientErrorWrapper {
fn from(err: EthersProviderError) -> Self {
JsonRpcClientErrorWrapper(StarknetProviderError::Other(JsonRpcClientError::RpcError(
RpcError::Unknown(JsonRpcError {
code: 520, // Unknown error, at least we keep the message
message: err.to_string(),
},
}),
)))
}
}

impl From<JsonRpcClientErrorWrapper> for JsonRpcClientError<ReqwestError> {
impl From<JsonRpcClientErrorWrapper>
for StarknetProviderError<JsonRpcClientError<HttpTransportError>>
{
fn from(err: JsonRpcClientErrorWrapper) -> Self {
err.0
}
}

impl From<JsonRpcClientError<ReqwestError>> for JsonRpcClientErrorWrapper {
fn from(err: JsonRpcClientError<ReqwestError>) -> Self {
impl From<StarknetProviderError<JsonRpcClientError<HttpTransportError>>>
for JsonRpcClientErrorWrapper
{
fn from(err: StarknetProviderError<JsonRpcClientError<HttpTransportError>>) -> Self {
JsonRpcClientErrorWrapper(err)
}
}

// Since we dont have conversion ErrorCode -> i64 (dont implemented in starknet-rs) this is necessary.
impl From<ErrorCode> for StarknetErrorCodeWrapper {
fn from(code: ErrorCode) -> Self {
match code {
ErrorCode::FailedToReceiveTransaction => StarknetErrorCodeWrapper { code: 1 },
ErrorCode::ContractNotFound => StarknetErrorCodeWrapper { code: 20 },
ErrorCode::InvalidMessageSelector => StarknetErrorCodeWrapper { code: 21 },
ErrorCode::InvalidCallData => StarknetErrorCodeWrapper { code: 22 },
ErrorCode::BlockNotFound => StarknetErrorCodeWrapper { code: 24 },
ErrorCode::TransactionHashNotFound => StarknetErrorCodeWrapper { code: 25 },
ErrorCode::InvalidTransactionIndex => StarknetErrorCodeWrapper { code: 27 },
ErrorCode::ClassHashNotFound => StarknetErrorCodeWrapper { code: 28 },
ErrorCode::PageSizeTooBig => StarknetErrorCodeWrapper { code: 31 },
ErrorCode::NoBlocks => StarknetErrorCodeWrapper { code: 32 },
ErrorCode::InvalidContinuationToken => StarknetErrorCodeWrapper { code: 33 },
ErrorCode::ContractError => StarknetErrorCodeWrapper { code: 40 },
// Since we dont have conversion StarknetError -> i64 (dont implemented in starknet-rs) this is necessary.
impl From<StarknetErrorWithMessage> for StarknetErrorCodeWrapper {
fn from(err: StarknetErrorWithMessage) -> Self {
match err.code {
MaybeUnknownErrorCode::Unknown(code) => StarknetErrorCodeWrapper { code },
MaybeUnknownErrorCode::Known(starknet_error) => match starknet_error {
StarknetError::FailedToReceiveTransaction => StarknetErrorCodeWrapper { code: 1 },
StarknetError::ContractNotFound => StarknetErrorCodeWrapper { code: 20 },
StarknetError::BlockNotFound => StarknetErrorCodeWrapper { code: 24 },
StarknetError::TransactionHashNotFound => StarknetErrorCodeWrapper { code: 25 },
StarknetError::InvalidTransactionIndex => StarknetErrorCodeWrapper { code: 27 },
StarknetError::ClassHashNotFound => StarknetErrorCodeWrapper { code: 28 },
StarknetError::PageSizeTooBig => StarknetErrorCodeWrapper { code: 31 },
StarknetError::NoBlocks => StarknetErrorCodeWrapper { code: 32 },
StarknetError::InvalidContinuationToken => StarknetErrorCodeWrapper { code: 33 },
StarknetError::TooManyKeysInFilter => StarknetErrorCodeWrapper { code: 34 },
StarknetError::ContractError => StarknetErrorCodeWrapper { code: 40 },
StarknetError::InvalidContractClass => StarknetErrorCodeWrapper { code: 50 },
StarknetError::ClassAlreadyDeclared => StarknetErrorCodeWrapper { code: 51 },
},
}
}
}
Loading

0 comments on commit 9fbb0a8

Please sign in to comment.