Skip to content

Commit

Permalink
add cache
Browse files Browse the repository at this point in the history
  • Loading branch information
prin-r committed Jul 6, 2020
1 parent 4d0f525 commit a4dc251
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions mumu/contract/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#![cfg_attr(
not(target_arch = "wasm32"),
crate_type = "target arch should be wasm32"
)]
#![no_main]

use casperlabs_contract::{
contract_api::{runtime, storage},
unwrap_or_revert::UnwrapOrRevert,
};
use casperlabs_types::{ApiError, Key, URef};

const KEY: &str = "special_value";

fn store(value: String) {
// Store `value` under a new unforgeable reference.
let value_ref: URef = storage::new_uref(value);

// Wrap the unforgeable reference in a value of type `Key`.
let value_key: Key = value_ref.into();

// Store this key under the name "special_value" in context-local storage.
runtime::put_key(KEY, value_key);
}

// All session code must have a `call` entrypoint.
#[no_mangle]
pub extern "C" fn call() {
// Get the optional first argument supplied to the argument.
let value: String = runtime::get_arg(0)
// Unwrap the `Option`, returning an error if there was no argument supplied.
.unwrap_or_revert_with(ApiError::MissingArgument)
// Unwrap the `Result` containing the deserialized argument or return an error if there was
// a deserialization error.
.unwrap_or_revert_with(ApiError::InvalidArgument);

store(value);
}

0 comments on commit a4dc251

Please sign in to comment.