Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file fancy_l2block.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2022 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. *)(* *)(*****************************************************************************)openProtocolopenAlpha_contexttypel2_message=|Ok_depositofTx_rollup_message.t*Tx_rollup_l2_apply.indexes|Failing_depositof{message:Tx_rollup_message.t;reason:Environment.Error_monad.error;withdrawal:Tx_rollup_withdraw.t;}|Ok_batchof{transactions_and_results:((Indexable.unknown,Indexable.unknown)Tx_rollup_l2_batch.V1.transaction*Tx_rollup_l2_apply.Message_result.transaction_result)list;withdrawals:Tx_rollup_withdraw.tlist;indexes:Tx_rollup_l2_apply.indexes;aggregated_signature:Tx_rollup_l2_batch.V1.signature;}|Failing_batchof{transactions:(Indexable.unknown,Indexable.unknown)Tx_rollup_l2_batch.V1.transactionlist;reasons:tztrace;aggregated_signature:Tx_rollup_l2_batch.V1.signature;}|Unparsable_batchofstringtypefancy_message={message:l2_message;l2_context_hash:Inbox.l2_context_hash;}typeinbox=fancy_messagelisttypet=inboxL2block.blockletticket_hash_valuectxtticket_hash=letopenIndexableinletopenLwt_syntaxinmatchdestructticket_hashwith|Leftindex->(let*ticket_opt=Context.get_ticketctxtindexinmatchticket_optwith|SomeTicket.{hash;_}->return(Tx_rollup_l2_context_sig.Ticket_indexable.valuehash|>Indexable.forget)|None->returnticket_hash)|Right_->returnticket_hashletaddress_valuectxtaddr=letopenIndexableinletopenLwt_syntaxinmatchdestructaddrwith|Leftindex->(let*addr_opt=Context.get_addressctxtindexinmatchaddr_optwith|Someaddr->return(Tx_rollup_l2_address.Indexable.valueaddr|>Indexable.forget)|None->returnaddr)|Right_->returnaddrletsigner_valuectxtsigner=(* After interpretation, the signer always has an associated address *)letopenIndexableinletopenLwt_syntaxinmatchdestructsignerwith|Leftindex->(letindex=to_int32indexinletindex=from_index_exnindexinlet*addr=address_valuectxtindexinmatchdestructaddrwith|Rightaddr->return(value(Tx_rollup_l2_batch.L2_addraddr)|>forget)|Left_->assertfalse)|RightTx_rollup_l2_batch.(L2_addr_)->returnsigner|RightTx_rollup_l2_batch.(Bls_pkpk)->letaddr=Signature.Bls.Public_key.hashpkinreturn(value(Tx_rollup_l2_batch.L2_addraddr)|>forget)lettransaction_replace_indexesctxttransaction=letopenTx_rollup_l2_batch.V1inletopenLwt_syntaxinletoperation_content_replace_index=function|Transfer{destination;ticket_hash;qty}->let*ticket_hash=ticket_hash_valuectxtticket_hashinlet*destination=address_valuectxtdestinationinreturn(Transfer{destination;ticket_hash;qty})|Withdraw_asx->returnxinletoperation_replace_indexes{signer;counter;contents}=let*contents=List.map_soperation_content_replace_indexcontentsinlet*signer=signer_valuectxtsignerinreturn{signer;counter;contents}inlet*operations=List.map_soperation_replace_indexestransactioninreturnoperationsletfancy_message_of_messagectxtInbox.{message;result;l2_context_hash}=letopenLwt_syntaxinlet*(l2_message:l2_message)=match(message,result)with|Batchs,Discardedtztrace->(letbatch_opt=Data_encoding.Binary.of_string_optTx_rollup_l2_batch.encodingsinmatchbatch_optwith|Some(V1batch)->return(Failing_batch{transactions=batch.contents;reasons=tztrace;aggregated_signature=batch.aggregated_signature;})|None->return(Unparsable_batchs))|(Batchs,Interpreted(Batch_V1_result(Batch_result{results;indexes}),withdrawals))->let(V1batch)=Data_encoding.Binary.of_string_exnTx_rollup_l2_batch.encodingsinlet_,results=List.splitresultsinlet*transactions=List.map_s(transaction_replace_indexesctxt)batch.contentsinlettransactions_and_results=Stdlib.List.combinetransactionsresultsinreturn(Ok_batch{transactions_and_results;withdrawals;indexes;aggregated_signature=batch.aggregated_signature;})|Deposit_,Interpreted(Deposit_result(Deposit_successindexes),_)->return(Ok_deposit(message,indexes))|(Deposit_,Interpreted(Deposit_result(Deposit_failureerror),[withdrawal]))->return(Failing_deposit{message;reason=error;withdrawal})|_->assertfalseinreturn{message=l2_message;l2_context_hash}letof_l2blockctxtL2block.{hash;header;inbox;commitment}=letopenLwt_syntaxinlet+fancy_inbox=Lwt_list.map_s(fancy_message_of_messagectxt)inboxinL2block.{hash;header;inbox=fancy_inbox;commitment}letindexes_encoding=letopenData_encodinginletopenTx_rollup_l2_applyinletindexablevalue_encodingindex_encoding=obj2(req"value"value_encoding)(req"index"index_encoding)inconv(fun{address_indexes;ticket_indexes}->(address_indexes,ticket_indexes))(fun(address_indexes,ticket_indexes)->{address_indexes;ticket_indexes})@@obj2(req"address_indexes"(list(indexableTx_rollup_l2_address.encodingTx_rollup_l2_address.Indexable.index_encoding)))(req"ticket_indexes"(list(indexableTicket_hash.encodingTx_rollup_l2_context_sig.Ticket_indexable.index_encoding)))(** TODO/TORU: https://gitlab.com/tezos/tezos/-/issues/2957
Copy-pasted from the protocol. *)lettransaction_result_encoding=letopenData_encodinginletopenTx_rollup_l2_apply.Message_resultinunion[(letkind="success"incase~title:kind(Tag0)(constantkind)(functionTransaction_success->Some()|_->None)(fun()->Transaction_success));(letkind="failure"incase~title:kind(Tag1)(obj1(reqkind(obj2(req"transaction_index"Data_encoding.int31)(req"reason"Environment.Error_monad.error_encoding))))(function|Transaction_failure{index;reason}->Some(index,reason)|_->None)(fun(index,reason)->Transaction_failure{index;reason}));](** TODO/TORU: https://gitlab.com/tezos/tezos/-/issues/2957
Copy-pasted from the protocol. *)letbatch_encoding=letopenData_encodinginletjson=convBytes.of_stringBytes.to_stringbytesinsplitted~json~binary:stringletl2_message_encoding=letopenData_encodinginunion[case~title:"ok_deposit"(Tag0)(merge_objsTx_rollup_message.encoding(obj2(req"result"(constant"success"))(req"indexes"indexes_encoding)))(function|Ok_deposit(deposit,indexes)->Some(deposit,((),indexes))|_->None)(fun(deposit,((),indexes))->Ok_deposit(deposit,indexes));case~title:"failing_deposit"(Tag1)(obj4(req"deposit"Tx_rollup_message.encoding)(req"result"(constant"failed"))(req"reason"Environment.Error_monad.error_encoding)(req"withdrawal"Tx_rollup_withdraw.encoding))(function|Failing_deposit{message;reason;withdrawal}->Some(message,(),reason,withdrawal)|_->None)(fun(message,(),reason,withdrawal)->Failing_deposit{message;reason;withdrawal});case~title:"ok_batch"(Tag2)(obj4(req"transactions_and_results"(list(obj2(req"transaction"Tx_rollup_l2_batch.V1.transaction_encoding)(req"result"transaction_result_encoding))))(req"withdrawals"(listTx_rollup_withdraw.encoding))(req"indexes"indexes_encoding)(req"aggregated_signature"Signature.Bls.encoding))(function|Ok_batch{transactions_and_results;withdrawals;indexes;aggregated_signature;}->Some(transactions_and_results,withdrawals,indexes,aggregated_signature)|_->None)(fun(transactions_and_results,withdrawals,indexes,aggregated_signature)->Ok_batch{transactions_and_results;withdrawals;indexes;aggregated_signature;});case~title:"failing_batch"(Tag3)(obj3(req"transactions"(listTx_rollup_l2_batch.V1.transaction_encoding))(req"errors"Error_monad.trace_encoding)(req"aggregated_signature"Signature.Bls.encoding))(function|Failing_batch{transactions;reasons;aggregated_signature}->Some(transactions,reasons,aggregated_signature)|_->None)(fun(transactions,reasons,aggregated_signature)->Failing_batch{transactions;reasons;aggregated_signature});case~title:"unparsable_batch"(Tag4)(obj2(req"batch"batch_encoding)(req"result"(constant"failed to parse")))(functionUnparsable_batchs->Some(s,())|_->None)(fun(s,())->Unparsable_batchs);]letfancy_message_encoding:fancy_messageData_encoding.t=letopenData_encodinginconv(fun{message;l2_context_hash}->(message,l2_context_hash))(fun(message,l2_context_hash)->{message;l2_context_hash})(obj2(req"l2_message"l2_message_encoding)(req"l2_context_hash"Inbox.l2_context_hash_encoding))letinbox_encoding=Data_encoding.listfancy_message_encodingletencoding=L2block.block_encodinginbox_encoding