123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 G.B. Fefe <gb.fefe@protonmail.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)moduleTime=Tezos_base.Time.Systemletdefault_delay=Time.Span.of_seconds_exn(3600.*.24.*.365.)letspawn_activate_protocol?endpoint?(fitness=1)?(key=Constant.activator.alias)?(timestamp=Client.Agodefault_delay)~parameter_fileclient=lettimestamp=Client.time_of_timestamptimestampinClient.spawn_command?endpointclient["activate";"protocol";Protocol.demo_counter_hash;"with";"fitness";string_of_intfitness;"and";"key";key;"and";"parameters";parameter_file;"--timestamp";Time.to_notationtimestamp;]letactivate?endpoint?fitness?key?timestampclient=Lwt_io.with_temp_file(fun(parameter_file,ch)->let*()=Lwt_io.write_linech"{}"inspawn_activate_protocol?endpoint?fitness?key?timestamp~parameter_fileclient|>Process.check)letspawn_demo_bake?(msg="hello world")client=Client.spawn_commandclient["bake";msg]letbake?msgclient=spawn_demo_bake?msgclient|>Process.checkletspawn_getclientname=Client.spawn_commandclient["get";name]letgetclientname=letextract_key(client_output:string):int=letvalue=client_output=~*rex"The counter value is ?(\\w*)"|>mandatory"value"inmatchint_of_string_optvaluewith|Somei->i|None->failwith"Unexpected counter value."inlet*output=spawn_getclientname|>Process.check_and_read_stdoutinreturn@@extract_keyoutputletget_aclient=getclient"a"letget_bclient=getclient"b"letspawn_incrementclientname=Client.spawn_commandclient["increment";name]letincrementclientname=spawn_incrementclientname|>Process.checkletincrement_aclient=incrementclient"a"letincrement_bclient=incrementclient"b"letspawn_transferclientamount=Client.spawn_commandclient["transfer";string_of_intamount]lettransferclientamount=spawn_transferclientamount|>Process.check