Source file demo_client.ml
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
module Time = Tezos_base.Time.System
let default_delay = Time.Span.of_seconds_exn (3600. *. 24. *. 365.)
let spawn_activate_protocol ?endpoint ?(fitness = 1)
?(key = Constant.activator.alias) ?(timestamp = Client.Ago default_delay)
~parameter_file client =
let timestamp = Client.time_of_timestamp timestamp in
Client.spawn_command
?endpoint
client
[
"activate";
"protocol";
Protocol.demo_counter_hash;
"with";
"fitness";
string_of_int fitness;
"and";
"key";
key;
"and";
"parameters";
parameter_file;
"--timestamp";
Time.to_notation timestamp;
]
let activate ?endpoint ?fitness ?key ?timestamp client =
Lwt_io.with_temp_file (fun (parameter_file, ch) ->
let* () = Lwt_io.write_line ch "{}" in
spawn_activate_protocol
?endpoint
?fitness
?key
?timestamp
~parameter_file
client
|> Process.check)
let spawn_demo_bake ?(msg = "hello world") client =
Client.spawn_command client ["bake"; msg]
let bake ?msg client = spawn_demo_bake ?msg client |> Process.check
let spawn_get client name = Client.spawn_command client ["get"; name]
let get client name =
let (client_output : string) : int =
let value =
client_output =~* rex "The counter value is ?(\\w*)" |> mandatory "value"
in
match int_of_string_opt value with
| Some i -> i
| None -> failwith "Unexpected counter value."
in
let* output = spawn_get client name |> Process.check_and_read_stdout in
return @@ extract_key output
let get_a client = get client "a"
let get_b client = get client "b"
let spawn_increment client name =
Client.spawn_command client ["increment"; name]
let increment client name = spawn_increment client name |> Process.check
let increment_a client = increment client "a"
let increment_b client = increment client "b"
let spawn_transfer client amount =
Client.spawn_command client ["transfer"; string_of_int amount]
let transfer client amount = spawn_transfer client amount |> Process.check