123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111(*****************************************************************************)(* *)(* 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=letopenResult_syntaxinfunction|Blstz4->tzfail(Forbidden_tz4_delegatetz4)|Ed25519_|Secp256k1_|P256_->return_unitletfind=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=letopenLwt_result_syntaxinlet*?()=check_not_tz4delegateinlet*ctxt=Storage.Contract.Delegate.initctxtcontractdelegateinletdelegate_contract=Contract_repr.Implicitdelegateinlet*!ctxt=Storage.Contract.Delegated.add(ctxt,delegate_contract)contractinreturnctxtletunlinkctxtcontract=letopenLwt_result_syntaxinlet*delegate_opt=Storage.Contract.Delegate.findctxtcontractinmatchdelegate_optwith|None->returnctxt|Somedelegate->letdelegate_contract=Contract_repr.Implicitdelegateinlet*!ctxt=Storage.Contract.Delegated.remove(ctxt,delegate_contract)contractinreturnctxtletdeletectxtcontract=letopenLwt_result_syntaxinlet*ctxt=unlinkctxtcontractinlet*!ctxt=Storage.Contract.Delegate.removectxtcontractinreturnctxtletsetctxtcontractdelegate=letopenLwt_result_syntaxinlet*?()=check_not_tz4delegateinlet*ctxt=unlinkctxtcontractinlet*!ctxt=Storage.Contract.Delegate.addctxtcontractdelegateinletdelegate_contract=Contract_repr.Implicitdelegateinlet*!ctxt=Storage.Contract.Delegated.add(ctxt,delegate_contract)contractinreturnctxtletdelegated_contractsctxtdelegate=letcontract=Contract_repr.ImplicitdelegateinStorage.Contract.Delegated.elements(ctxt,contract)