diff --git a/contract-helpers/Cargo.toml b/contract-helpers/Cargo.toml deleted file mode 100644 index fac6fbb56e..0000000000 --- a/contract-helpers/Cargo.toml +++ /dev/null @@ -1,13 +0,0 @@ -[package] -name = "contract-helpers" -description = """Helper functions for smart contracts""" -categories = ["wasm", "no-std", "cryptography::cryptocurrencies"] -keywords = ["virtual", "machine", "smart", "contract", "wasm"] - -repository = "https://github.com/dusk-network/rusk" -version = "0.1.0" - -edition = "2021" -license = "MPL-2.0" - -[dependencies] diff --git a/contract-helpers/Makefile b/contract-helpers/Makefile deleted file mode 100644 index 4439d5d113..0000000000 --- a/contract-helpers/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -help: ## Display this help screen - @grep -h -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-15s\033[0m %s\n", $$1, $$2}' - -test: ## Run tests - @cargo test --release -- --nocapture - -clean: - @cargo clean - -clippy: ## Run clippy - @cargo clippy --all-features --release -- -D warnings - -.PHONY: test help clean diff --git a/contract-helpers/src/collection.rs b/contract-helpers/src/collection.rs deleted file mode 100644 index fbe58070a2..0000000000 --- a/contract-helpers/src/collection.rs +++ /dev/null @@ -1,160 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -use alloc::vec::Vec; - -#[derive(Debug, Clone)] -pub struct Map { - data: Vec<(K, V)>, -} - -#[derive(Debug, Clone)] -pub struct Set { - data: Vec, -} - -#[allow(dead_code)] -impl Map { - pub const fn new() -> Self { - Self { data: Vec::new() } - } - - pub fn len(&self) -> usize { - self.data.len() - } - - pub fn is_empty(&self) -> bool { - self.len() == 0 - } - - pub fn get(&self, key: &K) -> Option<&V> { - self.data.iter().find_map(|(k, v)| (k == key).then_some(v)) - } - - pub fn get_mut(&mut self, key: &K) -> Option<&mut V> { - self.data - .iter_mut() - .find_map(|(k, v)| (k == key).then_some(v)) - } - - pub fn insert(&mut self, key: K, value: V) { - if let Some(pos) = self.data.iter().position(|(k, _)| k == &key) { - self.data[pos] = (key, value) - } else { - self.data.push((key, value)) - } - } - - pub fn remove(&mut self, key: &K) { - self.data.retain(|(k, _)| k != key); - } - - pub fn find(&self, f: F) -> Option<&V> - where - F: Fn(&V) -> bool, - { - self.data.iter().find_map(|(_, v)| f(v).then_some(v)) - } - - pub fn filter(&self, f: F) -> impl Iterator - where - F: Fn(&V) -> bool, - { - self.data.iter().filter_map(move |(_, v)| f(v).then_some(v)) - } - - pub fn entries_filter(&self, f: F) -> impl Iterator - where - F: Fn((&K, &V)) -> bool, - { - self.data.iter().filter(move |(k, v)| f((k, v))) - } -} - -#[allow(dead_code)] -impl Set { - pub const fn new() -> Self { - Self { data: Vec::new() } - } - - pub fn get(&self, value: &V) -> Option<&V> { - self.data.iter().find(|&v| v == value) - } - - pub fn contains(&self, value: &V) -> bool { - self.data.iter().any(|v| v == value) - } - - pub fn insert(&mut self, value: V) -> bool { - if self.contains(&value) { - return false; - } - - self.data.push(value); - true - } - - pub fn remove(&mut self, value: &V) { - self.data.retain(|v| v != value); - } -} - -impl Default for Map { - fn default() -> Self { - Self { data: Vec::new() } - } -} - -impl Default for Set { - fn default() -> Self { - Self { data: Vec::new() } - } -} - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_map() { - let mut data = Map::::default(); - - assert!(data.get(&1).is_none()); - assert!(data.get(&12).is_none()); - - data.insert(12, 0); - - assert!(data.get(&1).is_none()); - assert!(data.get(&12).is_some()); - - data.remove(&12); - - assert!(data.get(&1).is_none()); - assert!(data.get(&12).is_none()); - } - - #[test] - fn test_set() { - let mut data = Set::::default(); - - assert!(!data.contains(&1), "1 is not in the set"); - assert!(!data.contains(&12), "12 is not in the set"); - - data.insert(12); - - assert!(!data.contains(&1), "1 is still not in the set"); - assert!(data.contains(&12), "12 is in the set"); - - data.remove(&12); - - assert!(!data.contains(&1), "1 is still not in the set"); - assert!(!data.contains(&12), "12 is removed from the set"); - - data.remove(&10); - - assert!(!data.contains(&10), "10 is not in the set"); - } -} diff --git a/contract-helpers/src/lib.rs b/contract-helpers/src/lib.rs deleted file mode 100644 index e1172482a6..0000000000 --- a/contract-helpers/src/lib.rs +++ /dev/null @@ -1,12 +0,0 @@ -// This Source Code Form is subject to the terms of the Mozilla Public -// License, v. 2.0. If a copy of the MPL was not distributed with this -// file, You can obtain one at http://mozilla.org/MPL/2.0/. -// -// Copyright (c) DUSK NETWORK. All rights reserved. - -#![no_std] - -extern crate alloc; - -mod collection; -pub use collection::*;