123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2019-2020 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. *)(* *)(*****************************************************************************)openAlpha_contextletcustom_root=RPC_path.open_rootmoduleSeed_computation=structmoduleS=structletseed_computation_status_encoding=letopenSeedinData_encoding.(union[case(Tag0)~title:"Nonce revelation stage"(obj1(req"nonce_revelation_stage"unit))(functionNonce_revelation_stage->Some()|_->None)(fun()->Nonce_revelation_stage);case(Tag1)~title:"VDF revelation stage"(obj2(req"seed_discriminant"Seed.seed_encoding)(req"seed_challenge"Seed.seed_encoding))(function|Vdf_revelation_stage{seed_discriminant;seed_challenge}->Some(seed_discriminant,seed_challenge)|_->None)(fun(seed_discriminant,seed_challenge)->Vdf_revelation_stage{seed_discriminant;seed_challenge});case(Tag2)~title:"Computation finished"(obj1(req"computation_finished"unit))(functionComputation_finished->Some()|_->None)(fun()->Computation_finished);])letseed_computation=RPC_service.get_service~description:"Seed computation status"~query:RPC_query.empty~output:seed_computation_status_encodingRPC_path.(custom_root/"context"/"seed_computation")endlet()=letopenServices_registrationinregister0~chunked:falseS.seed_computation(functxt()()->Seed.get_seed_computation_statusctxt)letgetctxtblock=RPC_context.make_call0S.seed_computationctxtblock()()endmoduleSeed=structmoduleS=structopenData_encodingletseed=RPC_service.post_service~description:"Seed of the cycle to which the block belongs."~query:RPC_query.empty~input:empty~output:Seed.seed_encodingRPC_path.(custom_root/"context"/"seed")endlet()=letopenServices_registrationinregister0~chunked:falseS.seed(functxt()()->letl=Level.currentctxtinSeed.for_cyclectxtl.cycle)letgetctxtblock=RPC_context.make_call0S.seedctxtblock()()endmoduleNonce=structtypeinfo=RevealedofNonce.t|MissingofNonce_hash.t|Forgottenletinfo_encoding=letopenData_encodinginunion[case(Tag0)~title:"Revealed"(obj1(req"nonce"Nonce.encoding))(functionRevealednonce->Somenonce|_->None)(funnonce->Revealednonce);case(Tag1)~title:"Missing"(obj1(req"hash"Nonce_hash.encoding))(functionMissingnonce->Somenonce|_->None)(funnonce->Missingnonce);case(Tag2)~title:"Forgotten"empty(functionForgotten->Some()|_->None)(fun()->Forgotten);]moduleS=structletget=RPC_service.get_service~description:"Info about the nonce of a previous block."~query:RPC_query.empty~output:info_encodingRPC_path.(custom_root/"context"/"nonces"/:Raw_level.rpc_arg)endletregister()=letopenServices_registrationinregister1~chunked:falseS.get(functxtraw_level()()->letlevel=Level.from_rawctxtraw_levelinNonce.getctxtlevel>|=function|Ok(Revealednonce)->ok(Revealednonce)|Ok(Unrevealed{nonce_hash;_})->ok(Missingnonce_hash)|Error_->okForgotten)letgetctxtblocklevel=RPC_context.make_call1S.getctxtblocklevel()()endtypeerror+=No_available_snapshotsof{min_cycle:int32}let()=Error_monad.register_error_kind`Permanent~id:"no_available_snapshots"~title:"No available snapshots"~description:"No available snapshots"~pp:(funppfmin_cycle->Format.fprintfppf"No available snapshots until cycle %ld"min_cycle)Data_encoding.(obj1(req"min_cycle"int32))(function|No_available_snapshots{min_cycle}->Somemin_cycle|_->None)(funmin_cycle->No_available_snapshots{min_cycle})moduleSnapshot_index=structmoduleS=structletcycle_query:Cycle.toptionRPC_query.t=letopenRPC_queryinquery(funx->x)|+opt_field"cycle"Cycle.rpc_arg(funcycle->cycle)|>sealletselected_snapshot=RPC_service.get_service~description:"Returns the index of the selected snapshot for the current cycle or \
for the specific `cycle` passed as argument, if any."~query:cycle_query~output:Data_encoding.int31RPC_path.(custom_root/"context"/"selected_snapshot")endletregister()=letopenServices_registrationinregister0~chunked:falseS.selected_snapshot(functxtcycle()->(* max_snapshot_index can be determined using constants only *)letblocks_per_stake_snapshot=Alpha_context.Constants.blocks_per_stake_snapshotctxtinletblocks_per_cycle=Alpha_context.Constants.blocks_per_cyclectxtinletpreserved_cycles=Int32.of_int(Alpha_context.Constants.preserved_cyclesctxt)inletcycle=matchcyclewith|None->Level.(currentctxt).cycle|Somecycle->cycleinifCompare.Int32.(Cycle.to_int32cycle<=Int32.succpreserved_cycles)then(* Early cycles are corner cases, fail if requested *)tzfail(No_available_snapshots{min_cycle=Int32.addpreserved_cycles2l})elseletmax_snapshot_index=Int32.divblocks_per_cycleblocks_per_stake_snapshot|>Int32.to_intinAlpha_context.Stake_distribution.compute_snapshot_indexctxtcycle~max_snapshot_index)letgetctxtblock?cycle()=RPC_context.make_call0S.selected_snapshotctxtblockcycle()endmoduleContract=Contract_servicesmoduleConstants=Constants_servicesmoduleDelegate=Delegate_servicesmoduleVoting=Voting_servicesmoduleSapling=Sapling_servicesmoduleTx_rollup=Tx_rollup_servicesmoduleLiquidity_baking=structmoduleS=structletget_cpmm_address=RPC_service.get_service~description:"Liquidity baking CPMM address"~query:RPC_query.empty~output:Alpha_context.Contract.originated_encodingRPC_path.(custom_root/"context"/"liquidity_baking"/"cpmm_address")endletregister()=letopenServices_registrationinregister0~chunked:falseS.get_cpmm_address(functxt()()->Alpha_context.Liquidity_baking.get_cpmm_addressctxt)letget_cpmm_addressctxtblock=RPC_context.make_call0S.get_cpmm_addressctxtblock()()endmoduleCache=structmoduleS=structletcached_contracts=RPC_service.get_service~description:"Return the list of cached contracts"~query:RPC_query.empty~output:Data_encoding.(list@@tup2Contract_hash.encodingint31)RPC_path.(custom_root/"context"/"cache"/"contracts"/"all")letcontract_cache_size=RPC_service.get_service~description:"Return the size of the contract cache"~query:RPC_query.empty~output:Data_encoding.int31RPC_path.(custom_root/"context"/"cache"/"contracts"/"size")letcontract_cache_size_limit=RPC_service.get_service~description:"Return the size limit of the contract cache"~query:RPC_query.empty~output:Data_encoding.int31RPC_path.(custom_root/"context"/"cache"/"contracts"/"size_limit")letcontract_rank=RPC_service.post_service~description:"Return the number of cached contracts older than the provided \
contract"~query:RPC_query.empty~input:Alpha_context.Contract.originated_encoding~output:Data_encoding.(optionint31)RPC_path.(custom_root/"context"/"cache"/"contracts"/"rank")endletregister()=letopenServices_registrationinregister0~chunked:trueS.cached_contracts(functxt()()->Script_cache.entriesctxt|>Lwt.return);register0~chunked:falseS.contract_cache_size(functxt()()->Script_cache.sizectxt|>return);register0~chunked:falseS.contract_cache_size_limit(functxt()()->Script_cache.size_limitctxt|>return);register0~chunked:falseS.contract_rank(functxt()contract->Script_cache.contract_rankctxtcontract|>return)letcached_contractsctxtblock=RPC_context.make_call0S.cached_contractsctxtblock()()letcontract_cache_sizectxtblock=RPC_context.make_call0S.contract_cache_sizectxtblock()()letcontract_cache_size_limitctxtblock=RPC_context.make_call0S.contract_cache_size_limitctxtblock()()letcontract_rankctxtblockcontract=RPC_context.make_call0S.contract_rankctxtblock()contractendletregister()=Contract.register();Constants.register();Delegate.register();Nonce.register();Snapshot_index.register();Voting.register();Sapling.register();Liquidity_baking.register();Cache.register();Tx_rollup.register()