From df6bd03169442180a401b88afd5657219c931541 Mon Sep 17 00:00:00 2001 From: mercy-wumi Date: Thu, 12 Sep 2024 12:16:58 +0100 Subject: [PATCH 1/3] Added argument checks - for better error display. --- .../courses/onchain-development/anchor-pdas.md | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/content/courses/onchain-development/anchor-pdas.md b/content/courses/onchain-development/anchor-pdas.md index a20e1e8ed..3e4a82d18 100644 --- a/content/courses/onchain-development/anchor-pdas.md +++ b/content/courses/onchain-development/anchor-pdas.md @@ -544,7 +544,7 @@ pub mod anchor_movie_review_program{ description: String, rating: u8, ) -> Result<()> { - // We require that the rating is between 1 and 5 + // We require that the rating is between 1 and 5 require!(rating >= MIN_RATING && rating <= MAX_RATING, MovieReviewError::InvalidRating); // We require that the title is not longer than 20 characters @@ -592,7 +592,7 @@ public key, and the movie review's rating, title, and description. ```rust #[derive(Accounts)] -#[instruction(title:String, description:String)] +#[instruction(title:String)] pub struct AddMovieReview<'info> { #[account( init, @@ -639,6 +639,16 @@ pub mod anchor_movie_review_program { description: String, rating: u8, ) -> Result<()> { + + // We require that the rating is between 1 and 5 + require!(rating >= MIN_RATING && rating <= MAX_RATING, MovieReviewError::InvalidRating); + + // We require that the title is not longer than 20 characters + require!(title.len() <= MAX_TITLE_LENGTH, MovieReviewError::TitleTooLong); + + // We require that the description is not longer than 50 characters + require!(description.len() <= MAX_DESCRIPTION_LENGTH, MovieReviewError::DescriptionTooLong); + msg!("Movie review account space reallocated"); msg!("Title: {}", title); msg!("Description: {}", description); @@ -668,7 +678,7 @@ We'll also still need the `seeds` and `bump` constraints as we had them in ```rust #[derive(Accounts)] -#[instruction(title:String, description:String)] +#[instruction(title:String)] pub struct UpdateMovieReview<'info> { #[account( mut, From 2c5ae7d61b6d6e9aac65d802c7ae84316f275e52 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Mon, 7 Oct 2024 14:13:48 +1100 Subject: [PATCH 2/3] Update content/courses/onchain-development/anchor-pdas.md --- content/courses/onchain-development/anchor-pdas.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/onchain-development/anchor-pdas.md b/content/courses/onchain-development/anchor-pdas.md index 3e4a82d18..d73086137 100644 --- a/content/courses/onchain-development/anchor-pdas.md +++ b/content/courses/onchain-development/anchor-pdas.md @@ -544,7 +544,7 @@ pub mod anchor_movie_review_program{ description: String, rating: u8, ) -> Result<()> { - // We require that the rating is between 1 and 5 + // We require that the rating is between 1 and 5 require!(rating >= MIN_RATING && rating <= MAX_RATING, MovieReviewError::InvalidRating); // We require that the title is not longer than 20 characters From 896642aa47b674c4941ceb7ba4317664e2aa1e06 Mon Sep 17 00:00:00 2001 From: Mike MacCana Date: Mon, 7 Oct 2024 14:15:16 +1100 Subject: [PATCH 3/3] Update content/courses/onchain-development/anchor-pdas.md --- content/courses/onchain-development/anchor-pdas.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/content/courses/onchain-development/anchor-pdas.md b/content/courses/onchain-development/anchor-pdas.md index d73086137..64c3bb1e3 100644 --- a/content/courses/onchain-development/anchor-pdas.md +++ b/content/courses/onchain-development/anchor-pdas.md @@ -544,7 +544,7 @@ pub mod anchor_movie_review_program{ description: String, rating: u8, ) -> Result<()> { - // We require that the rating is between 1 and 5 + // We require that the rating is between 1 and 5 require!(rating >= MIN_RATING && rating <= MAX_RATING, MovieReviewError::InvalidRating); // We require that the title is not longer than 20 characters