/
Caller.scilla
34 lines (31 loc) 路 1009 Bytes
/
Caller.scilla
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
scilla_version 0
(***************************************************)
(* call transition GetValue() of another contract *)
(* "Callee" and get called back in ValueCallback()*)
(***************************************************)
library Caller
let zero = Uint128 0
(* Wrap single message into singleton list *)
let one_msg =
fun (msg : Message) =>
let nil_msg = Nil {Message} in
Cons {Message} msg nil_msg
(***************************************************)
contract Caller
( init_callee : ByStr20 )
field callee: ByStr20 = init_callee
field value: Uint128 = Uint128 0
(* calls the callee's GetValue transition, i.e asks *)
(* to be called back with value *)
transition CallForValue()
to <- callee;
msg = {_tag : "GetValue"; _recipient : to; _amount : zero};
msgs = one_msg msg;
send msgs
end
(* callback called by callee with value v *)
transition ValueCallback(v : Uint128)
value := v;
e = {_eventname : "ValueCallbackSuccess"; new_value : v};
event e
end