Commit 986f6123 authored by Jun Furuse's avatar Jun Furuse

more examples

parent 05e72dd9
Pipeline #114765902 passed with stage
in 8 minutes and 3 seconds
open SCaml
type storage =
{ first : nat
; last : nat
; map : (nat, string) map
}
let [@entry] add s storage =
let last = storage.last +^ Nat 1 in
let map = Map.update last (Some s) storage.map in
[], { storage with last; map }
let [@entry] pop () storage =
let first = storage.first in
let last = storage.last in
if first = last then assert false;
let map = Map.update first None storage.map in
let first = first +^ Nat 1 in
[], { storage with first; map }
open SCaml
type storage =
{ key : key
; counter : nat
; string : string
}
let [@entry] get () storage =
if Global.get_amount () < Tz 1.0 then failwith "too low";
[], storage (* Unlike the original example, we cannot return the string *)
let [@entry] set (sign, s, n) storage =
if storage.counter <> n then failwith "invalid counter";
if not (Crypto.check_signature storage.key sign (Obj.pack (sign, n))) then
failwith "invalid signature";
[],
{ storage
with counter= storage.counter +^ Nat 1
; string= s
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment