1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2021 Nomadic Labs, <contact@nomadic-labs.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+=(* `Permanent *)Forbidden_tz4_delegateofBls.Public_key_hash.tlet()=register_error_kind`Branch~id:"delegate.forbidden_tz4"~title:"Forbidden delegate"~description:"Delegates are forbidden to be tz4 (BLS) accounts."~pp:(funppfimplicit->Format.fprintfppf"The delegate %a is forbidden as it is a BLS public key hash."Bls.Public_key_hash.ppimplicit)Data_encoding.(obj1(req"delegate"Bls.Public_key_hash.encoding))(functionForbidden_tz4_delegated->Somed|_->None)(fund->Forbidden_tz4_delegated)letcheck_not_tz4:Signature.Public_key_hash.t->unittzresult=function|Blstz4->error(Forbidden_tz4_delegatetz4)|Ed25519_|Secp256k1_|P256_->Ok()letfind=Storage.Contract.Delegate.findtypedelegate_status=|Delegate|DelegatedofSignature.Public_key_hash.t|Undelegatedletget_delegate_statusctxtpkh=letopenLwt_result_syntaxinlet+delegate=findctxt(Contract_repr.Implicitpkh)inmatchdelegatewith|None->Undelegated|SomedelegatewhenSignature.Public_key_hash.(delegate=pkh)->Delegate|Somedelegate->Delegateddelegateletis_delegatectxtpkh=letopenLwt_result_syntaxinlet+find_res=get_delegate_statusctxtpkhinmatchfind_reswithDelegate->true|Delegated_|Undelegated->falseletinitctxtcontractdelegate=check_not_tz4delegate>>?=fun()->Storage.Contract.Delegate.initctxtcontractdelegate>>=?functxt->letdelegate_contract=Contract_repr.ImplicitdelegateinStorage.Contract.Delegated.add(ctxt,delegate_contract)contract>|=okletunlinkctxtcontract=Storage.Contract.Delegate.findctxtcontract>>=?function|None->returnctxt|Somedelegate->letdelegate_contract=Contract_repr.ImplicitdelegateinStorage.Contract.Delegated.remove(ctxt,delegate_contract)contract>|=okletdeletectxtcontract=unlinkctxtcontract>>=?functxt->Storage.Contract.Delegate.removectxtcontract>|=okletsetctxtcontractdelegate=check_not_tz4delegate>>?=fun()->unlinkctxtcontract>>=?functxt->Storage.Contract.Delegate.addctxtcontractdelegate>>=functxt->letdelegate_contract=Contract_repr.ImplicitdelegateinStorage.Contract.Delegated.add(ctxt,delegate_contract)contract>|=okletdelegated_contractsctxtdelegate=letcontract=Contract_repr.ImplicitdelegateinStorage.Contract.Delegated.elements(ctxt,contract)