123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263(*****************************************************************************)(* *)(* 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={a:int32;b:int32}letinvariant{a;b}=Compare.Int32.(a>=0l&&b>=0l)letcreateab=letst={a;b}inifinvariantstthenSomestelseNoneletencoding=Data_encoding.conv(fun{a;b}->(a,b))(fun(a,b)->{a;b})Data_encoding.(obj2(req"demo_a"int32)(req"demo_b"int32))letencoding_length=matchData_encoding.Binary.fixed_lengthencodingwith|None->assertfalse|Somelength->lengthletstate_key=["state"]letget_statecontext=Context.findcontextstate_key>|=function|None->assertfalse|Someencoded_state->(matchData_encoding.Binary.of_bytes_optencodingencoded_statewith|Somex->x|None->assertfalse)letupdate_statecontextstate=letencoded_state=Data_encoding.Binary.to_bytes_exnencodingstateinContext.addcontextstate_keyencoded_state