123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200(*****************************************************************************)(* *)(* 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. *)(* *)(*****************************************************************************)openProtocol_client_contextmoduleEvents=Baking_events.Liquidity_bakingtypeper_block_votes={liquidity_baking_toggle_vote:Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_voteoption;}letper_block_votes_encoding=letopenData_encodingindef"per_block_votes.alpha"@@conv(fun{liquidity_baking_toggle_vote}->liquidity_baking_toggle_vote)(funliquidity_baking_toggle_vote->{liquidity_baking_toggle_vote})(obj1(opt"liquidity_baking_toggle_vote"Protocol.Alpha_context.Liquidity_baking.liquidity_baking_toggle_vote_encoding))typeerror+=Block_vote_file_not_foundofstringtypeerror+=Block_vote_file_invalidofstringtypeerror+=Block_vote_file_wrong_contentofstringtypeerror+=Block_vote_file_missing_liquidity_baking_toggle_voteofstringtypeerror+=Missing_vote_on_startuplet()=register_error_kind`Permanent~id:"Client_baking_forge.block_vote_file_not_found"~title:"The provided block vote file path does not point to an existing file."~description:"A block vote file path was provided on the command line but the path \
does not point to an existing file."~pp:(funppffile_path->Format.fprintfppf"@[The provided block vote file path \"%s\" does not point to an \
existing file.@]"file_path)Data_encoding.(obj1(req"file_path"string))(function|Block_vote_file_not_foundfile_path->Somefile_path|_->None)(funfile_path->Block_vote_file_not_foundfile_path);register_error_kind`Permanent~id:"Client_baking_forge.block_vote_file_invalid"~title:"The provided block vote file path does not point to a valid JSON file."~description:"A block vote file path was provided on the command line but the path \
does not point to a valid JSON file."~pp:(funppffile_path->Format.fprintfppf"@[The provided block vote file path \"%s\" does not point to a valid \
JSON file. The file exists but its content is not valid JSON.@]"file_path)Data_encoding.(obj1(req"file_path"string))(functionBlock_vote_file_invalidfile_path->Somefile_path|_->None)(funfile_path->Block_vote_file_invalidfile_path);register_error_kind`Permanent~id:"Client_baking_forge.block_vote_file_wrong_content"~title:"The content of the provided block vote file is unexpected."~description:"The block vote file is valid JSON but its content is not the expected \
one."~pp:(funppffile_path->Format.fprintfppf"@[The provided block vote file \"%s\" is a valid JSON file but its \
content is unexpected. Expecting a JSON file containing either \
'{\"liquidity_baking_toggle_vote\": \"on\"}', or \
'{\"liquidity_baking_toggle_vote\": \"off\"}', or \
'{\"liquidity_baking_toggle_vote\": \"pass\"}'.@]"file_path)Data_encoding.(obj1(req"file_path"string))(function|Block_vote_file_wrong_contentfile_path->Somefile_path|_->None)(funfile_path->Block_vote_file_wrong_contentfile_path);register_error_kind`Permanent~id:"Client_baking_forge.block_vote_file_missing_liquidity_baking_toggle_vote"~title:"In the provided block vote file, no entry for liquidity baking toggle \
vote was found"~description:"In the provided block vote file, no entry for liquidity baking toggle \
vote was found."~pp:(funppffile_path->Format.fprintfppf"@[In the provided block vote file \"%s\", the \
\"liquidity_baking_toggle_vote\" boolean field is missing. Expecting \
a JSON file containing either '{\"liquidity_baking_toggle_vote\": \
\"on\"}', or '{\"liquidity_baking_toggle_vote\": \"off\"}', or \
'{\"liquidity_baking_toggle_vote\": \"pass\"}'.@]"file_path)Data_encoding.(obj1(req"file_path"string))(function|Block_vote_file_missing_liquidity_baking_toggle_votefile_path->Somefile_path|_->None)(funfile_path->Block_vote_file_missing_liquidity_baking_toggle_votefile_path);register_error_kind`Permanent~id:"Client_baking_forge.missing_vote_on_startup"~title:"Missing vote on startup"~description:"No CLI flag, file path, or vote file in default location provided on \
startup"~pp:(funfmt()->Format.fprintffmt"Missing liquidity baking toggle vote, please use either the \
--liquidity-baking-toggle-vote or --per_block_vote_file option or a \
vote file in the default location: per_block_votes.json in the \
current working directory.")Data_encoding.empty(functionMissing_vote_on_startup->Some()|_->None)(fun()->Missing_vote_on_startup)lettraced_option_to_result~error=Option.fold~some:ok~none:(Result_syntax.tzfailerror)letcheck_file_existsfile=ifSys.file_existsfilethenResult.return_unitelseerror(Block_vote_file_not_foundfile)letread_liquidity_baking_toggle_vote~per_block_vote_file=Events.(emitreading_per_block)per_block_vote_file>>=fun()->check_file_existsper_block_vote_file>>?=fun()->trace(Block_vote_file_invalidper_block_vote_file)@@Lwt_utils_unix.Json.read_fileper_block_vote_file>>=?funvotes_json->Events.(emitper_block_vote_file_notice)"found">>=fun()->trace(Block_vote_file_wrong_contentper_block_vote_file)@@Error_monad.protect(fun()->return@@Data_encoding.Json.destructper_block_votes_encodingvotes_json)>>=?funvotes->Events.(emitper_block_vote_file_notice)"JSON decoded">>=fun()->traced_option_to_result~error:(Block_vote_file_missing_liquidity_baking_toggle_voteper_block_vote_file)votes.liquidity_baking_toggle_vote>>?=funliquidity_baking_toggle_vote->Events.(emitreading_liquidity_baking)()>>=fun()->Events.(emitliquidity_baking_toggle_vote)liquidity_baking_toggle_vote>>=fun()->returnliquidity_baking_toggle_voteletread_liquidity_baking_toggle_vote_no_fail~default~per_block_vote_file=read_liquidity_baking_toggle_vote~per_block_vote_file>>=function|Okvote->Lwt.returnvote|Errorerrs->Events.(emitper_block_vote_file_fail)errs>>=fun()->Lwt.returndefaultletread_liquidity_baking_toggle_vote_on_startup~default~per_block_vote_file=read_liquidity_baking_toggle_vote~per_block_vote_file>>=function|Okvote->return(vote,true)|Errorerrs->(matchdefaultwith|None->Events.(emitper_block_vote_file_fail)errs>>=fun()->failMissing_vote_on_startup|Somevote->return(vote,false))