Scilla入門
Scillaの基本的なコード記法はOcamlライクな関数型言語となります。
終了句以外の末尾には;を付ける必要があり、コメントアウトは(* コメント *)と括弧とアスタリスクで囲みます。
Scillaのコントラクトは、LibraryとContractの2部構成で作成し、LibraryはContractの前に定義します。
code:HelloWorld.scilla
scilla_version 1
(* HelloWorld contract *)
import ListUtils
(***************************************************)
(* Associated library *)
(***************************************************)
library HelloWorld
let one_msg =
fun (msg : Message) =>
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg
let not_owner_code = Int32 1
let set_hello_code = Int32 2
(***************************************************)
(* The contract definition *)
(***************************************************)
contract HelloWorld
(owner: ByStr20)
field welcome_msg : String = ""
transition setHello (msg : String)
is_owner = builtin eq owner _sender;
match is_owner with
| False =>
msg = {_tag : "Main"; _recipient : _sender; _amount : Uint128 0; code : not_owner_code};
msgs = one_msg msg;
send msgs
| True =>
welcome_msg := msg;
msg = {_tag : "Main"; _recipient : _sender; _amount : Uint128 0; code : set_hello_code};
msgs = one_msg msg;
send msgs
end
end
transition getHello ()
r <- welcome_msg;
msg = {_tag : "Main"; _recipient : _sender; _amount : Uint128 0; msg : r};
msgs = one_msg msg;
send msgs
end