123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.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. *)(* *)(*****************************************************************************)typet=int32typeraw_level=tinclude(Compare.Int32:Compare.Swithtypet:=t)letencoding=Data_encoding.int32letppppflevel=Format.fprintfppf"%ld"levelletrpc_arg=letconstructraw_level=Int32.to_stringraw_levelinletdestructstr=matchInt32.of_stringstrwith|exception_->Error"Cannot parse level"|raw_level->Okraw_levelinRPC_arg.make~descr:"A level integer"~name:"block_level"~construct~destruct()letroot=0lletsucc=Int32.succletpredl=ifl=0lthenNoneelseSome(Int32.predl)letdiff=Int32.subletto_int32l=lletof_int32_exnl=ifCompare.Int32.(l>=0l)thenlelseinvalid_arg"Level_repr.of_int32"typeerror+=Unexpected_levelofInt32.t(* `Permanent *)let()=register_error_kind`Permanent~id:"unexpected_level"~title:"Unexpected level"~description:"Level must be non-negative."~pp:(funppfl->Format.fprintfppf"The level is %s but should be non-negative."(Int32.to_stringl))Data_encoding.(obj1(req"level"int32))(functionUnexpected_levell->Somel|_->None)(funl->Unexpected_levell)letof_int32l=tryOk(of_int32_exnl)with_->Error[Unexpected_levell]moduleIndex=structtypet=raw_levelletpath_length=1letto_pathlevell=Int32.to_stringlevel::lletof_path=function|[s]->begintrySome(Int32.of_strings)with_->Noneend|_->Noneletrpc_arg=rpc_argletencoding=encodingletcompare=compareend