Skip to content

Commit

Permalink
expose data from starknet errors
Browse files Browse the repository at this point in the history
  • Loading branch information
tonypony220 authored and Anton Koshcheev committed Jan 4, 2024
1 parent 9a51602 commit 2957166
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 24 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ npm run build

## Endpoint support

*Starknet endpoints* (in compliance with [Starknet specs](https://github.com/starkware-lib/starknet-specs)):
*Starknet endpoints* (in compliance with [Starknet specs](https://github.com/starkware-libs/starknet-specs)):

| Endpoint | Supported |
|:-------------------------------------------| :----------------- |
Expand Down
5 changes: 0 additions & 5 deletions crates/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,10 @@ bitvec = "1.0.1"
ethabi = "18.0.0"
ethers = "2.0.11"
eyre.workspace = true
#helios = { git = "https://github.com/a16z/helios", rev = "d4722045914d93c6fd8978f1fb2183494bc78a15" }
helios = { git = "https://github.com/a16z/helios", rev = "9481aaa572a092d4e73ca520b67a3315faf7748e" }
# todo fix this after helios release
chrono = "0.4.31"
reqwest = "0.11.13"
serde = { workspace = true, features = ["derive"] }
serde_json = "1.0"
#starknet-crypto = "0.6.0"
#starknet-crypto = "0.6.1"
# todo fix this after starknet for json-rpc 0.6.0 release
starknet-crypto = { git = "https://github.com/xJonathanLEI/starknet-rs", rev = "082f5564cf77a128139d8c2acc4f27ba670780ab" }

Expand Down
3 changes: 1 addition & 2 deletions crates/core/src/storage_proofs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ use bitvec::prelude::Msb0;
use bitvec::slice::BitSlice;
use eyre::{eyre, Result};
use serde::{Deserialize, Serialize};
use starknet::core::types::FieldElement;
use starknet_crypto::{pedersen_hash, poseidon_hash_many};
use starknet_crypto::{pedersen_hash, poseidon_hash_many, FieldElement};
use types::{ContractData, Direction, TrieNode};

use crate::utils::{felt_from_bits, felt_to_bits};
Expand Down
3 changes: 1 addition & 2 deletions crates/core/src/storage_proofs/types.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use serde::{Deserialize, Serialize};
// use starknet_crypto::FieldElement;
use starknet::core::types::FieldElement;
use starknet_crypto::FieldElement;

use super::StorageProof;

Expand Down
4 changes: 1 addition & 3 deletions crates/core/tests/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ use helios::prelude::ConfigDB;
#[cfg(not(target_arch = "wasm32"))]
use helios::prelude::FileDB;
use rstest::rstest;
// use starknet_crypto::FieldElement;
use starknet::core::types::FieldElement;

use starknet_crypto::FieldElement;
#[rstest]
#[should_panic]
fn bad_toml() {
Expand Down
3 changes: 1 addition & 2 deletions crates/core/tests/proofs.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
use beerus_core::storage_proofs::StorageProof;
use rstest::{fixture, rstest};
// use starknet_crypto::FieldElement;
use starknet::core::types::FieldElement;
use starknet::macros::felt;
use starknet_crypto::FieldElement;

const TESTING_STATE_ROOT: FieldElement = felt!("0x11d7289401f12bdbbfcf890cf531dd13e215d68fa700b82b08220dc75c24f54");
const TESTING_CONTRACT_ADDR: FieldElement = felt!("0x49d36570d4e46f48e99674bd3fcc84644ddd6b96f7c741b1562b82f9e004dc7");
Expand Down
2 changes: 1 addition & 1 deletion crates/rpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub trait BeerusRpc {

#[method(name = "getTransactionStatus")]
async fn get_transaction_status(&self, transaction_hash: FieldElement)
-> Result<TransactionStatus, BeerusRpcError>;
-> Result<TransactionStatus, BeerusRpcError>;

#[method(name = "getTransactionByBlockIdAndIndex")]
async fn get_transaction_by_block_id_and_index(
Expand Down
30 changes: 23 additions & 7 deletions crates/rpc/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ impl From<BeerusRpcError> for ErrorObjectOwned {
match err {
BeerusRpcError::Provider(provider_err) => match provider_err {
StarknetError(sn_err) => {
let code = match sn_err {
let mut data = None;
let code = match &sn_err {
StarknetErr::FailedToReceiveTransaction => 1,
StarknetErr::ContractNotFound => 20,
StarknetErr::BlockNotFound => 24,
Expand All @@ -28,24 +29,39 @@ impl From<BeerusRpcError> for ErrorObjectOwned {
StarknetErr::NoBlocks => 32,
StarknetErr::InvalidContinuationToken => 33,
StarknetErr::TooManyKeysInFilter => 34,
StarknetErr::ContractError(_) => 40,
StarknetErr::TransactionExecutionError(_) => 41,
StarknetErr::ContractError(err) => {
data = Some(format!("{err:?}"));
40
}
StarknetErr::TransactionExecutionError(err) => {
data = Some(format!("{err:?}"));
41
}
StarknetErr::ClassAlreadyDeclared => 51,
StarknetErr::InvalidTransactionNonce => 52,
StarknetErr::InsufficientMaxFee => 53,
StarknetErr::InsufficientAccountBalance => 54,
StarknetErr::ValidationFailure(_) => 55,
StarknetErr::ValidationFailure(err) => {
data = Some(format!("{err}"));
55
}
StarknetErr::CompilationFailed => 56,
StarknetErr::ContractClassSizeIsTooLarge => 57,
StarknetErr::NonAccount => 58,
StarknetErr::DuplicateTx => 59,
StarknetErr::CompiledClassHashMismatch => 60,
StarknetErr::UnsupportedTxVersion => 61,
StarknetErr::UnsupportedContractClassVersion => 62,
StarknetErr::UnexpectedError(_) => 63,
StarknetErr::NoTraceAvailable(_) => 10,
StarknetErr::UnexpectedError(err) => {
data = Some(format!("{err}"));
63
}
StarknetErr::NoTraceAvailable(err) => {
data = Some(format!("{err:?}"));
10
}
};
ErrorObjectOwned::owned(code, sn_err.message(), None::<()>)
ErrorObjectOwned::owned(code, sn_err.message(), data)
}
_ => ErrorObjectOwned::owned(-32601, format!("{provider_err}"), None::<()>),
},
Expand Down

0 comments on commit 2957166

Please sign in to comment.