Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added argument checks - for better error display. #475

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions content/courses/onchain-development/anchor-pdas.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
Loading