Created
October 18, 2018 07:22
-
-
Save saibakatar/86790f002a696e453f93ed625371ebdc to your computer and use it in GitHub Desktop.
Map declaration in Scilla
This file contains 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
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