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

move StarknetRuntimeApi trait definition in its own crate #1272

Merged
merged 6 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## Next release

- refacto: move starknet runtime api in it's own crate
- chore: update README.md and getting-started.md
- chore: remove crates that have been copy-pasted from plkdtSDK
- feat(rpc): return deployed contract address and actual fee in transaction
Expand Down
22 changes: 22 additions & 0 deletions Cargo.lock

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

4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ resolver = "2"
members = [
"crates/node",
"crates/runtime",
"crates/pallets/starknet/runtime_api/",
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
"crates/pallets/starknet",
"crates/primitives/digest-log",
"crates/primitives/transactions",
Expand All @@ -28,6 +29,7 @@ members = [
default-members = [
"crates/node",
"crates/runtime",
"crates/pallets/starknet/runtime_api/",
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
"crates/pallets/starknet",
"crates/primitives/digest-log",
"crates/primitives/transactions",
Expand Down Expand Up @@ -147,7 +149,7 @@ pallet-timestamp = { default-features = false, git = "https://github.com/parityt

# Madara pallets
pallet-starknet = { path = "crates/pallets/starknet", default-features = false }

pallet-starknet-runtime-api = { path = "crates/pallets/starknet/runtime_api", default-features = false }
# Madara primtitives
mp-digest-log = { path = "crates/primitives/digest-log", default-features = false }
mp-block = { path = "crates/primitives/block", default-features = false }
Expand Down
1 change: 1 addition & 0 deletions crates/client/commitment-state-diff/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mp-digest-log = { workspace = true, default-features = true }
mp-hashers = { workspace = true, default-features = true }
mp-storage = { workspace = true, default-features = true }
pallet-starknet = { workspace = true }
pallet-starknet-runtime-api = { workspace = true, default-features = true }

# Starknet
blockifier = { workspace = true, default-features = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/commitment-state-diff/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use futures::{Stream, StreamExt};
use indexmap::IndexMap;
use mp_hashers::HasherT;
use mp_storage::{SN_COMPILED_CLASS_HASH_PREFIX, SN_CONTRACT_CLASS_HASH_PREFIX, SN_NONCE_PREFIX, SN_STORAGE_PREFIX};
use pallet_starknet::runtime_api::StarknetRuntimeApi;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use sc_client_api::client::BlockchainEvents;
use sc_client_api::{StorageEventStream, StorageNotification};
use sp_api::ProvideRuntimeApi;
Expand Down
1 change: 1 addition & 0 deletions crates/client/mapping-sync/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mp-digest-log = { workspace = true }
mp-hashers = { workspace = true }
mp-transactions = { workspace = true }
pallet-starknet = { workspace = true }
pallet-starknet-runtime-api = { workspace = true }
sc-client-api = { workspace = true }
sp-api = { workspace = true }
sp-blockchain = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/mapping-sync/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use futures::task::{Context, Poll};
use futures_timer::Delay;
use log::debug;
use mp_hashers::HasherT;
use pallet_starknet::runtime_api::StarknetRuntimeApi;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use sc_client_api::backend::{Backend, StorageProvider};
use sc_client_api::client::ImportNotifications;
use sp_api::ProvideRuntimeApi;
Expand Down
2 changes: 1 addition & 1 deletion crates/client/mapping-sync/src/sync_blocks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use mc_rpc_core::utils::get_block_by_block_hash;
use mp_digest_log::{find_starknet_block, FindLogError};
use mp_hashers::HasherT;
use mp_transactions::compute_hash::ComputeTransactionHash;
use pallet_starknet::runtime_api::StarknetRuntimeApi;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use sc_client_api::backend::{Backend, StorageProvider};
use sp_api::ProvideRuntimeApi;
use sp_blockchain::{Backend as _, HeaderBackend};
Expand Down
1 change: 1 addition & 0 deletions crates/client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
# Madara runtime
pallet-starknet = { workspace = true, default-features = true }
pallet-starknet-runtime-api = { workspace = true, default-features = true }
# Madara client
mc-db = { workspace = true }
mc-rpc-core = { workspace = true }
Expand Down
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 pallet_starknet::runtime_api::StarknetTransactionExecutionError;
use pallet_starknet_runtime_api::StarknetTransactionExecutionError;

// Comes from the RPC Spec:
// https://github.com/starkware-libs/starknet-specs/blob/0e859ff905795f789f1dfd6f7340cdaf5015acc8/api/starknet_write_api.json#L227
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 @@ -9,7 +9,7 @@ use log::error;
use mc_rpc_core::utils::get_block_by_block_hash;
use mp_felt::Felt252Wrapper;
use mp_hashers::HasherT;
use pallet_starknet::runtime_api::{ConvertTransactionRuntimeApi, StarknetRuntimeApi};
use pallet_starknet_runtime_api::{ConvertTransactionRuntimeApi, StarknetRuntimeApi};
use sc_client_api::backend::{Backend, StorageProvider};
use sc_client_api::BlockBackend;
use sc_transaction_pool::ChainApi;
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 @@ -24,7 +24,7 @@ use mp_hashers::HasherT;
use mp_transactions::compute_hash::ComputeTransactionHash;
use mp_transactions::to_starknet_core_transaction::to_starknet_core_tx;
use mp_transactions::UserTransaction;
use pallet_starknet::runtime_api::{ConvertTransactionRuntimeApi, StarknetRuntimeApi};
use pallet_starknet_runtime_api::{ConvertTransactionRuntimeApi, StarknetRuntimeApi};
use sc_client_api::backend::{Backend, StorageProvider};
use sc_client_api::BlockBackend;
use sc_network_sync::SyncingService;
Expand Down
1 change: 1 addition & 0 deletions crates/client/storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ frame-system = { workspace = true, features = ["std"] }
madara-runtime = { workspace = true, features = ["std"] }
mp-storage = { workspace = true, features = ["std"] }
pallet-starknet = { workspace = true, features = ["std"] }
pallet-starknet-runtime-api = { workspace = true, features = ["std"] }
sc-client-api = { workspace = true }
scale-codec = { workspace = true, features = ["std"] }
sp-api = { workspace = true, features = ["std"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/client/storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use std::sync::Arc;

use mp_storage::{StarknetStorageSchemaVersion, PALLET_STARKNET_SCHEMA};
pub use overrides::*;
use pallet_starknet::runtime_api::StarknetRuntimeApi;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use sc_client_api::backend::{Backend, StorageProvider};
use scale_codec::Decode;
use sp_api::ProvideRuntimeApi;
Expand Down
2 changes: 1 addition & 1 deletion crates/client/storage/src/overrides/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use blockifier::execution::contract_class::ContractClass;
use frame_support::{Identity, StorageHasher};
use mp_storage::StarknetStorageSchemaVersion;
use pallet_starknet::runtime_api::StarknetRuntimeApi;
use pallet_starknet_runtime_api::StarknetRuntimeApi;
use sc_client_api::{Backend, HeaderBackend, StorageProvider};
use sp_api::ProvideRuntimeApi;
use sp_io::hashing::twox_128;
Expand Down
1 change: 1 addition & 0 deletions crates/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ mc-mapping-sync = { workspace = true }
mc-rpc = { workspace = true }
mc-storage = { workspace = true }
pallet-starknet = { workspace = true }
pallet-starknet-runtime-api = { workspace = true }
starknet-core = { workspace = true }

# Primitives
Expand Down
4 changes: 2 additions & 2 deletions crates/node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ where
C: Send + Sync + 'static,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Index>,
C::Api: BlockBuilder<Block>,
C::Api: pallet_starknet::runtime_api::StarknetRuntimeApi<Block>
+ pallet_starknet::runtime_api::ConvertTransactionRuntimeApi<Block>,
C::Api: pallet_starknet_runtime_api::StarknetRuntimeApi<Block>
+ pallet_starknet_runtime_api::ConvertTransactionRuntimeApi<Block>,
P: TransactionPool<Block = Block> + 'static,
BE: Backend<Block> + 'static,
{
Expand Down
47 changes: 47 additions & 0 deletions crates/pallets/starknet/runtime_api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[package]
name = "pallet-starknet-runtime-api"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
# Madara primitives
mp-felt = { workspace = true, features = ["parity-scale-codec", "serde"] }
mp-transactions = { workspace = true, features = [
"parity-scale-codec",
"scale-info",
] }

# Starknet
blockifier = { workspace = true, features = [
"parity-scale-codec",
"scale-info",
] }
hashbrown = { workspace = true }
starknet_api = { workspace = true, features = [
"scale-info",
"parity-scale-codec",
] }

# Substrate
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
sp-api = { workspace = true }
sp-arithmetic = { workspace = true }
sp-runtime = { workspace = true }


[features]
default = ["std"]
std = [
"mp-felt/std",
"mp-transactions/std",
"blockifier/std",
"starknet_api/std",
"sp-api/std",
"sp-runtime/std",
"sp-arithmetic/std",
"parity-scale-codec/std",
"scale-info/std",
]
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Definition of the runtime API for the StarkNet pallet.

#![cfg_attr(not(feature = "std"), no_std)]
tdelabro marked this conversation as resolved.
Show resolved Hide resolved
// Adding allow unused type parameters to avoid clippy errors
// generated by the `decl_runtime_apis` macro.
// Specifically, the macro generates a trait (`StarknetRuntimeApi`) with unused type parameters.
Expand Down
2 changes: 0 additions & 2 deletions crates/pallets/starknet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,6 @@ pub mod blockifier_state_adapter;
pub mod genesis_loader;
/// The implementation of the message type.
pub mod message;
/// The Starknet pallet's runtime API
pub mod runtime_api;
/// Transaction validation logic.
pub mod transaction_validation;
/// The Starknet pallet's runtime custom types.
Expand Down
1 change: 1 addition & 0 deletions crates/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ frame-system-benchmarking = { workspace = true, optional = true }
# Madara Local Dependencies
# Madara Pallets
pallet-starknet = { workspace = true }
pallet-starknet-runtime-api = { workspace = true }

# Madara Primitives
mp-chain-id = { workspace = true }
Expand Down
8 changes: 4 additions & 4 deletions crates/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ use pallet_grandpa::{fg_primitives, AuthorityId as GrandpaId, AuthorityList as G
/// Import the StarkNet pallet.
pub use pallet_starknet;
use pallet_starknet::pallet::Error as PalletError;
use pallet_starknet::runtime_api::StarknetTransactionExecutionError;
use pallet_starknet_runtime_api::StarknetTransactionExecutionError;
use pallet_starknet::Call::{consume_l1_message, declare, deploy_account, invoke};
use pallet_starknet::{Config, Event};
pub use pallet_timestamp::Call as TimestampCall;
Expand Down Expand Up @@ -232,7 +232,7 @@ impl_runtime_apis! {
}
}

impl pallet_starknet::runtime_api::StarknetRuntimeApi<Block> for Runtime {
impl pallet_starknet_runtime_api::StarknetRuntimeApi<Block> for Runtime {

fn get_storage_at(address: ContractAddress, key: StorageKey) -> Result<StarkFelt, DispatchError> {
Starknet::get_storage_at(address, key)
Expand Down Expand Up @@ -362,12 +362,12 @@ impl_runtime_apis! {
Starknet::tx_revert_error(tx_hash).map(|s| s.into_bytes())
}

fn get_block_context() -> pallet_starknet::runtime_api::BlockContext {
fn get_block_context() -> pallet_starknet_runtime_api::BlockContext {
Starknet::get_block_context().into()
}
}

impl pallet_starknet::runtime_api::ConvertTransactionRuntimeApi<Block> for Runtime {
impl pallet_starknet_runtime_api::ConvertTransactionRuntimeApi<Block> for Runtime {
fn convert_transaction(transaction: UserTransaction) -> Result<UncheckedExtrinsic, DispatchError> {
let call = match transaction {
UserTransaction::Declare(tx, contract_class) => {
Expand Down
Loading