Rise In Logo

Build on Solana

Review I - Implementing State

In this lesson, we will take a look at how we can define the the state of our project.

You can click here for Solana Playground.

Here is the changes we have made to state.rs in this video:

use borsh::{BorshDeserialize, BorshSerialize};
use solana_program::program_error::ProgramError;
use solana_program::program_pack::{IsInitialized, Sealed};
use thiserror::Error;

#[derive(BorshSerialize, BorshDeserialize)]
pub struct AccountState {
    pub is_initialized: bool,
    pub rating: u8,
    pub description: String,
    pub title: String,

impl Sealed for AccountState {}

impl IsInitialized for AccountState {
    fn is_initialized(&self) -> bool {

#[derive(Debug, Error)]
pub enum ReviewError {
    #[error("Account not initialized yet")]

    #[error("PDA derived does not equal PDA passed in")]

    #[error("Rating greater than 10 or less than 1")]

impl From<ReviewError> for ProgramError {
    fn from(e: ReviewError) -> Self {
        ProgramError::Custom(e as u32)
Rise In Logo

Rise together in web3