From c542d099b12df41868bcc9ea9cea095d32b207aa Mon Sep 17 00:00:00 2001 From: code0xff Date: Mon, 9 Sep 2024 18:46:39 +0900 Subject: [PATCH] refactor: Move cosmos rpc and runtime-api to pallet-cosmos --- Cargo.toml | 6 ++---- {client => frame/cosmos}/rpc/Cargo.toml | 4 ++-- {client => frame/cosmos}/rpc/src/cosmos.rs | 4 ++-- {client => frame/cosmos}/rpc/src/lib.rs | 0 {primitives/rpc => frame/cosmos/runtime-api}/Cargo.toml | 2 +- {primitives/rpc => frame/cosmos/runtime-api}/src/lib.rs | 2 +- frame/cosmwasm/src/lib.rs | 2 +- template/node/Cargo.toml | 4 ++-- template/node/src/rpc.rs | 4 ++-- template/runtime/Cargo.toml | 4 ++-- template/runtime/src/lib.rs | 4 ++-- 11 files changed, 17 insertions(+), 19 deletions(-) rename {client => frame/cosmos}/rpc/Cargo.toml (86%) rename {client => frame/cosmos}/rpc/src/cosmos.rs (95%) rename {client => frame/cosmos}/rpc/src/lib.rs (100%) rename {primitives/rpc => frame/cosmos/runtime-api}/Cargo.toml (95%) rename {primitives/rpc => frame/cosmos/runtime-api}/src/lib.rs (98%) diff --git a/Cargo.toml b/Cargo.toml index 821fada..a941ef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,6 @@ [workspace] resolver = "2" members = [ - "client/rpc", "frame/accounts", "frame/cosmos", "frame/cosmwasm", @@ -17,7 +16,6 @@ members = [ "frame/cosmos/x/wasm/types", "primitives/account", "primitives/io", - "primitives/rpc", "template/runtime", "template/node", "cosmwasm/std", @@ -110,15 +108,15 @@ substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk fp-self-contained = { git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", default-features = false } # Horizon -hc-rpc = { path = "client/rpc" } hp-account = { path = "primitives/account", default-features = false } hp-crypto = { path = "primitives/crypto", default-features = false } hp-io = { path = "primitives/io", default-features = false } -hp-rpc = { path = "primitives/rpc", default-features = false } pallet-cosmos = { path = "frame/cosmos", default-features = false } pallet-cosmos-accounts = { path = "frame/accounts", default-features = false } horizon-template-runtime = { path = "template/runtime", default-features = false } +pallet-cosmos-rpc = { path = "frame/cosmos/rpc" } +pallet-cosmos-runtime-api = { path = "frame/cosmos/runtime-api", default-features = false } pallet-cosmos-types = { path = "frame/cosmos/types", default-features = false } pallet-cosmos-x-auth = { path = "frame/cosmos/x/auth", default-features = false } pallet-cosmos-x-auth-migrations = { path = "frame/cosmos/x/auth/migrations", default-features = false } diff --git a/client/rpc/Cargo.toml b/frame/cosmos/rpc/Cargo.toml similarity index 86% rename from client/rpc/Cargo.toml rename to frame/cosmos/rpc/Cargo.toml index d4577fe..740a55b 100644 --- a/client/rpc/Cargo.toml +++ b/frame/cosmos/rpc/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hc-rpc" +name = "pallet-cosmos-rpc" version = "0.1.0" edition = "2021" license = "Apache-2.0" @@ -21,4 +21,4 @@ sp-core = { workspace = true, features = ["std"] } sp-runtime = { workspace = true, features = ["std"] } # Horizon -hp-rpc = { workspace = true, features = ["std"] } +pallet-cosmos-runtime-api = { workspace = true, features = ["std"] } diff --git a/client/rpc/src/cosmos.rs b/frame/cosmos/rpc/src/cosmos.rs similarity index 95% rename from client/rpc/src/cosmos.rs rename to frame/cosmos/rpc/src/cosmos.rs index f9646ac..6b08d9e 100644 --- a/client/rpc/src/cosmos.rs +++ b/frame/cosmos/rpc/src/cosmos.rs @@ -18,11 +18,11 @@ use crate::internal_error; use futures::future::TryFutureExt; -use hp_rpc::{CosmosTxRuntimeApi, SimulateError, SimulateResponse}; use jsonrpsee::{ core::{async_trait, RpcResult}, proc_macros::rpc, }; +use pallet_cosmos_runtime_api::{CosmosRuntimeApi, SimulateError, SimulateResponse}; use sc_transaction_pool_api::TransactionPool; use sp_api::ProvideRuntimeApi; use sp_blockchain::HeaderBackend; @@ -59,7 +59,7 @@ where C: Send + Sync + 'static, C: ProvideRuntimeApi, C: HeaderBackend + 'static, - C::Api: hp_rpc::CosmosTxRuntimeApi, + C::Api: pallet_cosmos_runtime_api::CosmosRuntimeApi, P: TransactionPool + 'static, { async fn broadcast_tx(&self, tx_bytes: Bytes) -> RpcResult { diff --git a/client/rpc/src/lib.rs b/frame/cosmos/rpc/src/lib.rs similarity index 100% rename from client/rpc/src/lib.rs rename to frame/cosmos/rpc/src/lib.rs diff --git a/primitives/rpc/Cargo.toml b/frame/cosmos/runtime-api/Cargo.toml similarity index 95% rename from primitives/rpc/Cargo.toml rename to frame/cosmos/runtime-api/Cargo.toml index 24a081b..e02bb26 100644 --- a/primitives/rpc/Cargo.toml +++ b/frame/cosmos/runtime-api/Cargo.toml @@ -1,5 +1,5 @@ [package] -name = "hp-rpc" +name = "pallet-cosmos-runtime-api" version = "0.1.0" edition = "2021" license = "Apache-2.0" diff --git a/primitives/rpc/src/lib.rs b/frame/cosmos/runtime-api/src/lib.rs similarity index 98% rename from primitives/rpc/src/lib.rs rename to frame/cosmos/runtime-api/src/lib.rs index 6791d8c..8656e0a 100644 --- a/primitives/rpc/src/lib.rs +++ b/frame/cosmos/runtime-api/src/lib.rs @@ -46,7 +46,7 @@ pub enum SimulateError { } sp_api::decl_runtime_apis! { - pub trait CosmosTxRuntimeApi { + pub trait CosmosRuntimeApi { fn convert_tx(tx_bytes: Vec) -> ::Extrinsic; fn simulate(tx_bytes: Vec) -> Result; diff --git a/frame/cosmwasm/src/lib.rs b/frame/cosmwasm/src/lib.rs index de78a40..beca50f 100644 --- a/frame/cosmwasm/src/lib.rs +++ b/frame/cosmwasm/src/lib.rs @@ -43,6 +43,7 @@ pub use pallet::*; use sp_core::H256; pub mod crypto; pub mod dispatchable_call; +pub mod entrypoint; pub mod ibc; pub mod instrument; pub mod pallet_hook; @@ -51,7 +52,6 @@ pub mod runtimes; pub mod types; pub mod utils; pub mod weights; -pub mod entrypoint; const SUBSTRATE_ECDSA_SIGNATURE_LEN: usize = 65; use crate::{ diff --git a/template/node/Cargo.toml b/template/node/Cargo.toml index f7e4b8f..1b76d50 100644 --- a/template/node/Cargo.toml +++ b/template/node/Cargo.toml @@ -59,11 +59,11 @@ sp-wasm-interface = { workspace = true, features = ["std"] } substrate-frame-rpc-system = { workspace = true } # Horizon -hc-rpc = { workspace = true } hp-account = { workspace = true, features = ["std"] } hp-io = { workspace = true, features = ["std"] } -hp-rpc = { workspace = true, features = ["std"] } horizon-template-runtime = { workspace = true, features = ["std"] } +pallet-cosmos-rpc = { workspace = true } +pallet-cosmos-runtime-api = { workspace = true, features = ["std"] } pallet-cosmos-types = { workspace = true, features = ["std", "with-codec"] } pallet-cosmos-x-bank-types = { workspace = true, features = [ "std", diff --git a/template/node/src/rpc.rs b/template/node/src/rpc.rs index 954432e..32e4948 100644 --- a/template/node/src/rpc.rs +++ b/template/node/src/rpc.rs @@ -36,11 +36,11 @@ where C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, C::Api: BlockBuilder, P: TransactionPool + 'static, - C::Api: hp_rpc::CosmosTxRuntimeApi, + C::Api: pallet_cosmos_runtime_api::CosmosRuntimeApi, C::Api: cosmwasm_runtime_api::CosmwasmRuntimeApi>, { use cosmwasm_rpc::{Cosmwasm, CosmwasmApiServer}; - use hc_rpc::{Cosmos, CosmosApiServer}; + use pallet_cosmos_rpc::{Cosmos, CosmosApiServer}; use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; use substrate_frame_rpc_system::{System, SystemApiServer}; diff --git a/template/runtime/Cargo.toml b/template/runtime/Cargo.toml index e355e6d..18b53ba 100644 --- a/template/runtime/Cargo.toml +++ b/template/runtime/Cargo.toml @@ -56,9 +56,9 @@ fp-self-contained = { workspace = true, default-features = false, features = [ hp-account = { workspace = true, default-features = false } hp-crypto = { workspace = true, default-features = false } hp-io = { workspace = true, default-features = false } -hp-rpc = { workspace = true, default-features = false } pallet-cosmos = { workspace = true, default-features = false } pallet-cosmos-accounts = { workspace = true, default-features = false } +pallet-cosmos-runtime-api = { workspace = true, default-features = false } pallet-cosmos-types = { workspace = true, default-features = false, features = [ "with-codec", ] } @@ -113,9 +113,9 @@ std = [ "hp-account/std", "hp-crypto/std", "hp-io/std", - "hp-rpc/std", "pallet-cosmos/std", "pallet-cosmos-accounts/std", + "pallet-cosmos-runtime-api/std", "pallet-cosmos-types/std", "pallet-cosmos-x-auth/std", "pallet-cosmos-x-auth-migrations/std", diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 559b0bf..144a895 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -55,7 +55,6 @@ use frame_support::{ use frame_system::EnsureRoot; use hp_account::CosmosSigner; use hp_crypto::EcdsaExt; -use hp_rpc::{GasInfo, SimulateError, SimulateResponse}; use pallet_cosmos::{ config_preludes::{ AddressPrefix, ChainId, Context, MaxDenomLimit, MaxMemoCharacters, MsgFilter, NativeDenom, @@ -63,6 +62,7 @@ use pallet_cosmos::{ }, AddressMapping, }; +use pallet_cosmos_runtime_api::{GasInfo, SimulateError, SimulateResponse}; use pallet_cosmos_x_auth::sigverify::SECP256K1_TYPE_URL; use pallet_cosmos_x_auth_signing::{ sign_mode_handler::SignModeHandler, sign_verifiable_tx::SigVerifiableTx, @@ -655,7 +655,7 @@ impl Runtime { } impl_runtime_apis! { - impl hp_rpc::CosmosTxRuntimeApi for Runtime { + impl pallet_cosmos_runtime_api::CosmosRuntimeApi for Runtime { fn convert_tx(tx_bytes: Vec) -> ::Extrinsic { UncheckedExtrinsic::new_unsigned( pallet_cosmos::Call::::transact { tx_bytes }.into(),