Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_class/get_class_at implemented #126

Merged
merged 75 commits into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
6a4418f
Refactoring builder
Jul 12, 2023
24233c7
Make rpc, http required for a builder
Jul 12, 2023
9740039
Raw changes
Jul 13, 2023
3e014a3
Impl file introduced
Jul 13, 2023
909850e
Merge branch 'main' into cases/get_class_impls
Jul 17, 2023
ddf28c3
Some raw changes
Jul 17, 2023
aa39801
Raw changes. Need to keep sierra contracts in Starknet
Jul 17, 2023
9c92dc0
Single starknet impl
Jul 17, 2023
305f9f0
Added sierra contract + tests
Jul 17, 2023
ae81619
Formatted code
Jul 17, 2023
7f04552
Update README.md; trigger CI
FabijanC Jul 18, 2023
526e2b4
Unused error
Jul 18, 2023
99eaefb
Merge branch 'cases/starknet/store_sierra' of github.com:0xSpaceShard…
Jul 18, 2023
70e0479
Merge branch 'main' into cases/starknet/store_sierra
Jul 18, 2023
100ec39
Formatting applied
Jul 18, 2023
a59d02e
Merge branch 'cases/starknet/store_sierra' into cases/get_class_impls
Jul 26, 2023
29c498d
Raw commit
Jul 26, 2023
7563bea
Raw changes with serialization
Jul 27, 2023
36b7dfa
Compiles
Jul 27, 2023
8d82968
Merge branch 'main' into cases/get_class_impls
Jul 27, 2023
4e8ed28
Conflict resolved
Jul 27, 2023
4c1ddd2
Removed FeltHex
Jul 27, 2023
30419ee
Merge pull request #114 from 0xSpaceShard/cases/models-to-types
taco-paco Jul 28, 2023
d23c5c0
Merge branch 'main' into cases/get_class_impls
Aug 1, 2023
93ea518
Compilation fixed
Aug 1, 2023
c6ca44a
Merge branch 'cases/get_class_impls' of github.com:0xSpaceShard/stark…
Aug 1, 2023
e6a7259
Compilation fixed
Aug 1, 2023
9d17b17
Separate serde_helpers until fully migrated
Aug 1, 2023
aa6098f
ContractAddressHex -> ContractAddress
Aug 1, 2023
be6a4c4
ContractAddressHex -> ContractAddress
Aug 1, 2023
bf5daf3
Compilation fixes
Aug 1, 2023
42d47ce
Moved to types
Aug 1, 2023
8d2e152
Formating applied
Aug 1, 2023
3984aff
Merge branch 'cases/ContractAddressHex-To-ContractAddress' into cases…
Aug 1, 2023
2e2bfc1
Conpilation fixes
Aug 1, 2023
4372583
models::ContractClass -> types::ContractClass
Aug 1, 2023
f42aaa7
Compilation fixed after contract_class moved to types.
Aug 1, 2023
cb509c5
models/ContractClass -> types/ContractClass
Aug 3, 2023
66dfdc0
Raw changes
Aug 3, 2023
6695c12
Research DeclareTransactionV1::contract_class possible types
Aug 3, 2023
8ba20de
Compare results main
Aug 4, 2023
70235b9
Test fixes
Aug 7, 2023
ba49cb9
Tests fixed. correct class_hash
Aug 7, 2023
84a4461
get_class_impl done
Aug 7, 2023
450f845
Added some tests
Aug 7, 2023
a1ffb8d
Test fixes
Aug 8, 2023
274c483
Renamed data -> test_data
Aug 8, 2023
aaa917d
Removed test compilation warnings
Aug 8, 2023
a007274
Merge branch 'main' into cases/get_class_impls
Aug 8, 2023
373f4cb
Fix merge conflicts + clippy compilation fixes
Aug 8, 2023
df9602a
Merge branch 'main' into cases/ContractAddressHex-To-ContractAddress
Aug 8, 2023
be80d68
Clippy compilation fixes
Aug 8, 2023
e8385fd
Fixed pr comment
Aug 8, 2023
ecbb598
Merge branch 'cases/ContractAddressHex-To-ContractAddress' into cases…
Aug 8, 2023
63215de
Removed serde_helpers from starknet-server
Aug 8, 2023
5bc56fe
Stylistic edits
Aug 8, 2023
36f9ced
Convert ContracClass to codegen ContractClass
Aug 9, 2023
6c8df45
Follow up
Aug 9, 2023
648f94c
Cherry-picked from refactoring branch
Aug 13, 2023
f2854c0
Tests passed. Serialization fixed
Aug 13, 2023
f0ea419
Deleted sierra
Aug 13, 2023
50e3684
Added test + some cleaning
Aug 13, 2023
e2a363a
Fixed conversion to CodegenSierraClass
Aug 14, 2023
edc734a
Merge branch 'cases/merge/get_class_impls' into cases/get_class_impls
Aug 14, 2023
8230661
Merge branch 'main' into cases/get_class_impls
Aug 14, 2023
f3475f5
Compilation + some test fixes after merge
Aug 14, 2023
9a7488a
Formatting applied + clippy fixes
Aug 14, 2023
09cf010
Revert fmt changes + formatting applied
Aug 14, 2023
c7f1c9d
Remove mut access
Aug 14, 2023
0fff809
Deleted contract_class.rs from modules
Aug 14, 2023
a93bd40
Revert changes
Aug 14, 2023
b3066c8
Pr fixes
Aug 15, 2023
1e9eb4a
Removed old errors
Aug 15, 2023
3c789dd
Moved empty params into starknet-server
Aug 15, 2023
7ad9187
Get class impls ci (#131)
marioiordanov Aug 15, 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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ tower-http = { version = "0.4", features = ["full"] }
tower = { version = "0.4", features = ["full"] }

# rpc
rpc-core = { git = "https://github.com/foundry-rs/foundry.git", package = "anvil-rpc" }
rpc-core = { git = "https://github.com/foundry-rs/foundry", rev = "5f2262736feaeabadeef2ae989a78e9b43da8eee", package = "anvil-rpc" }

# async
tokio = { version = "1", features = ["time", "macros", "rt-multi-thread"] }
Expand Down
57 changes: 38 additions & 19 deletions crates/starknet-server/src/api/json_rpc/endpoints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use starknet_in_rust::core::errors::state_errors::StateError;
use starknet_in_rust::definitions::block_context::StarknetChainId;
use starknet_in_rust::transaction::error::TransactionError;
use starknet_in_rust::utils::Address;
use starknet_rs_core::types::ContractClass as CodegenContractClass;
use starknet_types::contract_address::ContractAddress;
use starknet_types::felt::{ClassHash, Felt, TransactionHash};
use starknet_types::starknet_api::block::BlockNumber;
Expand All @@ -16,7 +17,6 @@ use super::write_endpoints::{
};
use super::{JsonRpcHandler, RpcResult};
use crate::api::models::block::{Block, BlockHeader};
use crate::api::models::contract_class::ContractClass;
use crate::api::models::state::{
ClassHashes, ContractNonce, DeployedContract, StateUpdate, StorageDiff, StorageEntry,
ThinStateDiff,
Expand Down Expand Up @@ -196,10 +196,37 @@ impl JsonRpcHandler {
/// starknet_getClass
pub(crate) async fn get_class(
&self,
_block_id: BlockId,
_class_hash: ClassHash,
) -> RpcResult<ContractClass> {
Err(error::ApiError::ClassHashNotFound)
block_id: BlockId,
class_hash: ClassHash,
) -> RpcResult<CodegenContractClass> {
match self.api.starknet.read().await.get_class(block_id.into(), class_hash) {
Ok(contract_class) => Ok(contract_class.try_into()?),
Err(Error::NoBlock) => Err(ApiError::BlockNotFound),
Err(
Error::ContractNotFound
| Error::StateError(StateError::NoneContractState(_))
| Error::NoStateAtBlock { block_number: _ },
) => Err(ApiError::ContractNotFound),
Err(unknown_error) => Err(ApiError::StarknetDevnetError(unknown_error)),
}
}

/// starknet_getClassAt
pub(crate) async fn get_class_at(
&self,
block_id: BlockId,
contract_address: ContractAddress,
) -> RpcResult<CodegenContractClass> {
match self.api.starknet.read().await.get_class_at(block_id.into(), contract_address) {
Ok(contract_class) => Ok(contract_class.try_into()?),
Err(Error::NoBlock) => Err(ApiError::BlockNotFound),
Err(
Error::ContractNotFound
| Error::StateError(StateError::NoneContractState(_))
| Error::NoStateAtBlock { block_number: _ },
) => Err(ApiError::ContractNotFound),
Err(unknown_error) => Err(ApiError::StarknetDevnetError(unknown_error)),
}
}

/// starknet_getClassHashAt
Expand All @@ -208,26 +235,18 @@ impl JsonRpcHandler {
block_id: BlockId,
contract_address: ContractAddress,
) -> RpcResult<ClassHash> {
let starknet = self.api.starknet.read().await;
match starknet.get_class_hash_at(&block_id.into(), &contract_address) {
match self.api.starknet.read().await.get_class_hash_at(block_id.into(), contract_address) {
Ok(class_hash) => Ok(class_hash),
Err(Error::NoBlock) => Err(ApiError::BlockNotFound),
Err(Error::ContractNotFound | Error::NoStateAtBlock { block_number: _ }) => {
Err(ApiError::ContractNotFound)
}
Err(
Error::ContractNotFound
| Error::StateError(StateError::NoneContractState(_))
| Error::NoStateAtBlock { block_number: _ },
) => Err(ApiError::ContractNotFound),
Err(unknown_error) => Err(ApiError::StarknetDevnetError(unknown_error)),
}
}

/// starknet_getClassAt
pub(crate) async fn get_class_at(
&self,
_block_id: BlockId,
_contract_address: ContractAddress,
) -> RpcResult<ContractClass> {
Err(error::ApiError::ContractNotFound)
}

/// starknet_getBlockTransactionCount
pub(crate) async fn get_block_txs_count(&self, block_id: BlockId) -> RpcResult<u64> {
let num_trans_count = self.api.starknet.read().await.get_block_txs_count(block_id.into());
Expand Down
6 changes: 5 additions & 1 deletion crates/starknet-server/src/api/json_rpc/models.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,11 @@ mod tests {
"type": "function"
}],
"program": "",
"entry_points_by_type": {}
"entry_points_by_type": {
"CONSTRUCTOR": [],
"EXTERNAL": [],
"L1_HANDLER": []
}
}
},
{
Expand Down
30 changes: 2 additions & 28 deletions crates/starknet-server/src/api/json_rpc/write_endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
use serde_json::json;
use server::rpc_core::error::RpcError;
use starknet_core::transactions::declare_transaction::DeclareTransactionV1;
use starknet_core::transactions::declare_transaction_v2::DeclareTransactionV2;
use starknet_core::transactions::deploy_account_transaction::DeployAccountTransaction;
use starknet_core::transactions::invoke_transaction::InvokeTransactionV1;
use starknet_types::contract_class::ContractClass;
use starknet_types::felt::Felt;

use super::error::ApiError;
Expand All @@ -13,7 +11,6 @@ use super::models::{
};
use super::RpcResult;
use crate::api::json_rpc::JsonRpcHandler;
use crate::api::models::contract_class::DeprecatedContractClass;
use crate::api::models::transaction::{
BroadcastedDeclareTransaction, BroadcastedDeclareTransactionV1,
BroadcastedDeclareTransactionV2, BroadcastedDeployAccountTransaction,
Expand Down Expand Up @@ -90,29 +87,6 @@ impl JsonRpcHandler {
}
}

impl TryFrom<DeprecatedContractClass> for ContractClass {
type Error = ApiError;

fn try_from(value: DeprecatedContractClass) -> RpcResult<Self> {
let abi_json = serde_json::to_value(value.abi).map_err(|_| {
ApiError::RpcError(RpcError::invalid_params("abi: Unable to parse to JSON"))
})?;
let entry_points_json = serde_json::to_value(value.entry_points_by_type).map_err(|_| {
ApiError::RpcError(RpcError::invalid_params(
"entry_points_by_type: Unable to parse to JSON",
))
})?;

Ok(ContractClass::Cairo0(starknet_types::contract_class::Cairo0ContractClass::Json(
json!({
"program": value.program,
"abi": abi_json,
"entry_points_by_type": entry_points_json,
}),
)))
}
}

pub(crate) fn convert_to_declare_transaction_v1(
value: BroadcastedDeclareTransactionV1,
chain_id: Felt,
Expand All @@ -122,7 +96,7 @@ pub(crate) fn convert_to_declare_transaction_v1(
value.common.max_fee.0,
value.common.signature,
value.common.nonce,
ContractClass::try_from(value.contract_class)?,
value.contract_class.into(),
chain_id,
)
.map_err(ApiError::StarknetDevnetError)
Expand Down Expand Up @@ -155,7 +129,7 @@ pub(crate) fn convert_to_declare_transaction_v2(
chain_id: Felt,
) -> RpcResult<DeclareTransactionV2> {
DeclareTransactionV2::new(
ContractClass::from(value.contract_class),
value.contract_class,
value.compiled_class_hash,
value.sender_address,
value.common.max_fee.0,
Expand Down
Loading