123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)modulePre_entrypoint:sig(** Invariants on the string: 1 <= length <= 31 *)typet=privateNon_empty_string.tvalof_non_empty_string:Non_empty_string.t->toptionend=structtypet=Non_empty_string.tletof_non_empty_string(str:Non_empty_string.t)=ifCompare.Int.(String.length(str:>string)>31)thenNoneelseSomestrendtypet=Pre_entrypoint.tletcompare(x:t)(y:t)=Non_empty_string.compare(x:>Non_empty_string.t)(y:>Non_empty_string.t)let(=)(x:t)(y:t)=Non_empty_string.(=)(x:>Non_empty_string.t)(y:>Non_empty_string.t)typeerror+=Name_too_longofstringlet()=(* Entrypoint name too long *)register_error_kind`Permanent~id:"michelson_v1.entrypoint_name_too_long"~title:"Entrypoint name too long (type error)"~description:"An entrypoint name exceeds the maximum length of 31 characters."Data_encoding.(obj1(req"name"@@stringPlain))(functionName_too_longentrypoint->Someentrypoint|_->None)(funentrypoint->Name_too_longentrypoint)typeerror+=Unexpected_defaultofScript_repr.locationlet()=register_error_kind`Permanent~id:"michelson_v1.unexpected_default_entrypoint"~title:"The annotation 'default' was encountered where an entrypoint is expected"~description:"A node in the syntax tree was improperly annotated. An annotation used \
to designate an entrypoint cannot be exactly 'default'."Data_encoding.(obj1(req"location"Script_repr.location_encoding))(functionUnexpected_defaultloc->Someloc|_->None)(funloc->Unexpected_defaultloc)letdefault=matchPre_entrypoint.of_non_empty_string@@Non_empty_string.of_string_exn"default"with|None->assertfalse|Someres->resletis_defaultname=name=defaulttypeof_string_result=|Okoft|Too_long(** length > 31 *)|Got_default(** Got exactly "default", which can be an error in some cases or OK in others *)letof_non_empty_string(str:Non_empty_string.t)=matchPre_entrypoint.of_non_empty_stringstrwith|None->Too_long|Somestr->ifis_defaultstrthenGot_defaultelseOkstrletof_stringstr=matchNon_empty_string.of_stringstrwith|None(* empty string *)->(* The empty string always means the default entrypoint *)Okdefault|Somestr->of_non_empty_stringstrletof_string_strict~locstr=matchof_stringstrwith|Too_long->error(Name_too_longstr)|Got_default->error(Unexpected_defaultloc)|Okname->Oknameletof_string_strict'str=matchof_stringstrwith|Too_long->Error"Entrypoint name too long"|Got_default->Error"Unexpected annotation: default"|Okname->Oknameletof_string_strict_exnstr=matchof_string_strict'strwithOkv->v|Errorerr->invalid_argerrletof_annot_strict~loca=matchof_non_empty_stringawith|Too_long->error(Name_too_long(a:>string))|Got_default->error(Unexpected_defaultloc)|Okname->Oknameletof_annot_lax_opta=matchof_non_empty_stringawith|Too_long->None|Got_default->Somedefault|Okname->Somenameletof_string_lax_optstr=matchof_stringstrwith|Too_long->None|Got_default->Somedefault|Okname->Somenameletof_string_laxstr=matchof_string_lax_optstrwith|None->error(Name_too_longstr)|Somename->Oknameletof_annot_laxa=matchof_non_empty_stringawith|Too_long->error(Name_too_long(a:>string))|Got_default->Okdefault|Okname->Oknameletof_string_lax'str=matchof_string_lax_optstrwith|None->Error("Entrypoint name too long \""^str^"\"")|Somename->Oknameletroot=of_string_strict_exn"root"letdo_=of_string_strict_exn"do"letset_delegate=of_string_strict_exn"set_delegate"letremove_delegate=of_string_strict_exn"remove_delegate"letdeposit=of_string_strict_exn"deposit"letis_deposit=(=)depositletis_root=(=)rootletto_non_empty_string(name:t)=(name:>Non_empty_string.t)letto_string(name:t)=(name:>string)letto_address_suffix(name:t)=ifis_defaultnamethen""else"%"^(name:>string)letunparse_as_field_annot(name:t)="%"^(name:>string)letof_string_lax_exnstr=matchof_string_lax'strwithOkname->name|Errorerr->invalid_argerrletppfmt(name:t)=Format.pp_print_stringfmt(name:>string)letsimple_encoding=Data_encoding.conv_with_guard(fun(name:t)->(name:>string))of_string_lax'Data_encoding.(stringPlain)letvalue_encoding=Data_encoding.conv_with_guard(funname->ifis_defaultnamethen""else(name:>string))of_string_strict'Data_encoding.Variable.(stringPlain)letsmart_encoding=letopenData_encodingindef~title:"entrypoint"~description:"Named entrypoint to a Michelson smart contract""entrypoint"@@letbuiltin_casetag(name:Pre_entrypoint.t)=case(Tagtag)~title:(name:>string)(constant(name:>string))(funn->ifn=namethenSome()elseNone)(fun()->name)inunion[builtin_case0default;builtin_case1root;builtin_case2do_;builtin_case3set_delegate;builtin_case4remove_delegate;builtin_case5deposit;case(Tag255)~title:"named"(Bounded.stringPlain31)(fun(name:Pre_entrypoint.t)->Some(name:>string))of_string_lax_exn;]letrpc_arg=RPC_arg.make~descr:"A Michelson entrypoint (string of length < 32)"~name:"entrypoint"~construct:(fun(name:t)->(name:>string))~destruct:of_string_lax'()letin_memory_size(name:t)=Cache_memory_helpers.string_size_gen(String.length(name:>string))moduleT=structtypenonrect=tletcompare=compareendmoduleSet=Set.Make(T)moduleMap=Map.Make(T)