123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs, <contact@nomadic-labs.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. *)(* *)(*****************************************************************************)openInjector_sigsmoduleMake(O:PARAM_OPERATION):INJECTOR_OPERATIONwithtypeoperation=O.t=structmoduleHash=Tezos_crypto.Blake2B.Make(Tezos_crypto.Base58)(structletname="injector_operation_hash"lettitle="An identifier (hash) for an operation in the injector"letb58check_prefix="\064\007\206"(* iop(53) *)letsize=Noneend)let()=Tezos_crypto.Base58.check_encoded_prefixHash.b58check_encoding"iop"53typeoperation=O.ttypehash=Hash.ttypeerrors={count:int;last_error:tztraceoption}typet={hash:hash;operation:O.t;mutableerrors:errors}lethash_inner_operationnonceop=Hash.hash_string[Option.fold~none:""~some:Z.to_bitsnonce;Data_encoding.Binary.to_string_exnO.encodingop;]letcounter=refZ.zeroletno_errors={count=0;last_error=None}letmakeoperation=letnonce=ifnot@@O.uniqueoperationthen(letc=!counterincounter:=Z.succ!counter;Somec)elseNoneinlethash=hash_inner_operationnonceoperationin{hash;operation;errors=no_errors}leterrors_encoding=letopenData_encodinginconv(fun{count;last_error}->(count,last_error))(fun(count,last_error)->{count;last_error})@@obj2(req"count"int31)(opt"last_error"trace_encoding)letencoding=letopenData_encodinginconv(fun{hash;operation;errors}->(hash,operation,errors))(fun(hash,operation,errors)->{hash;operation;errors})@@obj3(req"hash"Hash.encoding)(req"operation"O.encoding)(dft"errors"errors_encodingno_errors)letppppf{hash;operation;errors}=letpp_errorsppferrors=iferrors.count=0then()elseFormat.fprintfppf" [%d errors]"errors.countinFormat.fprintfppf"%a (%a)%a"O.ppoperationHash.pphashpp_errorserrorsletregister_erroroperror_trace=op.errors<-{count=op.errors.count+1;last_error=Someerror_trace}end