pub use anyhow::Result; use std::collections::{HashMap, HashSet}; use tig_structs::{config::*, core::*}; #[allow(async_fn_in_trait)] pub trait Context { async fn get_algorithm_state(&self, algorithm_id: &String) -> Option; async fn add_algorithm_to_mempool( &self, details: AlgorithmDetails, code: AlgorithmCode, ) -> Result; async fn get_benchmark_details(&self, benchmark_id: &String) -> Option; async fn get_benchmark_data( &self, benchmark_id: &String, ) -> Option<(HashSet, HashSet)>; async fn add_benchmark_to_mempool( &self, benchmark_id: String, details: BenchmarkDetails, solution_nonces: HashSet, discarded_solution_nonces: HashSet, ) -> Result<()>; async fn get_binary_details(&self, algorithm_id: &String) -> Option; async fn add_binary_to_mempool( &self, algorithm_id: String, details: BinaryDetails, ) -> Result<()>; async fn get_latest_block_id(&self) -> String; async fn get_block_details(&self, block_id: &String) -> Option; async fn get_breakthrough_state(&self, breakthrough_id: &String) -> Option; async fn add_breakthrough_to_mempool( &self, details: BreakthroughDetails, evidence: String, ) -> Result; async fn get_challenge_state(&self, challenge_id: &String) -> Option; async fn get_challenge_block_data( &self, challenge_id: &String, block_id: &String, ) -> Option; async fn get_config(&self) -> ProtocolConfig; async fn add_deposit_to_mempool(&self, details: DepositDetails) -> Result; async fn get_player_details(&self, player_id: &String) -> Option; async fn get_player_state(&self, player_id: &String) -> Option; async fn get_player_block_data( &self, player_id: &String, block_id: &String, ) -> Option; async fn set_player_delegatees( &self, player_id: String, delegatees: HashMap, ) -> Result<()>; async fn set_player_reward_share(&self, player_id: String, reward_share: f64) -> Result<()>; async fn set_player_coinbase( &self, player_id: String, coinbase: HashMap, ) -> Result<()>; async fn set_player_vote( &self, player_id: String, breakthrough_id: String, yes: bool, ) -> Result<()>; async fn get_precommit_settings(&self, benchmark_id: &String) -> Option; async fn get_precommit_details(&self, benchmark_id: &String) -> Option; async fn add_precommit_to_mempool( &self, settings: BenchmarkSettings, details: PrecommitDetails, ) -> Result; async fn get_proof_details(&self, benchmark_id: &String) -> Option; async fn get_proof_state(&self, benchmark_id: &String) -> Option; async fn add_proof_to_mempool( &self, benchmark_id: String, merkle_proofs: Vec, allegation: Option, ) -> Result<()>; async fn add_topup_to_mempool(&self, details: TopUpDetails) -> Result; async fn build_block_cache(&self) -> AddBlockCache; async fn commit_block_cache(&self, cache: AddBlockCache); } pub struct AddBlockCache { pub config: ProtocolConfig, pub block_details: BlockDetails, pub block_data: BlockData, pub active_deposit_details: HashMap, pub active_players_state: HashMap, pub active_players_block_data: HashMap, pub active_opow_block_data: HashMap, pub active_challenges_block_data: HashMap, pub active_challenges_prev_block_data: HashMap, pub active_algorithms_state: HashMap, pub active_algorithms_details: HashMap, pub active_algorithms_block_data: HashMap, pub voting_breakthroughs_state: HashMap, pub active_breakthroughs_state: HashMap, pub active_breakthroughs_details: HashMap, pub active_breakthroughs_block_data: HashMap, pub active_solutions: Vec<(BenchmarkSettings, u32, u32, u32)>, pub confirmed_num_solutions: HashMap, }