123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2021-2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Trili Tech <contact@trili.tech> *)(* Copyright (c) 2022 Marigold <team@marigold.dev> *)(* *)(* 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. *)(* *)(*****************************************************************************)openScript_typed_iropenScript_ir_translatorletemptykey_typevalue_type=Big_map{id=None;diff={map=Big_map_overlay.empty;size=0};key_type;value_type;}letmemctxtkey(Big_map{id;diff;key_type;_})=letopenLwt_result_syntaxinlet*key_hash,ctxt=hash_comparable_datactxtkey_typekeyinmatch(Big_map_overlay.findkey_hashdiff.map,id)with|None,None->return(false,ctxt)|None,Someid->let+ctxt,res=Alpha_context.Big_map.memctxtidkey_hashin(res,ctxt)|Some(_,None),_->return(false,ctxt)|Some(_,Some_),_->return(true,ctxt)letget_by_hashctxtkey(Big_map{id;diff;value_type;_})=letopenLwt_result_syntaxinmatch(Big_map_overlay.findkeydiff.map,id)with|Some(_,x),_->return(x,ctxt)|None,None->return(None,ctxt)|None,Someid->(let*ctxt,value_opt=Alpha_context.Big_map.get_optctxtidkeyinmatchvalue_optwith|None->return(None,ctxt)|Somevalue->let+x,ctxt=parse_datactxt~elab_conf:Script_ir_translator_config.(make~legacy:true())~allow_forged:truevalue_type(Micheline.rootvalue)in(Somex,ctxt))letgetctxtkey(Big_map{key_type;_}asmap)=letopenLwt_result_syntaxinlet*key_hash,ctxt=hash_comparable_datactxtkey_typekeyinget_by_hashctxtkey_hashmapletupdate_by_hashkey_hashkeyvalue(Big_mapmap)=letcontains=Big_map_overlay.memkey_hashmap.diff.mapinBig_map{mapwithdiff={map=Big_map_overlay.addkey_hash(key,value)map.diff.map;size=(ifcontainsthenmap.diff.sizeelsemap.diff.size+1);};}letupdatectxtkeyvalue(Big_map{key_type;_}asmap)=letopenLwt_result_syntaxinlet*key_hash,ctxt=hash_comparable_datactxtkey_typekeyinletmap=update_by_hashkey_hashkeyvaluemapinreturn(map,ctxt)letget_and_updatectxtkeyvalue(Big_map{key_type;_}asmap)=letopenLwt_result_syntaxinlet*key_hash,ctxt=hash_comparable_datactxtkey_typekeyinletnew_map=update_by_hashkey_hashkeyvaluemapinlet*old_value,ctxt=get_by_hashctxtkey_hashmapinreturn((old_value,new_map),ctxt)