-
-
Save ink-playground-gists/d9a6046d0b9909e4d3459ea13f562115 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#![cfg_attr(not(feature = "std"), no_std)] | |
use ink_lang as ink; | |
#[ink::contract] | |
mod test { | |
use ink_storage::traits::{SpreadAllocate, SpreadLayout}; | |
use ink_storage::Mapping; | |
#[derive(SpreadAllocate, SpreadLayout, Debug)] | |
#[cfg_attr(feature = "std", derive(scale_info::TypeInfo, ink_storage::traits::StorageLayout))] | |
pub struct MerkleTree<const LEAVES: u32> { | |
nodes: Mapping<u32, Hash>, | |
next_free_leaf: u32, | |
} | |
/// The only way of constructing `MerkleTree`. | |
impl<const LEAVES: u32> Default for MerkleTree<LEAVES> { | |
fn default() -> Self { | |
if !LEAVES.is_power_of_two() { | |
panic!("Please have 2^n leaves") | |
} | |
Self { | |
nodes: Mapping::default(), | |
next_free_leaf: LEAVES, | |
} | |
} | |
} | |
#[ink(storage)] | |
#[derive(SpreadAllocate)] | |
pub struct Contract { | |
tree: MerkleTree<1024>, | |
} | |
impl Contract { | |
#[ink(constructor)] | |
pub fn new() -> Self { | |
// ink_lang::utils::initialize_contract(|_: &mut Test| {}) | |
Self { tree: Default::default() } | |
} | |
#[ink(message)] | |
pub fn get(&self) {} | |
} | |
} | |
// #[cfg(test)] | |
// mod tests { | |
// use crate::test::Contract; | |
// use super::*; | |
// #[ink::test] | |
// fn default_works() { | |
// let t = Contract::new(); | |
// // assert_eq!(t.get(), 100) | |
// } | |
// } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment