Skip to content

Commit

Permalink
chore: Switch Cosmos package dependencies from crate to workspace (#120)
Browse files Browse the repository at this point in the history
* chore: Change cosmos-rpc dependency from crate to workspace

* chore: Change cosmos-runtime-api dependency from crate to workspace

* chore: Update package info to use workspace values

* chore: Switch pallet-cosmos-types dependencies from crate to workspace

* chore: Update Cosmos package licenses to Apache-2.0

* feat: Integrate nostd crate for no_std environment support

* chore: Switch pallet-cosmos-x-auth-migrations dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-auth-signing dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-auth dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-bank-types dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-bank dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-wasm-types dependencies from crate to workspace

* chore: Switch pallet-cosmos-x-wasm dependencies from crate to workspace

* chore: Downgrade cosmwasm-std feature version to align with Composable

* refactor: Introduce nostd crate to np-crypto to enhance no_std development experience

* refactor: Switch hex encoding to const-hex

* refactor: Replace core2::io to nostd::io
  • Loading branch information
code0xff authored Jan 11, 2025
1 parent 11a05ae commit c56c47b
Show file tree
Hide file tree
Showing 52 changed files with 214 additions and 223 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,14 @@ derive-where = "1.2"
eager = "0.1.0"
enum-iterator = "1.5.0"
ethereum = { version = "0.15.0", default-features = false }
futures = "0.3"
getrandom = { version = "0.2", default-features = false }
hex-literal = "0.4"
impl-trait-for-tuples = { version = "0.2.2" }
itertools = { version = "0.12.1", default-features = false }
jsonrpsee = { version = "0.24" }
k256 = { version = "0.13", default-features = false }
libflate = { version = "2.1.0", default-features = false }
libsecp256k1 = { version = "0.6.0", default-features = false }
light-poseidon = "0.2.0"
log = { version = "0.4", default-features = false }
Expand Down Expand Up @@ -125,7 +129,9 @@ pallet-balances = { git = "https://github.com/paritytech/polkadot-sdk", branch =
pallet-sudo = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
pallet-timestamp = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
pallet-transaction-payment = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
sp-io = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
sp-keyring = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
Expand Down
10 changes: 6 additions & 4 deletions frame/cosmos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@ workspace = true
cosmos-sdk-proto = { workspace = true }
frame-support = { workspace = true }
frame-system = { workspace = true }
pallet-cosmos-x-auth-signing = { workspace = true, default-features = false }
pallet-cosmos-types = { workspace = true, default-features = false }
pallet-multimap = { workspace = true, default-features = false }
nostd = { workspace = true }
pallet-cosmos-x-auth-signing = { workspace = true }
pallet-cosmos-types = { workspace = true }
pallet-multimap = { workspace = true }
parity-scale-codec = { workspace = true }
np-cosmos = { workspace = true, default-features = false }
np-cosmos = { workspace = true }
scale-info = { workspace = true }
sp-core = { workspace = true }
sp-runtime = { workspace = true }
Expand All @@ -30,6 +31,7 @@ std = [
"cosmos-sdk-proto/std",
"frame-support/std",
"frame-system/std",
"nostd/std",
"pallet-cosmos-x-auth-signing/std",
"pallet-cosmos-types/std",
"pallet-multimap/std",
Expand Down
23 changes: 11 additions & 12 deletions frame/cosmos/rpc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
[package]
name = "cosmos-rpc"
version = "0.4.0"
authors = ["Haderech Pte. Ltd."]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/noirhq/noir.git"
authors = { workspace = true }
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
publish = false

[dependencies]
cosmos-runtime-api = { workspace = true, features = ["std"] }
futures = "0.3"
hex = "0.4.3"
jsonrpsee = { version = "0.24", features = ["client", "server", "macros"] }
futures = { workspace = true }
jsonrpsee = { workspace = true, features = ["client", "server", "macros"] }
pallet-cosmos-types = { workspace = true, features = ["std"] }
sc-transaction-pool-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-blockchain = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-core = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409" }
sc-transaction-pool-api = { workspace = true }
sp-api = { workspace = true, features = ["std"] }
sp-blockchain = { workspace = true }
sp-core = { workspace = true, features = ["std"] }
sp-runtime = { workspace = true, features = ["std"] }
8 changes: 6 additions & 2 deletions frame/cosmos/rpc/src/cosmos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,12 @@ where
.simulate(at, tx_bytes.to_vec())
.map_err(internal_error)?
.map_err(|e| match e {
SimulateError::InvalidTx => request_error("Invalid tx"),
SimulateError::InternalError(e) => internal_error(String::from_utf8_lossy(&e)),
SimulateError::InvalidTransaction =>
request_error("Simulate transaction failed: Invalid transaction"),
SimulateError::InternalError(e) => internal_error(format!(
"Simulate transaction failed: {})",
String::from_utf8_lossy(&e)
)),
})
}

Expand Down
24 changes: 7 additions & 17 deletions frame/cosmos/rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,19 @@

pub mod cosmos;

use jsonrpsee::{
core::to_json_raw_value,
types::{
error::{INTERNAL_ERROR_CODE, INVALID_REQUEST_CODE},
ErrorObject, ErrorObjectOwned,
},
use jsonrpsee::types::{
error::{INTERNAL_ERROR_CODE, INVALID_REQUEST_CODE},
ErrorObject, ErrorObjectOwned,
};

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

pub fn request_error<T: ToString>(message: T) -> ErrorObjectOwned {
error(INVALID_REQUEST_CODE, message, None)
error(INVALID_REQUEST_CODE, message)
}

pub fn internal_error<T: ToString>(message: T) -> ErrorObjectOwned {
error(INTERNAL_ERROR_CODE, message, None)
error(INTERNAL_ERROR_CODE, message)
}
22 changes: 12 additions & 10 deletions frame/cosmos/runtime-api/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
[package]
name = "cosmos-runtime-api"
version = "0.4.0"
authors = ["Haderech Pte. Ltd."]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/noirhq/noir.git"
authors = { workspace = true }
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
publish = false

[dependencies]
pallet-cosmos-types = { workspace = true, default-features = false }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
sp-api = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
nostd = { workspace = true }
pallet-cosmos-types = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
sp-api = { workspace = true }
sp-runtime = { workspace = true }

[features]
default = ["std"]
std = [
"nostd/std",
"pallet-cosmos-types/std",
"parity-scale-codec/std",
"scale-info/std",
Expand Down
6 changes: 2 additions & 4 deletions frame/cosmos/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

use alloc::{string::String, vec::Vec};
use nostd::{string::String, vec::Vec};
use pallet_cosmos_types::tx::SimulateResponse;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
Expand All @@ -29,7 +27,7 @@ use sp_runtime::traits::Block as BlockT;

#[derive(Clone, Decode, Encode, Debug, Eq, PartialEq, TypeInfo)]
pub enum SimulateError {
InvalidTx,
InvalidTransaction,
InternalError(Vec<u8>),
}

Expand Down
4 changes: 1 addition & 3 deletions frame/cosmos/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![allow(unreachable_patterns)]

extern crate alloc;

pub mod types;
pub mod weights;

Expand Down Expand Up @@ -138,7 +136,6 @@ pub trait AddressMapping<A> {
#[frame_support::pallet]
pub mod pallet {
use super::*;
use alloc::{string::String, vec::Vec};
use cosmos_sdk_proto::Any;
use frame_support::{
dispatch::WithPostDispatchInfo,
Expand All @@ -148,6 +145,7 @@ pub mod pallet {
Contains, Currency,
},
};
use nostd::{string::String, vec::Vec};
use np_cosmos::traits::ChainInfo;
use pallet_cosmos_types::{
context::traits::MinGasPrices, errors::CosmosError, events::CosmosEvent, gas::Gas,
Expand Down
6 changes: 3 additions & 3 deletions frame/cosmos/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use core::marker::PhantomData;
use frame_support::{dispatch::DispatchClass, weights::Weight};
use frame_system::limits::BlockWeights;
use nostd::marker::PhantomData;
use sp_core::Get;

pub trait WeightInfo {
Expand All @@ -30,8 +30,8 @@ impl WeightInfo for () {
}
}

pub struct CosmosWeight<T>(PhantomData<T>);
impl<T> WeightInfo for CosmosWeight<T>
pub struct SubstrateWeight<T>(PhantomData<T>);
impl<T> WeightInfo for SubstrateWeight<T>
where
T: frame_system::Config,
{
Expand Down
27 changes: 14 additions & 13 deletions frame/cosmos/types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
[package]
name = "pallet-cosmos-types"
version = "0.4.0"
authors = ["Haderech Pte. Ltd."]
edition = "2021"
license = "Apache-2.0"
repository = "https://github.com/noirhq/noir.git"
authors = { workspace = true }
version = { workspace = true }
edition = { workspace = true }
repository = { workspace = true }
publish = false

[dependencies]
bech32 = { version = "0.11", default-features = false, features = ["alloc"] }
cosmos-sdk-proto = { version = "0.24", default-features = false, features = ["cosmwasm"] }
frame-support = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
impl-trait-for-tuples = { version = "0.2.2" }
parity-scale-codec = { version = "3.6", default-features = false, features = ["derive"] }
scale-info = { version = "2.11", default-features = false, features = ["derive"] }
serde = { version = "1.0.210", default-features = false, features = ["derive"] }
sp-runtime = { git = "https://github.com/paritytech/polkadot-sdk", branch = "stable2409", default-features = false }
bech32 = { workspace = true, features = ["alloc"] }
cosmos-sdk-proto = { workspace = true, features = ["cosmwasm"] }
frame-support = { workspace = true }
impl-trait-for-tuples = { workspace = true }
nostd = { workspace = true }
parity-scale-codec = { workspace = true, features = ["derive"] }
scale-info = { workspace = true, features = ["derive"] }
serde = { workspace = true, features = ["derive"] }
sp-runtime = { workspace = true }

[dev-dependencies]
hex = "0.4"
const-hex = { workspace = true, features = ["std"] }

[features]
default = ["std"]
Expand Down
4 changes: 2 additions & 2 deletions frame/cosmos/types/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloc::{
use nostd::{
string::{String, ToString},
vec::Vec,
};
Expand All @@ -41,7 +41,7 @@ mod tests {
let (hrp, address_raw) = acc_address_from_bech32(address).unwrap();
assert_eq!(hrp, "cosmos");

let address_raw = hex::encode(address_raw);
let address_raw = const_hex::encode(address_raw);
assert_eq!(address_raw, "037459f1d22d10bed7b6920865c8bc96c5571f2d");
}
}
2 changes: 1 addition & 1 deletion frame/cosmos/types/src/coin/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

pub mod traits;

use alloc::{
use nostd::{
string::{String, ToString},
vec::Vec,
};
Expand Down
2 changes: 1 addition & 1 deletion frame/cosmos/types/src/coin/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

use alloc::string::String;
use nostd::string::String;

pub trait Coins {
type Error;
Expand Down
2 changes: 1 addition & 1 deletion frame/cosmos/types/src/context/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
events::traits::EventManager,
gas::{traits::GasMeter, Gas},
};
use alloc::vec::Vec;
use nostd::vec::Vec;

pub trait Context {
type GasMeter: GasMeter;
Expand Down
2 changes: 1 addition & 1 deletion frame/cosmos/types/src/events/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

pub mod traits;

use alloc::vec::Vec;
use nostd::vec::Vec;
use parity_scale_codec::{Decode, Encode};
use scale_info::TypeInfo;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 0 additions & 2 deletions frame/cosmos/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@

#![cfg_attr(not(feature = "std"), no_std)]

extern crate alloc;

pub mod address;
pub mod coin;
pub mod context;
Expand Down
2 changes: 1 addition & 1 deletion frame/cosmos/types/src/msgservice/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// limitations under the License.

use crate::errors::CosmosError;
use alloc::boxed::Box;
use cosmos_sdk_proto::Any;
use nostd::boxed::Box;

pub trait MsgHandler<Context> {
fn handle(&self, ctx: &mut Context, msg: &Any) -> Result<(), CosmosError>;
Expand Down
5 changes: 4 additions & 1 deletion frame/cosmos/types/src/tx_msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
// limitations under the License.

use crate::gas::Gas;
use alloc::{string::String, vec::Vec};
use cosmos_sdk_proto::cosmos::tx::v1beta1::{Fee, Tx};
use nostd::{string::String, vec::Vec};

pub trait Msg {
// get_signers returns the addresses of signers that must sign.
Expand All @@ -35,12 +35,15 @@ impl FeeTx for Tx {
fn fee(&self) -> Option<Fee> {
self.auth_info.as_ref().and_then(|auth_info| auth_info.fee.clone())
}

fn gas(&self) -> Option<Gas> {
self.fee().map(|fee| fee.gas_limit)
}

fn fee_payer(&self) -> Option<String> {
self.fee().map(|fee| fee.payer.clone())
}

fn fee_granter(&self) -> Option<String> {
self.fee().map(|fee| fee.granter.clone())
}
Expand Down
Loading

0 comments on commit c56c47b

Please sign in to comment.