Skip to content
This repository was archived by the owner on Jul 22, 2024. It is now read-only.

Add DECLARE and DEPLOY_ACCOUNT support to rpc_state_reader. #995

Closed
wants to merge 63 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
20585f1
From/TryFrom starknet api types
mmsc2 Aug 29, 2023
24b327e
Add deploy account
mmsc2 Aug 29, 2023
8f62569
Modify gitignore
mmsc2 Aug 29, 2023
dc8f5a1
Deploy account and invoke function
mmsc2 Aug 29, 2023
d4491cf
Change into_iter to iter
mmsc2 Aug 29, 2023
10467c8
Update .gitignore
juanbono Aug 29, 2023
4b16b7b
change to try_from
mmsc2 Aug 29, 2023
78b9ee7
Merge branch 'FromStarknetApi' of github.com:lambdaclass/starknet_in_…
mmsc2 Aug 29, 2023
327bddc
Merge branch 'main' into FromStarknetApi
mmsc2 Aug 29, 2023
f40fad6
Move functions to its respective files
mmsc2 Aug 29, 2023
9ec7c07
Merge branch 'FromStarknetApi' of github.com:lambdaclass/starknet_in_…
mmsc2 Aug 29, 2023
160b82d
Merge branch 'main' into FromStarknetApi
xqft Aug 30, 2023
5ce80fb
WIP Added SIR support to SNRPC
xqft Aug 30, 2023
75894a4
Implemented state reader for sir
xqft Aug 30, 2023
d277eb3
WIP Transaction
xqft Aug 30, 2023
9f810d4
WIP SiR execution
xqft Aug 30, 2023
7dcc455
Fixed rpc sir execute_tx
xqft Aug 30, 2023
99e7cc0
Fix clippy
xqft Aug 30, 2023
f84aaf3
Import last version of sn_api
xqft Aug 30, 2023
edd9fd6
Formatting
xqft Aug 30, 2023
70335b5
Test
mmsc2 Aug 30, 2023
403aa45
Merge branch 'FromStarknetApi' of github.com:lambdaclass/starknet_in_…
mmsc2 Aug 30, 2023
ffb9e28
Test try from
mmsc2 Aug 30, 2023
bea372a
Delete test
mmsc2 Aug 30, 2023
af487c0
Fix format
mmsc2 Aug 30, 2023
c11eb16
Fix test
mmsc2 Aug 30, 2023
e630727
Merge branch 'main' into FromStarknetApi
mmsc2 Aug 30, 2023
6ad0466
Merge branch 'main' into deprecate_old_rpc
xqft Sep 1, 2023
eb6acb8
Merge branch 'FromStarknetApi' into deprecate_old_rpc
xqft Sep 1, 2023
23cbaf3
Implement stuff.
azteca1998 Sep 1, 2023
3340856
Merge branch 'main' into deprecate_old_rpc
xqft Sep 1, 2023
fcccf58
Fix clippy
xqft Sep 1, 2023
94638d4
Add support for `DeployAccount` transactions.
azteca1998 Sep 4, 2023
0dcce62
Make `create_for_simulation` public and use it.
azteca1998 Sep 4, 2023
ed001ee
Fix clippy issues.
azteca1998 Sep 4, 2023
098f14a
Merge branch 'main' into deprecate_old_rpc
xqft Sep 4, 2023
ab48bb5
Replaced try_from with from_invoke_transaction
xqft Sep 4, 2023
8b83cd2
infer version
edg-l Sep 4, 2023
52dd83c
Fix version
xqft Sep 4, 2023
8e50309
Changed test_try_from_invoke
xqft Sep 4, 2023
a0d34e6
Ignore test_recent_tx
xqft Sep 4, 2023
ce4060b
Refactor tx deser, (un)ignore tests
xqft Sep 4, 2023
46c2f48
Merge branch 'deprecate_old_rpc' into add-declare-transactions-rpcsta…
azteca1998 Sep 4, 2023
453ef5f
Reimplement everythin in the new rpc state reader.
azteca1998 Sep 4, 2023
2d99cf3
Fix review comments.
azteca1998 Sep 6, 2023
f0300cc
Merge branch 'main' into add-declare-transactions-rpcstatereader
azteca1998 Sep 8, 2023
710e26f
Ignore failing tests from the old API.
azteca1998 Sep 8, 2023
05e0a66
Fix formatting.
azteca1998 Sep 8, 2023
cedfd7e
Revert deprecated RPC state reader.
azteca1998 Sep 8, 2023
676ae65
Merge branch 'main' into add-declare-transactions-rpcstatereader
azteca1998 Sep 12, 2023
bc44f04
Fix stuff and add conversions.
azteca1998 Sep 12, 2023
85bea77
More stuff.
azteca1998 Sep 13, 2023
e9f20a9
More stuff.
azteca1998 Sep 13, 2023
2956eaa
Make it compile.
azteca1998 Sep 13, 2023
5758902
Merge branch 'main' into add-declare-transactions-rpcstatereader
azteca1998 Sep 18, 2023
ed5bf48
Fix block numbers.
azteca1998 Sep 18, 2023
1ed5bc4
Use `Arc<_>` in `MaybeSierraContractClass`
azteca1998 Sep 19, 2023
1f7ae8c
Add `skip_nonce_check` to `DeployAccount`.
azteca1998 Sep 20, 2023
3adfaa8
Fix stuff.
azteca1998 Sep 20, 2023
9d1bf0a
Merge branch 'main' into add-declare-transactions-rpcstatereader
azteca1998 Sep 21, 2023
f29808c
Display the RPC error within the `RpcError` error enum.
azteca1998 Sep 21, 2023
96ce59b
Merge branch 'main' into add-declare-transactions-rpcstatereader
azteca1998 Sep 22, 2023
62cdc87
Fix after merge.
azteca1998 Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 35 additions & 8 deletions rpc_state_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ mod tests {
);

assert_eq!(
tx_trace.validate_invocation.calldata,
tx_trace.validate_invocation.as_ref().unwrap().calldata,
Some(vec![
stark_felt!("1"),
stark_felt!("690c876e61beda61e994543af68038edac4e1cb1990ab06e52a2d27e56a1232"),
Expand All @@ -157,9 +157,16 @@ mod tests {
stark_felt!("38bd34c31a0a5c"),
])
);
assert_eq!(tx_trace.validate_invocation.retdata, Some(vec![]));
assert_eq!(
tx_trace.validate_invocation.as_ref().unwrap().retdata,
Some(vec![])
);
assert_eq_sorted!(
tx_trace.validate_invocation.execution_resources,
tx_trace
.validate_invocation
.as_ref()
.unwrap()
.execution_resources,
ExecutionResources {
n_steps: 790,
n_memory_holes: 51,
Expand All @@ -170,7 +177,15 @@ mod tests {
]),
}
);
assert_eq!(tx_trace.validate_invocation.internal_calls.len(), 1);
assert_eq!(
tx_trace
.validate_invocation
.as_ref()
.unwrap()
.internal_calls
.len(),
1
);

assert_eq!(
tx_trace.function_invocation.as_ref().unwrap().calldata,
Expand Down Expand Up @@ -243,19 +258,23 @@ mod tests {
);

assert_eq!(
tx_trace.fee_transfer_invocation.calldata,
tx_trace.fee_transfer_invocation.as_ref().unwrap().calldata,
Some(vec![
stark_felt!("1176a1bd84444c89232ec27754698e5d2e7e1a7f1539f12027f28b23ec9f3d8"),
stark_felt!("2b0322a23ba4"),
stark_felt!("0"),
])
);
assert_eq!(
tx_trace.fee_transfer_invocation.retdata,
tx_trace.fee_transfer_invocation.as_ref().unwrap().retdata,
Some(vec![1u128.into()])
);
assert_eq_sorted!(
tx_trace.fee_transfer_invocation.execution_resources,
tx_trace
.fee_transfer_invocation
.as_ref()
.unwrap()
.execution_resources,
ExecutionResources {
n_steps: 586,
n_memory_holes: 42,
Expand All @@ -265,7 +284,15 @@ mod tests {
]),
}
);
assert_eq!(tx_trace.fee_transfer_invocation.internal_calls.len(), 1);
assert_eq!(
tx_trace
.fee_transfer_invocation
.as_ref()
.unwrap()
.internal_calls
.len(),
1
);
}

#[test]
Expand Down
43 changes: 36 additions & 7 deletions rpc_state_reader/src/rpc_state.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::utils;
use cairo_vm::vm::runners::cairo_runner::ExecutionResources as VmExecutionResources;
use core::fmt;
use dotenv::dotenv;
Expand All @@ -14,8 +15,6 @@ use starknet_api::{
use std::{collections::HashMap, env, fmt::Display};
use thiserror::Error;

use crate::utils;

/// Starknet chains supported in Infura.
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)]
pub enum RpcChain {
Expand Down Expand Up @@ -142,14 +141,42 @@ pub struct RpcBlockInfo {
/// A RPC response.
#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
pub struct RpcResponse<T> {
result: T,
result: Option<T>,
error: Option<RpcResponseError>,
}

impl<T> RpcResponse<T> {
fn into_result(self) -> Result<T, RpcError> {
match (self.result, self.error) {
(None, None) => panic!("API returned neither a result nor an error"),
(None, Some(error)) => Err(RpcError::RpcCall(match error.data {
Some(data) => format!(
"The API returned an error {} '{}' with data '{}'",
error.code, error.message, data
),
None => format!(
"The API returned an error {} '{}'",
error.code, error.message
),
})),
(Some(result), None) => Ok(result),
(Some(_), Some(_)) => panic!("API returned both a result and an error"),
}
}
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Hash, PartialOrd, Ord)]
pub struct RpcResponseError {
code: i32,
message: String,
data: Option<String>,
}

#[derive(Debug, Deserialize, Clone, Eq, PartialEq)]
pub struct TransactionTrace {
pub validate_invocation: RpcCallInfo,
pub validate_invocation: Option<RpcCallInfo>,
pub function_invocation: Option<RpcCallInfo>,
pub fee_transfer_invocation: RpcCallInfo,
pub fee_transfer_invocation: Option<RpcCallInfo>,
pub signature: Vec<StarkFelt>,
pub revert_error: Option<String>,
}
Expand Down Expand Up @@ -270,7 +297,8 @@ impl RpcState {
method: &str,
params: &serde_json::Value,
) -> Result<T, RpcError> {
Ok(self.rpc_call::<RpcResponse<T>>(method, params)?.result)
self.rpc_call::<RpcResponse<T>>(method, params)?
.into_result()
}

fn rpc_call<T: for<'a> Deserialize<'a>>(
Expand Down Expand Up @@ -302,7 +330,8 @@ impl RpcState {
fn deserialize_call<T: for<'a> Deserialize<'a>>(
response: serde_json::Value,
) -> Result<T, RpcError> {
serde_json::from_value(response).map_err(|err| RpcError::RpcCall(err.to_string()))
serde_json::from_value(response.clone())
.map_err(|err| RpcError::RpcCall(format!("'{}' while deserializing {}", err, response)))
}

/// Gets the url of the feeder endpoint
Expand Down
20 changes: 19 additions & 1 deletion rpc_state_reader/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use starknet_api::{
core::EntryPointSelector,
deprecated_contract_class::{EntryPoint, EntryPointOffset, EntryPointType},
hash::{StarkFelt, StarkHash},
transaction::{InvokeTransaction, Transaction},
transaction::{DeclareTransaction, InvokeTransaction, Transaction},
};

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -82,6 +82,24 @@ pub fn deserialize_transaction_json(
"unimplemented invoke version: {x}"
))),
},
"DECLARE" => match tx_version.as_str() {
"0x0" => Ok(Transaction::Declare(DeclareTransaction::V0(
serde_json::from_value(transaction)?,
))),
"0x1" => Ok(Transaction::Declare(DeclareTransaction::V1(
serde_json::from_value(transaction)?,
))),
"0x2" => Ok(Transaction::Declare(DeclareTransaction::V2(
serde_json::from_value(transaction)?,
))),
x => Err(serde::de::Error::custom(format!(
"unimplemented declare version: {x}"
))),
},
"DEPLOY" => Ok(Transaction::Deploy(serde_json::from_value(transaction)?)),
"DEPLOY_ACCOUNT" => Ok(Transaction::DeployAccount(serde_json::from_value(
transaction,
)?)),
x => Err(serde::de::Error::custom(format!(
"unimplemented transaction type deserialization: {x}"
))),
Expand Down
Loading