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

Commit

Permalink
refactor: Improve pallet-cosmos and runtime in horizon-template-node (#…
Browse files Browse the repository at this point in the history
…33)

* refactor: Refactor cosmos host functions

* refactor: Add support for tuple ante decorators (#25)

* refactor: Rename decode cosmos error

* feat: Add known msg decorator

* refactor: Rename cosmos modules

* refactor: Separate cosmos msg from primitives

* refactor: Refactor decode cosmos tx

* refactor: Add transcoder for converting protobuf to scale

* refactor: Restructure hp-cosmos into pallet-cosmos-types

* refactor: Refactor chain id

* refactor: Add cosmos type registry

* refactor: Refactor legacy msg

* refactor: Rename sign bytes

* refactor: Remove unused code

* feat: Add weight to transact call

* feat: Add tx get signers

* feat: Add fee payer

* fix: Fix set cosmos tx origin

* feat: Add validate sig count decorator

* feat: Add increment sequence decorator

* refactor: Separate coin struct from tx

* refactor: Remove unused error

* refactor: Add conditional compilation for sp_std::vec::Vec import

* fix: Fix msg send weight

* feat: Add default config to pallet-cosmos

* chore: Merge pallet-cosmos-x to pallet-cosmos-types

* refactor: Add conversion from Any to cosmrs::Any

* fix: Add no_default to Currency in pallet_cosmos

* feat: Add cosmos event

* feat: Add event type

* feat: Add msg send events

* fix: Fix migration bug

* fix: Remove unused error

* fix: Fix std sign doc creation bug

* fix: Fix typo

* feat: Apply cosmos proto types (#26)

* build(deps): Add no_std version of `cosmos-sdk-proto`

* feat: Directly apply protobuf type

* feat: Apply protobuf tx to ante decorators

* feat: Apply protobuf type to msg send

* feat: Apply protobuf type to pallet cosmos

* feat: Add types to pallet cosmos

* feat: Add get signers and sign bytes to msg send

* feat: Implement get sign bytes and get signers

* test: Add get sign bytes test

* test: Add get std sign bytes test

* fix: Remove ripemd160 host function

* fix: Fix add fee payer bug

* fix: Add error handlings

* feat: Implement check_self_contained

* refactor: Add get address from bech32

* fix: Re-enable transaction validation check

* docs: Refactor pallet cosmos annotations

* feat: Add get sequence from transaction

* feat: Add default weight to pallet cosmos

* fix: Add get sequence to validate transaction in pool

* refactor: Refactor dependencies

---------

Co-authored-by: Jeeyong Um <[email protected]>
Co-authored-by: Jungyong Um <[email protected]>

* feat: Add cosmos tx simulate json rpc (#27)

* feat: Add cosmos transaction simulation json rpc

* feat: Add simulate json rpc

* feat: Add events to simulate response

* fix: Fix simulate return type

* fix: Fix check tx event handling in sidecar

* feat: Transform raw type event values to string in simulate

* fix: Fix search tx bug

* fix: Fix typos

* fix: Fix pallet cosmos event

---------

Co-authored-by: Jungyong Um <[email protected]>

* feat: Add cosmos error (#28)

* feat: Add module error to pallet cosmos

* refactor: Refactor get fee payer from tx

* refactor: Refactor get fee from tx

* fix: Change event and error names

* feat: Add cosmos errors

* fix: Add codespace to check result

* refactor: Refactor remove 0x from hex string

* feat: Add error to simulate rpc

* feat: Add pallet assets to support multiple assets (#29)

* feat: Add pallet assets

* feat: Add asset id to denom converter

* feat: Add asset transfer

* feat: Add denom asset router

* feat: Add genesis build for register denom asset routes

* feat: Add denom asset route example to chain spec

* fix: Set deposit values

* feat: Add deduct fee decorator (#30)

* feat: Add deduct fee decorator

* feat: Add deduct fee events

* feat: Add simulate query to json rpc

* fix: Fix decode tx to get fee error

* refactor: Remove unused code

* fix: Fix keplr gas rate settings

* chore: Add asset transfer todo to migration

* refactor: Refactor create events in check deduct fee

* chore: Add todo for resolve imbalance to withdraw fee

* feat: Add more conditions to simulate

* fix: Remove unused code and dependency

* refactor: Refactor to string

* feat: Add remove denom asset pair from router

* chore: Add todo to simulate

* feat: Add cosmwasm message handlers (#31)

* feat: Add any match macro

* refactor: Refactor message router with any_match macro

* style: Reformat any_match macros

* refactor: Refactor msg filter with any_match macro

* feat: Add cosmwasm msgs to MsgFilter

* feat: Add MsgStoreCode

* feat: Add MsgInstantiateContract2 handler

* feat: Add MsgExecuteContract handler

* feat: Add MsgMigrateContract and MsgUpdateAdmin handlers

* feat: Add pallet-cosmwasm (#32)

* feat: Add cosmwasm libraries

* refactor: Refactor from IbcPacketReceiveResult to ContractResult function

* fix: Fix cosmwasm-vm errors

* feat: Add pallet-cosmwasm

* chore: Move cosmwasm vm and vm-wasmi to cosmwasm

* chore: Fix typos

* feat: Add pallet-cosmwasm

* feat: Add composable-support

* fix: Remove outdated ibc implements

* refactor: Remove unused dependencies

* fix: Add iterator and stargate features to cosmwasm vm and vm-wasmi

* refactor: Reformat pallet-cosmwasm Cargo.toml

* fix: Add no_std to several packages

* build: Add no_std to cosmwasm-std

* build: Remove unused features of cosmwasm vm and vm-wasmi

* build: Add default-features=false to several dependencies

* build: Fix num no_std issue

* refactor: Replace deprecated GenesisBuild with BuildGenesisConfig

* style: Reformat

---------

Co-authored-by: Jeeyong Um <[email protected]>
Co-authored-by: Jungyong Um <[email protected]>
  • Loading branch information
3 people authored Aug 27, 2024
1 parent 34656a5 commit d444191
Show file tree
Hide file tree
Showing 228 changed files with 53,998 additions and 1,919 deletions.
74 changes: 58 additions & 16 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,61 @@
resolver = "2"
members = [
"client/rpc",
"frame/accounts",
"frame/cosmos",
"frame/cosmos/modules",
"frame/cosmos/modules/auth",
"frame/cosmos/modules/bank",
"frame/cosmos-accounts",
"frame/cosmwasm",
"frame/cosmos/types",
"frame/cosmos/x/auth",
"frame/cosmos/x/auth/migrations",
"frame/cosmos/x/auth/signing",
"frame/cosmos/x/bank",
"frame/cosmos/x/bank/types",
"frame/cosmos/x/wasm",
"frame/cosmos/x/wasm/types",
"primitives/account",
"primitives/cosmos",
"primitives/io",
"primitives/rpc",
"template/runtime",
"template/node",
"cosmwasm/std",
"composable/primitives",
"composable/vm",
"composable/vm-wasmi",
"composable/composable-support",
"composable/composable-traits",
]

[workspace.dependencies]
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.15.0"
clap = { version = "4.5.16", features = ["derive"] }
cosmos-sdk-proto = { version = "0.24.0", default-features = false }
futures = "0.3.28"
hex = "0.4.3"
hex = { version = "0.4.3", default-features = false }
hex-literal = "0.4.1"
impl-trait-for-tuples = "0.2.2"
jsonrpsee = "0.22.5"
log = { version = "0.4.21", default-features = false }
num_enum = { version = "0.7.2", default-features = false }
num = { version = "0.4.3", default-features = false }
parity-scale-codec = { version = "3.2.0", default-features = false }
rand_core = { version = "0.6.4", default-features = false }
ripemd = { version = "0.1.3", default-features = false }
scale-info = { version = "2.3.0", default-features = false }
schemars = { version = "1.0.0-alpha.5", default-features = false }
secp256k1 = { version = "0.28.1", default-features = false }
serde = { version = "1.0.0", default-features = false }
serde_json = { version = "1.0.94", default-features = false }
serde = { version = "1.0.209", default-features = false }
serde_json = { version = "1.0.127", default-features = false, features = [
"alloc",
] }

# Substrate FRAME
frame-executive = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-system = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
frame-system-rpc-runtime-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-aura = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-assets = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-grandpa = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
Expand All @@ -64,6 +82,7 @@ sc-service = { git = "https://github.com/paritytech/polkadot-sdk", branch = "rel
sc-telemetry = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
sc-transaction-pool = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0" }
sp-arithmetic = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-block-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
Expand Down Expand Up @@ -92,17 +111,40 @@ fp-self-contained = { git = "https://github.com/polkadot-evm/frontier", branch =
# Horizon
hc-rpc = { path = "client/rpc" }
hp-account = { path = "primitives/account", default-features = false }
hp-cosmos = { path = "primitives/cosmos", 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/cosmos-accounts", default-features = false }
pallet-cosmos-accounts = { path = "frame/accounts", default-features = false }
horizon-template-runtime = { path = "template/runtime", default-features = false }

pallet-cosmos-auth = { path = "frame/cosmos/modules/auth", default-features = false}
pallet-cosmos-bank = { path = "frame/cosmos/modules/bank", default-features = false}
pallet-cosmos-modules = { path = "frame/cosmos/modules", 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 }
pallet-cosmos-x-auth-signing = { path = "frame/cosmos/x/auth/signing", default-features = false }
pallet-cosmos-x-bank = { path = "frame/cosmos/x/bank", default-features = false }
pallet-cosmos-x-bank-types = { path = "frame/cosmos/x/bank/types", default-features = false }
pallet-cosmos-x-wasm = { path = "frame/cosmos/x/wasm", default-features = false }
pallet-cosmos-x-wasm-types = { path = "frame/cosmos/x/wasm/types", default-features = false }

cosmwasm-core = { version = "2.1.3", default-features = false }
cosmwasm-schema = { version = "2.1.3", default-features = false }
cosmwasm-crypto = { version = "2.1.3", default-features = false }

cosmwasm-std = { path = "cosmwasm/std", default-features = false }
ibc = { version = "0.54.0", default-features = false }

wasm-instrument = { version = "0.4.0", default-features = false }
wasmi = { version = "0.30.0", default-features = false }
wasmi-validation = { version = "0.5.0", default-features = false }

# Composable
pallet-cosmwasm = { path = "frame/cosmwasm", default-features = false }
ibc-primitives = { path = "composable/primitives", default-features = false }
cosmwasm-vm = { path = "composable/vm", default-features = false }
cosmwasm-vm-wasmi = { path = "composable/vm-wasmi", default-features = false }
composable-support = { path = "composable/composable-support", default-features = false }
composable-traits = { path = "composable/composable-traits", default-features = false }

[profile.release]
panic = "unwind"
Expand Down
2 changes: 1 addition & 1 deletion client/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ targets = ["x86_64-unknown-linux-gnu"]
[dependencies]
futures = { workspace = true }
jsonrpsee = { workspace = true, features = ["server", "macros"] }
hex = { workspace = true }
hex = { workspace = true, features = ["std"] }

# Substrate
sc-transaction-pool-api = { workspace = true }
Expand Down
43 changes: 29 additions & 14 deletions client/rpc/src/cosm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.

use crate::internal_err;
use crate::internal_error;
use futures::future::TryFutureExt;
use hp_rpc::{CosmosTxRuntimeApi, SimulateError, SimulateResponse};
use jsonrpsee::{
core::{async_trait, RpcResult},
proc_macros::rpc,
Expand All @@ -34,6 +35,9 @@ use std::{marker::PhantomData, sync::Arc};
pub trait CosmApi {
#[method(name = "cosm_broadcastTx")]
async fn broadcast_tx(&self, tx_bytes: Bytes) -> RpcResult<H256>;

#[method(name = "cosm_simulate")]
async fn simulate(&self, tx_bytes: Bytes) -> RpcResult<SimulateResponse>;
}

pub struct Cosm<B: BlockT, C, P> {
Expand All @@ -49,29 +53,40 @@ impl<B: BlockT, C, P> Cosm<B, C, P> {
}

#[async_trait]
impl<B, C, P> CosmApiServer for Cosm<B, C, P>
impl<Block, C, P> CosmApiServer for Cosm<Block, C, P>
where
B: BlockT,
Block: BlockT,
C: Send + Sync + 'static,
C: ProvideRuntimeApi<B>,
C: HeaderBackend<B> + 'static,
C::Api: hp_rpc::ConvertTxRuntimeApi<B>,
P: TransactionPool<Block = B> + 'static,
C: ProvideRuntimeApi<Block>,
C: HeaderBackend<Block> + 'static,
C::Api: hp_rpc::CosmosTxRuntimeApi<Block>,
P: TransactionPool<Block = Block> + 'static,
{
async fn broadcast_tx(&self, tx_bytes: Bytes) -> RpcResult<H256> {
use hp_rpc::ConvertTxRuntimeApi;

let block_hash = self.client.info().best_hash;
let best_hash = self.client.info().best_hash;
let extrinsic = self
.client
.runtime_api()
.convert_tx(block_hash, tx_bytes.to_vec())
.map_err(|_| internal_err("cannot access runtime api"))?;
.convert_tx(best_hash, tx_bytes.to_vec())
.map_err(internal_error)?;

let tx_hash = H256(sha2_256(&tx_bytes));
self.pool
.submit_one(block_hash, TransactionSource::Local, extrinsic)
.submit_one(best_hash, TransactionSource::Local, extrinsic)
.map_ok(move |_| tx_hash)
.map_err(|e| internal_err(e.to_string()))
.map_err(internal_error)
.await
}

async fn simulate(&self, tx_bytes: Bytes) -> RpcResult<SimulateResponse> {
let best_hash = self.client.info().best_hash;
self.client
.runtime_api()
.simulate(best_hash, tx_bytes.to_vec())
.map_err(internal_error)?
.map_err(|e| match e {
SimulateError::InvalidTx => internal_error("invalid tx"),
SimulateError::UnknownError => internal_error("unknown error"),
})
}
}
24 changes: 10 additions & 14 deletions client/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,22 @@
mod cosm;

pub use cosm::{Cosm, CosmApiServer};
pub use jsonrpsee::{
core,
types::{error, ErrorObject, ErrorObjectOwned},
};

pub fn err<T: ToString>(
code: i32,
message: T,
data: Option<&[u8]>,
) -> jsonrpsee::types::ErrorObjectOwned {
jsonrpsee::types::error::ErrorObject::owned(
pub fn error<T: ToString>(code: i32, message: T, data: Option<&[u8]>) -> ErrorObjectOwned {
ErrorObject::owned(
code,
message.to_string(),
data.map(|bytes| {
jsonrpsee::core::to_json_raw_value(&format!("0x{}", hex::encode(bytes)))
.expect("fail to serialize data")
core::to_json_raw_value(&format!("0x{}", hex::encode(bytes)))
.expect("Failed to serialize data")
}),
)
}

pub fn request_err<T: ToString>(message: T) -> jsonrpsee::types::ErrorObjectOwned {
err(jsonrpsee::types::error::INVALID_REQUEST_CODE, message, None)
}

pub fn internal_err<T: ToString>(message: T) -> jsonrpsee::types::ErrorObjectOwned {
err(jsonrpsee::types::error::INTERNAL_ERROR_CODE, message, None)
pub fn internal_error<T: ToString>(message: T) -> ErrorObjectOwned {
error(error::INTERNAL_ERROR_CODE, message, None)
}
38 changes: 38 additions & 0 deletions composable/composable-support/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
[package]
authors = ["Composable Developers"]
edition = "2021"
homepage = "https://composable.finance"
name = "composable-support"
rust-version = "1.56"
version = "1.0.0"

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
codec = { version = "3.2.0", package = "parity-scale-codec", default-features = false, features = [
"derive",
] }
scale-info = { version = "2.3.0", default-features = false, features = [
"derive",
] }
num-traits = { version = "0.2.14", default-features = false }
schemars = { optional = true, default-features = false, workspace = true }

frame-support = { default-features = false, workspace = true }
sp-arithmetic = { default-features = false, workspace = true }
sp-runtime = { default-features = false, workspace = true }
sp-std = { default-features = false, workspace = true }

[features]
default = ["std"]
std = [
"codec/std",
"scale-info/std",
"num-traits/std",
"frame-support/std",
"sp-arithmetic/std",
"sp-runtime/std",
"sp-std/std",
"schemars/std",
]
Loading

0 comments on commit d444191

Please sign in to comment.