Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch Cosmos package dependencies from crate to workspace #120

Merged
merged 17 commits into from
Jan 11, 2025
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
1c34c67
chore: Change cosmos-rpc dependency from crate to workspace
code0xff Jan 9, 2025
a063ee3
chore: Change cosmos-runtime-api dependency from crate to workspace
code0xff Jan 9, 2025
fc9b2f7
chore: Update package info to use workspace values
code0xff Jan 9, 2025
f538666
chore: Switch pallet-cosmos-types dependencies from crate to workspace
code0xff Jan 9, 2025
42ee599
chore: Update Cosmos package licenses to Apache-2.0
code0xff Jan 9, 2025
072ded4
feat: Integrate nostd crate for no_std environment support
code0xff Jan 9, 2025
58a0bcb
chore: Switch pallet-cosmos-x-auth-migrations dependencies from crate…
code0xff Jan 9, 2025
cdb1e7b
chore: Switch pallet-cosmos-x-auth-signing dependencies from crate to…
code0xff Jan 9, 2025
ef7fdde
chore: Switch pallet-cosmos-x-auth dependencies from crate to workspace
code0xff Jan 9, 2025
e1418f7
chore: Switch pallet-cosmos-x-bank-types dependencies from crate to w…
code0xff Jan 9, 2025
4665cec
chore: Switch pallet-cosmos-x-bank dependencies from crate to workspace
code0xff Jan 9, 2025
727917b
chore: Switch pallet-cosmos-x-wasm-types dependencies from crate to w…
code0xff Jan 9, 2025
259d207
chore: Switch pallet-cosmos-x-wasm dependencies from crate to workspace
code0xff Jan 9, 2025
5d31990
chore: Downgrade cosmwasm-std feature version to align with Composable
code0xff Jan 9, 2025
2f631c6
refactor: Introduce nostd crate to np-crypto to enhance no_std develo…
code0xff Jan 10, 2025
c991fee
refactor: Switch hex encoding to const-hex
code0xff Jan 11, 2025
596a12d
refactor: Replace core2::io to nostd::io
code0xff Jan 11, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,22 @@ bytemuck = "1.16.1"
bytemuck_derive = "1.7.0"
byteorder = { version = "1.5.0", default-features = false }
const-hex = { version = "1.13", default-features = false }
core2 = { version = "0.4.0", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use nostd::io instead of core2.

cosmos-sdk-proto = { version = "0.24", default-features = false }
curve25519-dalek = { version = "4.1.3", features = ["digest", "rand_core"] }
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 = { version = "0.4", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use const-hex instead of hex.

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 +131,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"
hex = { workspace = true, features = ["std"] }

[features]
default = ["std"]
Expand Down
2 changes: 1 addition & 1 deletion 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 Down
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
Loading