From 6b3579834821f4381721c665d0e8f56c1c7b2c6e Mon Sep 17 00:00:00 2001 From: Jeeyong Um Date: Thu, 25 Jan 2024 19:12:08 +0900 Subject: [PATCH] fix: Add missing GenesisBuilder runtime API --- Cargo.toml | 7 ++++--- primitives/cosmos/src/legacy.rs | 5 +++-- primitives/cosmos/src/lib.rs | 19 +++++++------------ template/runtime/Cargo.toml | 2 ++ template/runtime/src/lib.rs | 14 +++++++++++++- 5 files changed, 29 insertions(+), 18 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2555c9f6..371d1f8a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,11 +17,11 @@ array-bytes = "6.2.2" base64ct = { version = "1.6.0", default-features = false } bech32 = { version = "0.9.1", default-features = false } clap = { version = "4.0.9", features = ["derive"] } -cosmrs = "0.14.0" +cosmrs = "0.15.0" futures = "0.3.28" hex = "0.4.3" jsonrpsee = "0.16.2" -num_enum = { version = "0.6.1", default-features = false } +num_enum = { version = "0.7.2", default-features = false } parity-scale-codec = { version = "3.2.0", default-features = false } ripemd = { version = "0.1.3", default-features = false } scale-info = { version = "2.3.0", default-features = false } @@ -65,6 +65,7 @@ sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } sp-consensus-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } sp-consensus-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } +sp-genesis-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } sp-inherents = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0", default-features = false } @@ -81,7 +82,7 @@ substrate-build-script-utils = { git = "https://github.com/paritytech/polkadot-s substrate-frame-rpc-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.6.0" } # Frontier -fp-self-contained = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.6.0", default-features = false } +fp-self-contained = { git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.6.0", default-features = false } # Horizon hc-rpc = { path = "client/rpc" } diff --git a/primitives/cosmos/src/legacy.rs b/primitives/cosmos/src/legacy.rs index eebdd0a6..88ea8247 100644 --- a/primitives/cosmos/src/legacy.rs +++ b/primitives/cosmos/src/legacy.rs @@ -16,7 +16,7 @@ // limitations under the License. use crate::error::DecodeTxError; -use cosmrs::{proto::cosmos::bank::v1beta1::MsgSend, tx::MessageExt}; +use cosmrs::proto::cosmos::bank::v1beta1::MsgSend; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Debug, Clone)] @@ -63,7 +63,8 @@ impl TryFrom<&cosmrs::Any> for Msg { fn try_from(msg: &cosmrs::Any) -> Result { if msg.type_url == "/cosmos.bank.v1beta1.MsgSend" { - let msg_send = MsgSend::from_any(msg).map_err(|_| DecodeTxError::InvalidMsgData)?; + let msg_send: MsgSend = + cosmrs::Any::to_msg(msg).map_err(|_| DecodeTxError::InvalidMsgData)?; let amount = msg_send.amount.iter().map(|c| c.into()).collect::>(); Ok(Self { r#type: "cosmos-sdk/MsgSend".to_string(), diff --git a/primitives/cosmos/src/lib.rs b/primitives/cosmos/src/lib.rs index b8a46281..626f9dfb 100644 --- a/primitives/cosmos/src/lib.rs +++ b/primitives/cosmos/src/lib.rs @@ -22,13 +22,7 @@ pub mod error; mod legacy; #[cfg(feature = "std")] -use core::str::FromStr; -#[cfg(feature = "std")] -use cosmrs::tendermint::chain; -#[cfg(feature = "std")] -use cosmrs::tx::SignMode; -#[cfg(feature = "std")] -use cosmrs::{self, tx::MessageExt}; +use cosmrs::{tendermint::chain, tx::SignMode}; #[cfg(feature = "std")] use error::DecodeTxError; #[cfg(feature = "std")] @@ -40,11 +34,11 @@ use scale_info::TypeInfo; #[cfg(feature = "with-serde")] use serde::{Deserialize, Serialize}; #[cfg(feature = "std")] -use sp_core::hashing::sha2_256; -#[cfg(feature = "std")] -use sp_core::Bytes; +use sp_core::{hashing::sha2_256, Bytes}; use sp_core::{H160, H256}; use sp_std::vec::Vec; +#[cfg(feature = "std")] +use std::str::FromStr; pub type SequenceNumber = u64; pub type SignatureBytes = Vec; @@ -217,9 +211,10 @@ impl TryFrom<&cosmrs::Any> for Msg { type Error = DecodeTxError; fn try_from(any: &cosmrs::Any) -> Result { + use cosmrs::proto::cosmos::bank::v1beta1::MsgSend; if any.type_url == "/cosmos.bank.v1beta1.MsgSend" { - let typed_msg = cosmrs::proto::cosmos::bank::v1beta1::MsgSend::from_any(any) - .map_err(|_| DecodeTxError::InvalidMsgData)?; + let typed_msg: MsgSend = + cosmrs::Any::to_msg(any).map_err(|_| DecodeTxError::InvalidMsgData)?; let typed_msg: cosmrs::bank::MsgSend = typed_msg.try_into().map_err(|_| DecodeTxError::InvalidMsgData)?; if typed_msg.amount.is_empty() { diff --git a/template/runtime/Cargo.toml b/template/runtime/Cargo.toml index 9951402a..3baa3f66 100644 --- a/template/runtime/Cargo.toml +++ b/template/runtime/Cargo.toml @@ -18,6 +18,7 @@ sp-api = { workspace = true } sp-block-builder = { workspace = true } sp-consensus-aura = { workspace = true } sp-core = { workspace = true } +sp-genesis-builder = { workspace = true } sp-inherents = { workspace = true } sp-offchain = { workspace = true } sp-runtime = { workspace = true } @@ -63,6 +64,7 @@ std = [ "sp-block-builder/std", "sp-consensus-aura/std", "sp-core/std", + "sp-genesis-builder/std", "sp-offchain/std", "sp-runtime/std", "sp-std/std", diff --git a/template/runtime/src/lib.rs b/template/runtime/src/lib.rs index 26c6f97f..92edc388 100644 --- a/template/runtime/src/lib.rs +++ b/template/runtime/src/lib.rs @@ -29,7 +29,9 @@ include!(concat!(env!("OUT_DIR"), "/wasm_binary.rs")); mod compat; use frame_support::{ - construct_runtime, derive_impl, parameter_types, + construct_runtime, derive_impl, + genesis_builder_helper::{build_config, create_default_config}, + parameter_types, traits::{ tokens::{fungible, Fortitude, Preservation}, ConstBool, ConstU32, ConstU8, OnTimestampSet, @@ -675,4 +677,14 @@ impl_runtime_apis! { None } } + + impl sp_genesis_builder::GenesisBuilder for Runtime { + fn create_default_config() -> Vec { + create_default_config::() + } + + fn build_config(config: Vec) -> sp_genesis_builder::Result { + build_config::(config) + } + } }