From 4e8f8e3642f3c9147aebc2495cdbd13aca03ec76 Mon Sep 17 00:00:00 2001 From: Daniel Olano Date: Fri, 15 Dec 2023 18:23:18 +0100 Subject: [PATCH] Rename shared to virto-common --- Cargo.lock | 124 ++++++++++++++------------- Cargo.toml | 7 +- common/.gitignore | 1 + {shared => common}/Cargo.toml | 5 +- common/README.md | 4 + common/justfile | 7 ++ common/src/lib.rs | 8 ++ {shared => common}/src/payment_id.rs | 20 +++-- {shared => common}/test.html | 12 +-- justfile | 5 +- pallets/asset-registry/Cargo.toml | 7 +- pallets/asset-registry/src/lib.rs | 2 +- runtime/common/Cargo.toml | 2 +- runtime/kreivo/Cargo.toml | 4 +- runtime/kreivo/src/lib.rs | 6 +- runtime/kreivo/src/xcm_config.rs | 2 +- runtime/virto/Cargo.toml | 4 +- runtime/virto/src/lib.rs | 6 +- runtime/virto/src/xcm_config.rs | 2 +- shared/justfile | 5 -- shared/src/lib.rs | 7 -- 21 files changed, 126 insertions(+), 114 deletions(-) create mode 100644 common/.gitignore rename {shared => common}/Cargo.toml (78%) create mode 100644 common/README.md create mode 100644 common/justfile create mode 100644 common/src/lib.rs rename {shared => common}/src/payment_id.rs (88%) rename {shared => common}/test.html (90%) delete mode 100644 shared/justfile delete mode 100644 shared/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index 257aa080..c66a11cf 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4590,6 +4590,7 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", + "runtime-common", "scale-info", "smallvec", "sp-api", @@ -4609,7 +4610,6 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "virto-common", ] [[package]] @@ -6108,6 +6108,7 @@ dependencies = [ "pallet-balances", "pallet-xcm", "parity-scale-codec", + "runtime-common", "scale-info", "sp-core", "sp-io", @@ -6115,7 +6116,6 @@ dependencies = [ "sp-runtime", "sp-std", "staging-xcm", - "virto-common", ] [[package]] @@ -9667,6 +9667,67 @@ dependencies = [ "webrtc-util", ] +[[package]] +name = "runtime-common" +version = "0.1.0" +dependencies = [ + "cumulus-pallet-aura-ext", + "cumulus-pallet-dmp-queue", + "cumulus-pallet-parachain-system", + "cumulus-pallet-session-benchmarking", + "cumulus-pallet-xcm", + "cumulus-pallet-xcmp-queue", + "cumulus-primitives-core", + "cumulus-primitives-timestamp", + "cumulus-primitives-utility", + "frame-benchmarking", + "frame-executive", + "frame-support", + "frame-system", + "frame-system-benchmarking", + "frame-system-rpc-runtime-api", + "frame-try-runtime", + "hex-literal 0.3.4", + "kusama-runtime-constants", + "log", + "pallet-asset-tx-payment", + "pallet-assets", + "pallet-aura", + "pallet-authorship", + "pallet-balances", + "pallet-collator-selection", + "pallet-lockdown-mode", + "pallet-session", + "pallet-sudo", + "pallet-timestamp", + "pallet-transaction-payment", + "pallet-transaction-payment-rpc-runtime-api", + "pallet-treasury", + "pallet-xcm", + "parachains-common", + "parity-scale-codec", + "polkadot-core-primitives", + "polkadot-runtime-common", + "scale-info", + "smallvec", + "sp-api", + "sp-block-builder", + "sp-consensus-aura", + "sp-core", + "sp-inherents", + "sp-offchain", + "sp-runtime", + "sp-session", + "sp-std", + "sp-transaction-pool", + "sp-version", + "staging-parachain-info", + "staging-xcm", + "staging-xcm-builder", + "staging-xcm-executor", + "substrate-wasm-builder", +] + [[package]] name = "rustc-demangle" version = "0.1.23" @@ -13631,61 +13692,8 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" name = "virto-common" version = "0.1.0" dependencies = [ - "cumulus-pallet-aura-ext", - "cumulus-pallet-dmp-queue", - "cumulus-pallet-parachain-system", - "cumulus-pallet-session-benchmarking", - "cumulus-pallet-xcm", - "cumulus-pallet-xcmp-queue", - "cumulus-primitives-core", - "cumulus-primitives-timestamp", - "cumulus-primitives-utility", - "frame-benchmarking", - "frame-executive", - "frame-support", - "frame-system", - "frame-system-benchmarking", - "frame-system-rpc-runtime-api", - "frame-try-runtime", - "hex-literal 0.3.4", - "kusama-runtime-constants", - "log", - "pallet-asset-tx-payment", - "pallet-assets", - "pallet-aura", - "pallet-authorship", - "pallet-balances", - "pallet-collator-selection", - "pallet-lockdown-mode", - "pallet-session", - "pallet-sudo", - "pallet-timestamp", - "pallet-transaction-payment", - "pallet-transaction-payment-rpc-runtime-api", - "pallet-treasury", - "pallet-xcm", - "parachains-common", - "parity-scale-codec", - "polkadot-core-primitives", - "polkadot-runtime-common", - "scale-info", - "smallvec", - "sp-api", - "sp-block-builder", - "sp-consensus-aura", - "sp-core", - "sp-inherents", - "sp-offchain", - "sp-runtime", - "sp-session", - "sp-std", - "sp-transaction-pool", - "sp-version", - "staging-parachain-info", - "staging-xcm", - "staging-xcm-builder", - "staging-xcm-executor", - "substrate-wasm-builder", + "bs58 0.5.0", + "wasm-bindgen", ] [[package]] @@ -13815,6 +13823,7 @@ dependencies = [ "polkadot-core-primitives", "polkadot-parachain-primitives", "polkadot-runtime-common", + "runtime-common", "scale-info", "smallvec", "sp-api", @@ -13834,7 +13843,6 @@ dependencies = [ "staging-xcm-builder", "staging-xcm-executor", "substrate-wasm-builder", - "virto-common", ] [[package]] diff --git a/Cargo.toml b/Cargo.toml index b71e9269..f81b65c2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,8 +2,8 @@ members = [ "node", "runtime/kreivo", - "runtime/virto" - "shared", + "runtime/virto", + "common", ] exclude = ["xcm-emulator"] @@ -58,8 +58,7 @@ pallet-lockdown-mode = { default-features = false, path = "pallets/lockdown-mode pallet-payments = { default-features = false, path = "pallets/payments" } pallet-communities = { default-features = false, path = "pallets/communities" } -# Virto common -virto-common = { default-features = false, path = "runtime/common" } +runtime-common = { default-features = false, path = "runtime/common" } # Substrate std try-runtime-cli = { git = "https://github.com/virto-network/polkadot-sdk", branch = "virto-crates-io-v1.2.0" } diff --git a/common/.gitignore b/common/.gitignore new file mode 100644 index 00000000..89f9ac04 --- /dev/null +++ b/common/.gitignore @@ -0,0 +1 @@ +out/ diff --git a/shared/Cargo.toml b/common/Cargo.toml similarity index 78% rename from shared/Cargo.toml rename to common/Cargo.toml index 03c6f802..1222ad25 100644 --- a/shared/Cargo.toml +++ b/common/Cargo.toml @@ -1,8 +1,11 @@ [package] -name = "virto-shared" +name = "virto-common" version = "0.1.0" edition = "2021" +[lib] +crate-type = ["cdylib", "rlib"] + [dependencies] bs58 = { version = "0.5.0", default-features = false } wasm-bindgen = { version = "0.2.87", optional = true } diff --git a/common/README.md b/common/README.md new file mode 100644 index 00000000..251bd540 --- /dev/null +++ b/common/README.md @@ -0,0 +1,4 @@ +# Virto Common + +This repo holds common primitive types that are shared between the parachain +runtime and client side applications including the web and `no_std` embedded targets. diff --git a/common/justfile b/common/justfile new file mode 100644 index 00000000..9425cc1d --- /dev/null +++ b/common/justfile @@ -0,0 +1,7 @@ +build-web: + @mkdir -p out + RUSTFLAGS="--cfg nightly" cargo +nightly build --release --target wasm32-unknown-unknown --features js --out-dir out -Z unstable-options + wasm-bindgen --out-dir out --target web --no-typescript --remove-name-section out/virto_common.wasm + +test: + RUSTFLAGS="--cfg nightly" cargo +nightly test --lib test diff --git a/common/src/lib.rs b/common/src/lib.rs new file mode 100644 index 00000000..3f5a24a0 --- /dev/null +++ b/common/src/lib.rs @@ -0,0 +1,8 @@ +#![cfg_attr(not(any(test, feature = "std")), no_std)] +#![cfg_attr(nightly, feature(ascii_char))] + +#[cfg(feature = "alloc")] +extern crate alloc; + +mod payment_id; +pub use payment_id::PaymentId; diff --git a/shared/src/payment_id.rs b/common/src/payment_id.rs similarity index 88% rename from shared/src/payment_id.rs rename to common/src/payment_id.rs index 4dc83543..78c25ff9 100644 --- a/shared/src/payment_id.rs +++ b/common/src/payment_id.rs @@ -1,7 +1,7 @@ -use core::{fmt, str::FromStr}; #[cfg(feature = "js")] use wasm_bindgen::prelude::*; +/// A compact identifier for payment #[cfg_attr(feature = "js", wasm_bindgen)] #[derive(Debug, Default, Clone, Copy, PartialEq)] #[repr(C)] @@ -14,6 +14,7 @@ pub struct PaymentId { #[cfg_attr(feature = "js", wasm_bindgen)] impl PaymentId { #[cfg_attr(feature = "js", wasm_bindgen(constructor))] + #[cfg(nightly)] pub fn new(id: &str) -> PaymentId { id.parse().unwrap_or(Default::default()) } @@ -33,7 +34,7 @@ impl PaymentId { self.index as u32 } - #[cfg(feature = "alloc")] + #[cfg(all(nightly, feature = "alloc"))] pub fn encode(&self, pretty: bool) -> alloc::string::String { if pretty { alloc::format!("{self:#}") @@ -90,7 +91,8 @@ impl AsRef<[u8]> for PaymentId { } } -impl FromStr for PaymentId { +#[cfg(nightly)] +impl core::str::FromStr for PaymentId { type Err = (); fn from_str(s: &str) -> Result { @@ -109,11 +111,13 @@ impl FromStr for PaymentId { } } -impl fmt::Display for PaymentId { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { +#[cfg(nightly)] +impl core::fmt::Display for PaymentId { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + use core::fmt::Error; let mut out = [0u8; 12]; - let n = bs58::encode(self).onto(&mut out[..]).map_err(|_| fmt::Error)?; - let out = out[..n].as_ascii().ok_or(fmt::Error)?.as_str(); + let n = bs58::encode(self).onto(&mut out[..]).map_err(|_| Error)?; + let out = out[..n].as_ascii().ok_or(Error)?.as_str(); write!(f, "{}", &out[..5])?; if f.alternate() { write!(f, "-")?; @@ -122,7 +126,7 @@ impl fmt::Display for PaymentId { } } -#[cfg(test)] +#[cfg(all(test, nightly))] mod tests { extern crate alloc; use super::*; diff --git a/shared/test.html b/common/test.html similarity index 90% rename from shared/test.html rename to common/test.html index 8265923b..d9db682e 100644 --- a/shared/test.html +++ b/common/test.html @@ -37,20 +37,16 @@ } output { - flex: 1; background: whitesmoke; - padding: 0 0.5rem; - line-height: 2.5rem; color: gray; font-family: monospace; + line-height: 2.5rem; + min-width: fit-content; overflow: hidden; + padding: 0 0.5rem; text-overflow: ellipsis; white-space: nowrap; } - - output[name=id]:before { - content: '🆔 '; - } @@ -63,7 +59,7 @@