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

Commit

Permalink
fix: Add missing GenesisBuilder runtime API (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
conr2d authored Jan 25, 2024
1 parent 146aa6a commit 2f7b897
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 18 deletions.
7 changes: 4 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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 }
Expand All @@ -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" }
Expand Down
5 changes: 3 additions & 2 deletions primitives/cosmos/src/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -63,7 +63,8 @@ impl TryFrom<&cosmrs::Any> for Msg {

fn try_from(msg: &cosmrs::Any) -> Result<Self, Self::Error> {
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::<Vec<Coin>>();
Ok(Self {
r#type: "cosmos-sdk/MsgSend".to_string(),
Expand Down
19 changes: 7 additions & 12 deletions primitives/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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<u8>;
Expand Down Expand Up @@ -217,9 +211,10 @@ impl TryFrom<&cosmrs::Any> for Msg {
type Error = DecodeTxError;

fn try_from(any: &cosmrs::Any) -> Result<Self, Self::Error> {
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() {
Expand Down
2 changes: 2 additions & 0 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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",
Expand Down
14 changes: 13 additions & 1 deletion template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -675,4 +677,14 @@ impl_runtime_apis! {
None
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn create_default_config() -> Vec<u8> {
create_default_config::<RuntimeGenesisConfig>()
}

fn build_config(config: Vec<u8>) -> sp_genesis_builder::Result {
build_config::<RuntimeGenesisConfig>(config)
}
}
}

0 comments on commit 2f7b897

Please sign in to comment.