anchor/examples/misc/programs/misc/src/lib.rs

55 lines
1.1 KiB
Rust

//! Misc example is a catchall program for testing unrelated features.
//! It's not too instructive/coherent by itself, so please see other examples.
use anchor_lang::prelude::*;
#[program]
pub mod misc {
use super::*;
pub const SIZE: u64 = 99;
#[state(SIZE)]
pub struct MyState {
pub v: Vec<u8>,
}
impl MyState {
pub fn new(_ctx: Context<Ctor>) -> Result<Self, ProgramError> {
Ok(Self { v: vec![] })
}
}
pub fn initialize(ctx: Context<Initialize>, udata: u128, idata: i128) -> ProgramResult {
ctx.accounts.data.udata = udata;
ctx.accounts.data.idata = idata;
Ok(())
}
pub fn test_executable(ctx: Context<TestExecutable>) -> ProgramResult {
Ok(())
}
}
#[derive(Accounts)]
pub struct Ctor {}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init)]
data: ProgramAccount<'info, Data>,
rent: Sysvar<'info, Rent>,
}
#[derive(Accounts)]
pub struct TestExecutable<'info> {
#[account(executable)]
program: AccountInfo<'info>,
}
#[account]
pub struct Data {
udata: u128,
idata: i128,
}