Skip to content

Instantly share code, notes, and snippets.

@ink-playground-gists
Created November 16, 2022 07:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ink-playground-gists/d9a6046d0b9909e4d3459ea13f562115 to your computer and use it in GitHub Desktop.
Save ink-playground-gists/d9a6046d0b9909e4d3459ea13f562115 to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
#![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