1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192(*****************************************************************************)(* *)(* 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;_})=hash_comparable_datactxtkey_typekey>>=?fun(key_hash,ctxt)->match(Big_map_overlay.findkey_hashdiff.map,id)with|None,None->return(false,ctxt)|None,Someid->Alpha_context.Big_map.memctxtidkey_hash>|=?fun(ctxt,res)->(res,ctxt)|Some(_,None),_->return(false,ctxt)|Some(_,Some_),_->return(true,ctxt)letget_by_hashctxtkey(Big_map{id;diff;value_type;_})=match(Big_map_overlay.findkeydiff.map,id)with|Some(_,x),_->return(x,ctxt)|None,None->return(None,ctxt)|None,Someid->(Alpha_context.Big_map.get_optctxtidkey>>=?function|ctxt,None->return(None,ctxt)|ctxt,Somevalue->parse_datactxt~legacy:true~allow_forged:truevalue_type(Micheline.rootvalue)>|=?fun(x,ctxt)->(Somex,ctxt))letgetctxtkey(Big_map{key_type;_}asmap)=hash_comparable_datactxtkey_typekey>>=?fun(key_hash,ctxt)->get_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)=hash_comparable_datactxtkey_typekey>>=?fun(key_hash,ctxt)->letmap=update_by_hashkey_hashkeyvaluemapinreturn(map,ctxt)letget_and_updatectxtkeyvalue(Big_map{key_type;_}asmap)=hash_comparable_datactxtkey_typekey>>=?fun(key_hash,ctxt)->letnew_map=update_by_hashkey_hashkeyvaluemapinget_by_hashctxtkey_hashmap>>=?fun(old_value,ctxt)->return((old_value,new_map),ctxt)