Created
February 3, 2022 17:41
-
-
Save jamiebullock/acac9850c97ef182a69ee9b4dc04244a to your computer and use it in GitHub Desktop.
Elrond Adder
This file contains hidden or 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
#![no_std] | |
elrond_wasm::imports!(); | |
/// One of the simplest smart contracts possible, | |
/// it holds a single variable in storage, which anyone can increment. | |
#[elrond_wasm::derive::contract] | |
pub trait Adder { | |
#[view(getSum)] | |
#[storage_mapper("sum")] | |
fn sum(&self) -> SingleValueMapper<BigInt>; | |
#[init] | |
fn init(&self, initial_value: BigInt) { | |
self.sum().set(&initial_value); | |
} | |
/// Add desired amount to the storage variable. | |
#[endpoint] | |
fn add(&self, value: BigInt) -> SCResult<()> { | |
self.sum().update(|sum| *sum += value); | |
Ok(()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment