Created
October 31, 2021 05:44
-
-
Save farzaa/7d6269db57044a3b85aba04535709b66 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use anchor_lang::prelude::*; | |
declare_id!("3qTa9cUAzWf1TMaDQx8UESjUMGJEiaCmpDBuBpVbqRDD"); | |
#[program] | |
mod mysolanaapp { | |
use super::*; | |
pub fn create(ctx: Context<Create>) -> ProgramResult { | |
let base_account = &mut ctx.accounts.base_account; | |
base_account.count = 0; | |
Ok(()) | |
} | |
pub fn increment(ctx: Context<Increment>) -> ProgramResult { | |
let base_account = &mut ctx.accounts.base_account; | |
base_account.count += 1; | |
let cs = CustomStruct { | |
num: 0, | |
name: String::from("farza"), | |
}; | |
base_account.data_list.push(cs); | |
Ok(()) | |
} | |
} | |
// Transaction instructions | |
#[derive(Accounts)] | |
pub struct Create<'info> { | |
#[account(init, payer = user, space = 16 + 16)] | |
pub base_account: Account<'info, BaseAccount>, | |
#[account(mut)] | |
pub user: Signer<'info>, | |
pub system_program: Program <'info, System>, | |
} | |
// Transaction instructions | |
#[derive(Accounts)] | |
pub struct Increment<'info> { | |
#[account(mut)] | |
pub base_account: Account<'info, BaseAccount>, | |
} | |
#[derive(Debug, Clone, AnchorSerialize, AnchorDeserialize)] | |
pub struct CustomStruct { | |
pub num: u64, | |
pub name: String, | |
} | |
#[account] | |
pub struct BaseAccount { | |
pub count: u64, | |
pub data_list: Vec<CustomStruct>, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment