123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 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. *)(* *)(*****************************************************************************)typet={limit_of_staking_over_baking_millionth:int32;edge_of_baking_over_staking_billionth:int32;}letmaximum_edge_of_baking_over_staking_billionth=(* max is 1 (1_000_000_000 billionth) *)1_000_000_000lletdefault={limit_of_staking_over_baking_millionth=0l;edge_of_baking_over_staking_billionth=1_000_000_000l;}typeerror+=Invalid_staking_parameterslet()=register_error_kind`Permanent~id:"operations.invalid_staking_parameters"~title:"Invalid parameters for staking parameters"~description:"The staking parameters are invalid."~pp:(funppf()->Format.fprintfppf"Invalid staking parameters")Data_encoding.empty(functionInvalid_staking_parameters->Some()|_->None)(fun()->Invalid_staking_parameters)letmake~limit_of_staking_over_baking_millionth~edge_of_baking_over_staking_billionth=ifCompare.Int32.(limit_of_staking_over_baking_millionth<0l)||Compare.Int32.(edge_of_baking_over_staking_billionth<0l)||Compare.Int32.(edge_of_baking_over_staking_billionth>maximum_edge_of_baking_over_staking_billionth)thenError()elseOk{limit_of_staking_over_baking_millionth;edge_of_baking_over_staking_billionth;}letencoding=letopenData_encodinginconv_with_guard(fun{limit_of_staking_over_baking_millionth;edge_of_baking_over_staking_billionth;}->(limit_of_staking_over_baking_millionth,edge_of_baking_over_staking_billionth))(fun(limit_of_staking_over_baking_millionth,edge_of_baking_over_staking_billionth)->Result.map_error(fun()->"Invalid staking parameters")(make~limit_of_staking_over_baking_millionth~edge_of_baking_over_staking_billionth))(obj2(req"limit_of_staking_over_baking_millionth"int32)(req"edge_of_baking_over_staking_billionth"int32))letmake~limit_of_staking_over_baking_millionth~edge_of_baking_over_staking_billionth=matchifCompare.Z.(limit_of_staking_over_baking_millionth<Z.zero)||Compare.Z.(edge_of_baking_over_staking_billionth<Z.zero)||not(Z.fits_int32edge_of_baking_over_staking_billionth)thenError()elseletlimit_of_staking_over_baking_millionth=ifZ.fits_int32limit_of_staking_over_baking_millionththenZ.to_int32limit_of_staking_over_baking_millionthelseInt32.max_intinletedge_of_baking_over_staking_billionth=Z.to_int32edge_of_baking_over_staking_billionthinmake~limit_of_staking_over_baking_millionth~edge_of_baking_over_staking_billionthwith|Error()->Result_syntax.tzfailInvalid_staking_parameters|Ok_asok->ok