From 5cb5c3bfad54210e98a633bf159bba65be12ea92 Mon Sep 17 00:00:00 2001 From: Marko Petrlic Date: Thu, 29 Aug 2024 17:57:40 +0200 Subject: [PATCH] made avail-core wasm compatible --- Cargo.toml | 2 +- core/Cargo.toml | 9 +++++++-- core/src/lib.rs | 13 +++++++++---- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 2e6df40..0e20b06 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,10 +9,10 @@ bounded-collections = { version = "0.2", default-features = false } scale-info = { version = "2", default-features = false, features = ["derive"] } # Polkadot SDK +sp-io = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } binary-merkle-tree = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } sp-arithmetic = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } sp-core = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } -sp-io = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } sp-std = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } sp-trie = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } sp-runtime = { git = "https://github.com/availproject/polkadot-sdk.git", tag = "polkadot-1.7.1-patch-8", default-features = false } diff --git a/core/Cargo.toml b/core/Cargo.toml index 8e11492..9ddde23 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -5,6 +5,13 @@ authors = [] edition = "2021" license = "Apache-2.0" +# Target Dependencies +[target.'cfg(target_arch = "wasm32")'.dependencies] +sp-io = { workspace = true, features = ["disable_panic_handler"] } + +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +sp-io = { workspace = true } + [dependencies] # Others derive_more.workspace = true @@ -23,11 +30,9 @@ bounded-collections.workspace = true codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive", "max-encoded-len"] } scale-info.workspace = true -# Polkadot SDK frame-support = { workspace = true, optional = true } sp-arithmetic.workspace = true sp-core.workspace = true -sp-io.workspace = true sp-runtime = { workspace = true, optional = true } sp-runtime-interface = { workspace = true, optional = true } sp-std.workspace = true diff --git a/core/src/lib.rs b/core/src/lib.rs index b84f6b9..d846ae4 100644 --- a/core/src/lib.rs +++ b/core/src/lib.rs @@ -1,8 +1,10 @@ #![cfg_attr(not(feature = "std"), no_std)] #![deny(clippy::arithmetic_side_effects)] +use core::fmt::Debug; + use codec::{Decode, Encode, MaxEncodedLen}; -use derive_more::{Add, Constructor, Deref, Display, Into, Mul}; +use derive_more::{Add, Constructor, Deref, Into, Mul}; use scale_info::TypeInfo; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -88,11 +90,16 @@ pub enum InvalidTransactionCustomId { Into, MaxEncodedLen, RuntimeDebug, - Display, )] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AppId(#[codec(compact)] pub u32); +impl core::fmt::Display for AppId { + fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result { + write!(f, "{}", self.0) + } +} + impl Zero for AppId { fn zero() -> Self { AppId(Zero::zero()) @@ -119,7 +126,6 @@ impl Zero for AppId { Into, Constructor, MaxEncodedLen, - Display, Default, )] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize, Debug))] @@ -143,7 +149,6 @@ pub struct BlockLengthColumns(#[codec(compact)] pub u32); Ord, Into, Constructor, - Display, Default, )] #[mul(forward)]