123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contextmoduleContract_entity=structtypet=Contract.tinclude(Contract:Compare.Swithtypet:=t)letencoding=Contract.encodingletof_sources=matchContract.of_b58checkswith|Error_aserr->Lwt.return(Environment.wrap_errorerr)|>trace(error_of_fmt"bad contract notation")|Oks->returnsletto_sources=return(Contract.to_b58checks)letname="contract"endmoduleRaw_contract_alias=Client_aliases.Alias(Contract_entity)moduleContract_alias=structletfindcctxts=Raw_contract_alias.find_optcctxts>>=?function|Somev->return(s,v)|None->(Client_keys_v0.Public_key_hash.find_optcctxts>>=?function|Somev->return(s,Contract.implicit_contractv)|None->failwith"no contract or key named %s"s)letfind_keycctxtname=Client_keys_v0.Public_key_hash.findcctxtname>>=?funv->return(name,Contract.implicit_contractv)letrev_findcctxtc=matchContract.is_implicitcwith|Somehash->(Client_keys_v0.Public_key_hash.rev_findcctxthash>>=?function|Somename->return_some("key:"^name)|None->return_none)|None->Raw_contract_alias.rev_findcctxtcletget_contractcctxts=matchString.split~limit:1':'swith|["key";key]->find_keycctxtkey|_->findcctxtsletautocompletecctxt=Client_keys_v0.Public_key_hash.autocompletecctxt>>=?funkeys->Raw_contract_alias.autocompletecctxt>>=?funcontracts->return(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~autocomplete(funcctxtp->get_contractcctxtp))next)letdestination_parameter()=Tezos_clic.parameter~autocomplete:(funcctxt->autocompletecctxt>>=?funlist1->Client_keys_v0.Public_key_hash.autocompletecctxt>>=?funlist2->return(list1@list2))(funcctxts->matchString.split~limit:1':'swith|["alias";alias]->findcctxtalias|["key";text]->Client_keys_v0.Public_key_hash.findcctxttext>>=?funv->return(s,Contract.implicit_contractv)|_->(findcctxts>>=function|Okv->returnv|Errork_errs->(Contract_entity.of_sources>>=function|Okv->return(s,v)|Errorc_errs->Lwt.return_error(k_errs@c_errs))))letdestination_param?(name="dst")?(desc="destination contract")next=letdesc=String.concat"\n"[desc;"Can be an alias, a key, or a literal (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 an alias, a key, or a literal (autodetected in order).\n\
Use 'text:<literal>', 'alias:<name>', 'key:<key>' to force.";]inTezos_clic.arg~long:name~doc~placeholder:name(destination_parameter())letnamecctxtcontract=rev_findcctxtcontract>>=?function|None->return(Contract.to_b58checkcontract)|Somename->returnnameendletlist_contractscctxt=Raw_contract_alias.loadcctxt>>=?funraw_contracts->List.map_s(fun(n,v)->Lwt.return("",n,v))raw_contracts>>=funcontracts->Client_keys_v0.Public_key_hash.loadcctxt>>=?funkeys->(* List accounts (implicit contracts of identities) *)List.map_es(fun(n,v)->Raw_contract_alias.memcctxtn>>=?funmem->letp=ifmemthen"key:"else""inletv'=Contract.implicit_contractvinreturn(p,n,v'))keys>>=?funaccounts->return(contracts@accounts)letget_delegatecctxt~chain~blocksource=Alpha_services.Contract.delegate_optcctxt(chain,block)source