1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 TriliTech <contact@trili.tech> *)(* *)(* 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. *)(* *)(*****************************************************************************)openSc_rollup_errorsmoduleStore=Storage.Sc_rollupmoduleCommitment=Sc_rollup_commitment_reprmoduleCommitment_hash=Commitment.Hashletget_commitment_unsafectxtrollupcommitment=letopenLwt_tzresult_syntaxinlet*ctxt,res=Store.Commitments.find(ctxt,rollup)commitmentinmatchreswith|None->fail(Sc_rollup_unknown_commitmentcommitment)|Somecommitment->return(commitment,ctxt)letlast_cemented_commitmentctxtrollup=letopenLwt_tzresult_syntaxinlet*ctxt,res=Store.Last_cemented_commitment.findctxtrollupinmatchreswith|None->fail(Sc_rollup_does_not_existrollup)|Somelcc->return(lcc,ctxt)letget_commitmentctxtrollupcommitment=letopenLwt_tzresult_syntaxin(* Assert that a last cemented commitment exists. *)let*_lcc,ctxt=last_cemented_commitmentctxtrollupinget_commitment_unsafectxtrollupcommitmentletlast_cemented_commitment_hash_with_levelctxtrollup=letopenLwt_tzresult_syntaxinlet*commitment_hash,ctxt=last_cemented_commitmentctxtrollupinifCommitment_hash.(commitment_hash=zero)thenlet+initial_level=Storage.Sc_rollup.Initial_level.getctxtrollupin(commitment_hash,initial_level,ctxt)elselet+{inbox_level;_},ctxt=get_commitment_unsafectxtrollupcommitment_hashin(commitment_hash,inbox_level,ctxt)letset_commitment_addedctxtrollupnodenew_value=letopenLwt_tzresult_syntaxinlet*ctxt,res=Store.Commitment_added.find(ctxt,rollup)nodeinmatchreswith|Someold_value->(* No need to re-add the read value *)return(0,old_value,ctxt)|None->let*ctxt,size_diff,_was_bound=Store.Commitment_added.add(ctxt,rollup)nodenew_valueinreturn(size_diff,new_value,ctxt)letget_predecessor_unsafectxtrollupnode=letopenLwt_tzresult_syntaxinlet*commitment,ctxt=get_commitment_unsafectxtrollupnodeinreturn(commitment.predecessor,ctxt)