From b845db8a6c46cb00e21396ae26f4d72ffdd6e567 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aleksandar=20Terenti=C4=87?= Date: Fri, 4 Oct 2024 10:08:56 +0200 Subject: [PATCH] Expose public parameters and Position fns in no-std --- Cargo.lock | 12 ++++++++---- kate/recovery/Cargo.toml | 6 +++++- kate/recovery/src/data.rs | 6 +++++- kate/recovery/src/lib.rs | 1 - kate/recovery/src/matrix.rs | 7 +++++-- 5 files changed, 23 insertions(+), 9 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index efc87a50..67a3e9b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1756,13 +1756,15 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.12" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "190092ea657667030ac6a35e305e62fc4dd69fd98ac98631e5d3a2b1575a12b5" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if", + "js-sys", "libc", "wasi", + "wasm-bindgen", ] [[package]] @@ -2144,6 +2146,7 @@ dependencies = [ "derive_more", "dusk-bytes", "dusk-plonk", + "getrandom", "hex", "once_cell", "parity-scale-codec", @@ -2151,6 +2154,7 @@ dependencies = [ "rand_chacha", "serde", "sp-arithmetic", + "sp-io", "sp-std", "static_assertions", "test-case", @@ -2174,9 +2178,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.159" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "561d97a539a36e26a9a5fad1ea11a3039a67714694aaa379433e580854bc3dc5" [[package]] name = "libm" diff --git a/kate/recovery/Cargo.toml b/kate/recovery/Cargo.toml index 9e885d52..d3e7c1b2 100644 --- a/kate/recovery/Cargo.toml +++ b/kate/recovery/Cargo.toml @@ -5,10 +5,14 @@ authors = ["Denis Ermolin "] edition = "2018" license = "Apache-2.0" +[target.'cfg(target_arch = "wasm32")'.dependencies] +getrandom = { version = "0.2.15", features = ["js"] } +sp-io = { workspace = true, features = [ "disable_panic_handler" ] } + [dependencies] # Internals avail-core = { path = "../../core", default-features = false } -dusk-plonk = { workspace = true, optional = true } +dusk-plonk = { workspace = true } # Parity codec = { package = "parity-scale-codec", version = "3", default-features = false, features = ["derive"] } diff --git a/kate/recovery/src/data.rs b/kate/recovery/src/data.rs index d55fab75..02a7387b 100644 --- a/kate/recovery/src/data.rs +++ b/kate/recovery/src/data.rs @@ -4,6 +4,11 @@ use sp_std::{collections::btree_map::BTreeMap, vec::Vec}; use crate::matrix::{Dimensions, Position, RowIndex}; +#[cfg(target_arch = "wasm32")] +extern crate alloc; +#[cfg(target_arch = "wasm32")] +use alloc::string::String; + /// Position and data of a cell in extended matrix #[derive(Default, Debug, Clone, Constructor)] pub struct DataCell { @@ -23,7 +28,6 @@ pub struct Cell { } impl Cell { - #[cfg(feature = "std")] pub fn reference(&self, block: u32) -> String { self.position.reference(block) } diff --git a/kate/recovery/src/lib.rs b/kate/recovery/src/lib.rs index deca212c..d7777992 100644 --- a/kate/recovery/src/lib.rs +++ b/kate/recovery/src/lib.rs @@ -11,5 +11,4 @@ pub mod sparse_slice_read; #[cfg(feature = "std")] pub mod testnet; -#[cfg(feature = "std")] pub mod couscous; diff --git a/kate/recovery/src/matrix.rs b/kate/recovery/src/matrix.rs index 1f61abdf..8679c7bd 100644 --- a/kate/recovery/src/matrix.rs +++ b/kate/recovery/src/matrix.rs @@ -12,6 +12,11 @@ use sp_std::vec; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; +#[cfg(target_arch = "wasm32")] +extern crate alloc; +#[cfg(target_arch = "wasm32")] +use alloc::{format, string::String}; + /// Position of a cell in the the matrix. #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[derive(Default, Debug, Clone, Copy, Hash, Eq, PartialEq, Constructor)] @@ -51,7 +56,6 @@ impl Display for Position { impl Position { /// Reference in format `block_number:column_number:row_number` - #[cfg(feature = "std")] pub fn reference(&self, block_number: u32) -> String { format!("{}:{}", block_number, self) } @@ -76,7 +80,6 @@ pub struct RowIndex(pub u32); impl RowIndex { /// Reference in format `block_number:row_number` - #[cfg(feature = "std")] pub fn reference(&self, block_number: u32) -> String { format!("{}:{}", block_number, self.0) }