diff --git a/tig-protocol/src/submit_algorithm.rs b/tig-protocol/src/submit_algorithm.rs index 1f9576d3..f4f6be2f 100644 --- a/tig-protocol/src/submit_algorithm.rs +++ b/tig-protocol/src/submit_algorithm.rs @@ -10,6 +10,7 @@ pub(crate) async fn execute( details: &AlgorithmDetails, code: &String, ) -> ProtocolResult { + verify_challenge_exists(ctx, details).await?; verify_algorithm_name_is_unique(ctx, details).await?; verify_submission_fee(ctx, player, details).await?; let algorithm_id = ctx @@ -19,6 +20,23 @@ pub(crate) async fn execute( Ok(algorithm_id) } +async fn verify_challenge_exists( + ctx: &mut T, + details: &AlgorithmDetails, +) -> ProtocolResult<()> { + if ctx + .get_challenges(ChallengesFilter::Id(details.challenge_id.clone()), None) + .await + .unwrap_or_else(|e| panic!("get_challenges error: {:?}", e)) + .is_empty() + { + return Err(ProtocolError::InvalidChallenge { + challenge_id: details.challenge_id.clone(), + }); + } + Ok(()) +} + async fn verify_algorithm_name_is_unique( ctx: &mut T, details: &AlgorithmDetails,