123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 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. *)(* *)(*****************************************************************************)openTezos_michelineopenProtocolopenAlpha_contexttypeerror+=|Wrong_stack_itemofMicheline_parser.location*Micheline_printer.node|Wrong_stackofMicheline_parser.location*Micheline_printer.node|Wrong_other_contracts_itemofMicheline_parser.location*Micheline_printer.node|Wrong_other_contractsofMicheline_parser.location*Micheline_printer.node|Wrong_extra_big_maps_itemofMicheline_parser.location*Micheline_printer.node|Wrong_extra_big_mapsofMicheline_parser.location*Micheline_printer.node|Invalid_address_for_smart_contractofstringletmicheline_printer_location_encoding:Micheline_printer.locationData_encoding.encoding=letopenData_encodinginconv(funloc->loc.Micheline_printer.comment)(funcomment->{comment})(optionstring)letmicheline_printer_node_encoding:Micheline_printer.nodeData_encoding.encoding=Micheline_encoding.table_encoding~variant:""micheline_printer_location_encodingData_encoding.stringlet()=letopenData_encodinginProtocol_client_context.register_error_kind`Permanent~id:"michelson.stack.wrong_stack_item"~title:"Wrong stack item"~description:"Failed to parse an item in a typed stack."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for an item in a typed stack. Expected: Stack_elt \
<ty> <value>; got %a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(functionWrong_stack_item(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_stack_item(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"michelson.stack.wrong_stack"~title:"Wrong stack"~description:"Failed to parse a typed stack."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for a typed stack. Expected a sequence of Stack_elt \
<ty> <value>; got %a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(functionWrong_stack(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_stack(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"michelson.wrong_other_contracts_item"~title:"Wrong description of an other contract"~description:"Failed to parse an item in a description of other contracts."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for an item in a description of other contracts. \
Expected: Contract <address> <ty>; got %a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(function|Wrong_other_contracts_item(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_other_contracts_item(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"michelson.wrong_other_contracts"~title:"Wrong description of a list of other contracts"~description:"Failed to parse a description of other contracts."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for a description of other contracts. Expected a \
sequence of Contract <address> <ty>; got %a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(function|Wrong_other_contracts(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_other_contracts(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"michelson.wrong_extra_big_maps_item"~title:"Wrong description of an extra big map"~description:"Failed to parse an item in a description of extra big maps."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for an item in a description of extra big maps. \
Expected: Big_map <index> <key_type> <value_type> <content>; got %a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(function|Wrong_extra_big_maps_item(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_extra_big_maps_item(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"michelson.wrong_extra_big_maps"~title:"Wrong description of a list of extra big maps"~description:"Failed to parse a description of extra big maps."~pp:(funppf(_loc,node)->Format.fprintfppf"Unexpected format for a description of extra big maps. Expected a \
sequence of Big_map <index> <key_type> <value_type> <content>; got \
%a."Micheline_printer.print_expr_unwrappednode)(obj2(req"location"Micheline_parser.location_encoding)(req"node"micheline_printer_node_encoding))(function|Wrong_extra_big_maps(loc,node)->Some(loc,node)|_->None)(fun(loc,node)->Wrong_extra_big_maps(loc,node));Protocol_client_context.register_error_kind`Permanent~id:"InvalidAddressForSmartContract"~title:"Invalid address for smart contract"~description:"Invalid input, expected a smart contract address in base58 check \
notation (KT1...)"Data_encoding.(obj1(req"invalid_address"string))~pp:(funppfliteral->Format.fprintfppf"Bad argument value for a smart contract address. Expected an address \
in base58 checked notation starting with 'KT1', but given '%s'"literal)(functionInvalid_address_for_smart_contractstr->Somestr|_->None)(funstr->Invalid_address_for_smart_contractstr)letparse_expression~source(node:Micheline_parser.node):Script.exprtzresult=letopenResult_syntaxinletparsing_result=Michelson_v1_parser.expand_all~source~original:nodeinlet*parsed=Micheline_parser.no_parsing_errorparsing_resultinreturnparsed.expandedletprintablenode=Micheline_printer.printableFun.id(Micheline.strip_locationsnode)letparse_stack_item~source=letopenResult_syntaxinfunction|Micheline.Prim(_loc,"Stack_elt",[ty;v],_annot)->let*ty=parse_expression~sourcetyinlet*v=parse_expression~sourcevinreturn(ty,v)|e->tzfail(Wrong_stack_item(Micheline.locatione,printablee))letparse_other_contract_item~source=letopenResult_syntaxinfunction|Micheline.Prim(_loc,"Contract",[address;ty],_annot)ase->let*address=parse_expression~sourceaddressinlet*address=matchMicheline.rootaddresswith|Micheline.String(_loc,s)->(matchEnvironment.Base58.decodeswith|Some(Contract_hash.Datah)->returnh|Some_|None->tzfail(Invalid_address_for_smart_contracts))|_->tzfail(Wrong_other_contracts_item(Micheline.locatione,printablee))inlet*ty=parse_expression~sourcetyinreturnRPC.Scripts.S.{address;ty}|e->tzfail(Wrong_other_contracts_item(Micheline.locatione,printablee))letparse_extra_big_map_item~source=letopenResult_syntaxinfunction|Micheline.Prim(_loc,"Big_map",[id;kty;vty;items],_annot)ase->let*id=parse_expression~sourceidinlet*id=matchMicheline.rootidwith|Micheline.Int(_loc,id)->return(Big_map.Id.parse_zid)|_->tzfail(Wrong_other_contracts_item(Micheline.locatione,printablee))inlet*kty=parse_expression~sourcektyinlet*vty=parse_expression~sourcevtyinlet*items=parse_expression~sourceitemsinreturnRPC.Scripts.S.{id;kty;vty;items}|e->tzfail(Wrong_extra_big_maps_item(Micheline.locatione,printablee))letparse_stack~source=function|Micheline.Seq(loc,l)ase->record_trace(Wrong_stack(loc,printablee))@@List.map_e(parse_stack_item~source)l|e->Result_syntax.tzfail(Wrong_stack(Micheline.locatione,printablee))letparse_other_contracts~source=function|Micheline.Seq(loc,l)ase->record_trace(Wrong_other_contracts(loc,printablee))@@List.map_e(parse_other_contract_item~source)l|e->Result_syntax.tzfail(Wrong_other_contracts(Micheline.locatione,printablee))letparse_extra_big_maps~source=function|Micheline.Seq(loc,l)ase->record_trace(Wrong_extra_big_maps(loc,printablee))@@List.map_e(parse_extra_big_map_item~source)l|e->Result_syntax.tzfail(Wrong_extra_big_maps(Micheline.locatione,printablee))