123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 Marigold <contact@marigold.dev> *)(* Copyright (c) 2022 Nomadic Labs <contact@nomadic-labs.com> *)(* Copyright (c) 2022 Oxhead Alpha <info@oxheadalpha.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. *)(* *)(*****************************************************************************)typet=|ContractofContract_repr.t|Sc_rollupofSc_rollup_repr.t|Zk_rollupofZk_rollup_repr.t(* If you add more cases to this type, please update the
[test_compare_destination] test in
[test/unit/test_destination_repr.ml] to ensure that the compare
function keeps its expected behavior to distinguish between
implicit accounts and smart contracts. *)includeCompare.Make(structtypenonrect=tletcomparel1l2=match(l1,l2)with|Contractk1,Contractk2->Contract_repr.comparek1k2|Sc_rollupk1,Sc_rollupk2->Sc_rollup_repr.Address.comparek1k2|Zk_rollupk1,Zk_rollupk2->Zk_rollup_repr.Address.comparek1k2(* This function is used by the Michelson interpreter to compare
addresses. It is of significant importance to remember that in
Michelson, address comparison is used to distinguish between
KT1 and tz1. As a consequence, we want to preserve that [tz1 <
KT1 < others], which the two following lines ensure. The
wildcards are therefore here for a reason, and should not be
modified when new constructors are added to [t]. *)|Contract_,_->-1|_,Contract_->1|Sc_rollup_,_->-1|_,Sc_rollup_->1end)letto_b58check=function|Contractk->Contract_repr.to_b58checkk|Sc_rollupk->Sc_rollup_repr.Address.to_b58checkk|Zk_rollupk->Zk_rollup_repr.Address.to_b58checkktypeerror+=Invalid_destination_b58checkofstringlet()=letopenData_encodinginregister_error_kind`Permanent~id:"destination_repr.invalid_b58check"~title:"Destination decoding failed"~description:"Failed to read a valid destination from a b58check_encoding data"(obj1(req"input"(stringPlain)))(functionInvalid_destination_b58checkx->Somex|_->None)(funx->Invalid_destination_b58checkx)letof_b58datadata=letdecode_on_nonedecodewrap=function|Somex->Somex|None->Option.mapwrap@@decodedatainNone|>decode_on_noneContract_repr.of_b58data(func->Contractc)|>decode_on_noneSc_rollup_repr.Address.of_b58data(funs->Sc_rollups)|>decode_on_noneZk_rollup_repr.Address.of_b58data(funz->Zk_rollupz)letof_b58check_opts=Option.bind(Base58.decodes)of_b58dataletof_b58checks=matchof_b58check_optswith|None->error(Invalid_destination_b58checks)|Somedest->Okdestletencoding=letopenData_encodinginletcase=function|Tagtag->(* The tag was used by old variant. It have been removed in
protocol proposal O, it can be unblocked in the future. *)lettx_rollup_address_reserved_tag=2inassert(Compare.Int.(tag<>tx_rollup_address_reserved_tag));case(Tagtag)|_asc->casecindef"transaction_destination"~title:"A destination of a transaction"~description:"A destination notation compatible with the contract notation as given \
to an RPC or inside scripts. Can be a base58 implicit contract hash, a \
base58 originated contract hash, a base58 originated transaction \
rollup, or a base58 originated smart rollup."@@splitted~binary:(union~tag_size:`Uint8(Contract_repr.cases(functionContractx->Somex|_->None)(funx->Contractx)@[case(Tag3)(Fixed.add_paddingSc_rollup_repr.Address.encoding1)~title:"Smart_rollup"(functionSc_rollupk->Somek|_->None)(funk->Sc_rollupk);case(Tag4)(Fixed.add_paddingZk_rollup_repr.Address.encoding1)~title:"Zk_rollup"(functionZk_rollupk->Somek|_->None)(funk->Zk_rollupk);]))~json:(convto_b58check(funs->matchof_b58checkswith|Oks->s|Error_->Data_encoding.Json.cannot_destruct"Invalid destination notation.")(stringPlain))letpp:Format.formatter->t->unit=funfmt->function|Contractk->Contract_repr.ppfmtk|Sc_rollupk->Sc_rollup_repr.ppfmtk|Zk_rollupk->Zk_rollup_repr.Address.ppfmtkletin_memory_size=letopenCache_memory_helpersinfunction|Contractk->h1w+!Contract_repr.in_memory_sizek|Sc_rollupk->h1w+!Sc_rollup_repr.in_memory_sizek|Zk_rollupk->h1w+!Zk_rollup_repr.in_memory_sizek