Skip to content

Instantly share code, notes, and snippets.

@saibakatar
Created October 18, 2018 07:22
Show Gist options
  • Save saibakatar/86790f002a696e453f93ed625371ebdc to your computer and use it in GitHub Desktop.
Save saibakatar/86790f002a696e453f93ed625371ebdc to your computer and use it in GitHub Desktop.
Map declaration in Scilla
contract Maps()
field a: Map ByStr20 String = Emp ByStr20 String (*declaring variable a with no value*)
field b: Map ByStr20 Int32 = let c = Emp ByStr20 Int32 in
let d = 0x1234567890123456789012345678901234567896 in
let e = Int32 5 in
builtin put c d e (*declaring variable b with fixed value*)
transition update_value()
f = 0xffff567890123456789012345678901234567896;
g = "hello";
h = Int32 6;
(*updating variable a*)
i <- a;
j = builtin put i f g;
a:= j; (*Puts a new entry in the previously empty map a*)
(*updating variable b*)
k <- b;
l = builtin put k f h;
b:= l; (*updates a new entry in the map b along with the existing entries*)
(*to extract the entry stored against a key in a map, one can use the following method*)
m = builtin get k f; (*m is not equal to the value h stored, but is equal to the Option h. We'll need to further extract value from here*)
match m with
| Some n => (*this variable n now contains the value originally stored in the map*)
(*perform relevant operations on n*)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment