123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2024 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contextmoduleContract_entity=structincludeContract(* t, Compare, encoding *)letof_sources=Contract.of_b58checks|>Environment.wrap_tzresult|>record_trace_eval(fun()->error_of_fmt"bad contract notation")|>Lwt.returnletto_sources=letopenLwt_result_syntaxinreturn(Contract.to_b58checks)letname="contract"endmoduleRaw_contract_alias=Client_aliases.Alias(Contract_entity)moduleOriginated_contract_alias=structletfindcctxts=letopenLwt_result_syntaxinlet*contract_opt=Raw_contract_alias.find_optcctxtsinmatchcontract_optwith|Some(Contract.Originatedv)->returnv|Some(Implicit_)->failwith"contract %s is an implicit account"s|None->failwith"no contract named %s"sletof_literals=letopenLwt_result_syntaxinlet*!contract_opt=Contract_entity.of_sourcesinmatchcontract_optwith|Ok(Contract.Originatedv)->returnv|Ok(Implicit_)->failwith"contract %s is an implicit account"s|Error_aserr->Lwt.returnerrletfind_destinationcctxts=letopenLwt_result_syntaxinmatchString.split~limit:1':'swith|["alias";alias]->findcctxtalias|["text";text]->of_literaltext|_->(let*!contract_hash_opt=of_literalsinmatchcontract_hash_optwith|Ok_asok_v->Lwt.returnok_v|Errork_errs->(let*!contract_hash_opt=findcctxtsinLwt.return@@matchcontract_hash_optwith|Ok_asok_v->ok_v|Errorc_errs->Error(c_errs@k_errs)))letdestination_parameter()=Tezos_clic.parameter~autocomplete:Raw_contract_alias.autocompletefind_destinationletdestination_param?(name="dst")?(desc="destination contract")next=letdesc=String.concat"\n"[desc;"Can be a literal or an alias (autodetected in order).\n\
Use 'text:<literal>' or 'alias:<name>' to force.";]inTezos_clic.param~name~desc(destination_parameter())nextletdestination_arg?(name="dst")?(doc="destination contract")()=letdoc=String.concat"\n"[doc;"Can be a literal or an alias (autodetected in order).\n\
Use 'text:<literal>' or 'alias:<name>' to force.";]inTezos_clic.arg~long:name~doc~placeholder:name(destination_parameter())endmoduleContract_alias=structletfindcctxts=letopenLwt_result_syntaxinlet*contract_opt=Raw_contract_alias.find_optcctxtsinmatchcontract_optwith|Somev->returnv|None->(let*pkh_opt=Client_keys.Public_key_hash.find_optcctxtsinmatchpkh_optwith|Somev->return(Contract.Implicitv)|None->failwith"no contract or key named %s"s)letfind_keycctxtname=letopenLwt_result_syntaxinlet*v=Client_keys.Public_key_hash.findcctxtnameinreturn(Contract.Implicitv)letrev_findcctxt(c:Contract.t)=letopenLwt_result_syntaxinmatchcwith|Implicithash->(let*str_opt=Client_keys.Public_key_hash.rev_findcctxthashinmatchstr_optwith|Somename->return_some("key:"^name)|None->return_none)|Originated_->Raw_contract_alias.rev_findcctxtcletget_contractcctxts=matchString.split~limit:1':'swith|["key";key]->find_keycctxtkey|_->findcctxtsletautocompletecctxt=letopenLwt_result_syntaxinlet*keys=Client_keys.Public_key_hash.autocompletecctxtinlet*contracts=Raw_contract_alias.autocompletecctxtinreturn(List.map((^)"key:")keys@contracts)letalias_param?(name="name")?(desc="existing contract alias")next=letdesc=desc^"\n"^"Can be a contract alias or a key alias (autodetected in order).\n\
Use 'key:<name>' to force the later."inTezos_clic.(param~name~desc(parameter~autocompleteget_contract)next)letfind_destinationcctxts=letopenLwt_result_syntaxinmatchString.split~limit:1':'swith|["alias";alias]->findcctxtalias|["key";text]->let*v=Client_keys.Public_key_hash.findcctxttextinreturn(Contract.Implicitv)|["text";text]->Contract_entity.of_sourcetext|_->(let*!contract_opt=Contract_entity.of_sourcesinmatchcontract_optwith|Okv->returnv|Errorc_errs->(let*!contract_opt=findcctxtsinmatchcontract_optwith|Okv->returnv|Errork_errs->Lwt.return_error(c_errs@k_errs)))letdestination_parameter()=letopenLwt_result_syntaxinTezos_clic.parameter~autocomplete:(funcctxt->let*list1=autocompletecctxtinlet*list2=Client_keys.Public_key_hash.autocompletecctxtinreturn(list1@list2))find_destinationletdestination_param?(name="dst")?(desc="destination contract")next=letdesc=String.concat"\n"[desc;"Can be a literal, an alias, or a key (autodetected in order).\n\
Use 'text:<literal>', 'alias:<name>', 'key:<key>' to force.";]inTezos_clic.param~name~desc(destination_parameter())nextletdestination_arg?(name="dst")?(doc="destination contract")()=letdoc=String.concat"\n"[doc;"Can be a literal, an alias, or a key (autodetected in order).\n\
Use 'text:<literal>', 'alias:<name>', 'key:<key>' to force.";]inTezos_clic.arg~long:name~doc~placeholder:name(destination_parameter())letnamecctxtcontract=letopenLwt_result_syntaxinlet*str_opt=rev_findcctxtcontractinmatchstr_optwith|None->return(Contract.to_b58checkcontract)|Somename->returnnameendmoduleDestination_alias=structletcontract_parameter()=Tezos_clic.map_parameter~f:(func->Destination.Contractc)(Contract_alias.destination_parameter())letsmart_rollup_parameter()=Tezos_clic.map_parameter~f:(funsc->Destination.Sc_rollupsc)(Smart_rollup_alias.Address.parameter())letdestination_parameter()=Tezos_clic.compose_parameters(contract_parameter())(smart_rollup_parameter())letdestination_param?(name="dst")?(desc="destination address")next=letdesc=String.concat"\n"[desc;"Can be a literal, an alias, or a key (autodetected in order).\n\
Use 'text:<literal>', 'alias:<name>', 'key:<key>' to force.";]inTezos_clic.param~name~desc(destination_parameter())nextendletlist_contractscctxt=letopenLwt_result_syntaxinlet*raw_contracts=Raw_contract_alias.loadcctxtinletcontracts=List.map(fun(n,v)->("",n,v))raw_contractsinlet*keys=Client_keys.Public_key_hash.loadcctxtin(* List accounts (implicit contracts of identities) *)let*accounts=List.map_es(fun(n,v)->let*mem=Raw_contract_alias.memcctxtninletp=ifmemthen"key:"else""inletv'=Contract.Implicitvinreturn(p,n,v'))keysinreturn(contracts@accounts)letget_delegatecctxt~chain~blocksource=Alpha_services.Contract.delegate_optcctxt(chain,block)source