123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)typeerror+=Cannot_pay_storage_fee(* `Temporary *)typeerror+=Operation_quota_exceeded(* `Temporary *)typeerror+=Storage_limit_too_high(* `Permanent *)let()=letopenData_encodinginregister_error_kind`Temporary~id:"contract.cannot_pay_storage_fee"~title:"Cannot pay storage fee"~description:"The storage fee is higher than the contract balance"~pp:(funppf()->Format.fprintfppf"Cannot pay storage storage fee")Data_encoding.empty(functionCannot_pay_storage_fee->Some()|_->None)(fun()->Cannot_pay_storage_fee);register_error_kind`Temporary~id:"storage_exhausted.operation"~title:"Storage quota exceeded for the operation"~description:"A script or one of its callee wrote more \
bytes than the operation said it would"Data_encoding.empty(functionOperation_quota_exceeded->Some()|_->None)(fun()->Operation_quota_exceeded);register_error_kind`Permanent~id:"storage_limit_too_high"~title:"Storage limit out of protocol hard bounds"~description:"A transaction tried to exceed the hard limit on storage"empty(functionStorage_limit_too_high->Some()|_->None)(fun()->Storage_limit_too_high)letorigination_burnc~payer=letorigination_burn=Constants_storage.origination_burncinContract_storage.spend_from_scriptcpayerorigination_burn>>=?func->return(c,origination_burn)letrecord_paid_storage_spaceccontract=Contract_storage.used_storage_spaceccontract>>=?funsize->Contract_storage.set_paid_storage_space_and_return_fees_to_payccontractsize>>=?fun(to_be_paid,c)->letc=Raw_context.update_storage_space_to_paycto_be_paidinletcost_per_byte=Constants_storage.cost_per_bytecinLwt.return(Tez_repr.(cost_per_byte*?(Z.to_int64to_be_paid)))>>=?funto_burn->return(c,size,to_be_paid,to_burn)letburn_storage_feesc~storage_limit~payer=letc,storage_space_to_pay=Raw_context.clear_storage_space_to_paycinletremaining=Z.substorage_limitstorage_space_to_payinifCompare.Z.(remaining<Z.zero)thenfailOperation_quota_exceededelseletcost_per_byte=Constants_storage.cost_per_bytecinLwt.return(Tez_repr.(cost_per_byte*?(Z.to_int64storage_space_to_pay)))>>=?funto_burn->(* Burning the fees... *)ifTez_repr.(to_burn=Tez_repr.zero)then(* If the payer was was deleted by transfering all its balance, and no space was used,
burning zero would fail *)returncelsetraceCannot_pay_storage_fee(Contract_storage.must_existcpayer>>=?fun()->Contract_storage.spend_from_scriptcpayerto_burn)>>=?func->returncletcheck_storage_limitc~storage_limit=ifCompare.Z.(storage_limit>(Raw_context.constantsc).hard_storage_limit_per_operation)||Compare.Z.(storage_limit<Z.zero)thenerrorStorage_limit_too_highelseok()letstart_counting_storage_feesc=Raw_context.init_storage_space_to_payc