Skip to content

Instantly share code, notes, and snippets.

@elmariachi111
Last active August 9, 2024 13:24
Show Gist options
  • Save elmariachi111/3d14ce426f6d765cf439f97a4993fe7a to your computer and use it in GitHub Desktop.
Save elmariachi111/3d14ce426f6d765cf439f97a4993fe7a to your computer and use it in GitHub Desktop.
The simplest storage based Solana program thinkable.
use anchor_lang::prelude::*;
use std::mem::size_of;
// This is your program's public key and it will update
// automatically when you build the project.
declare_id!("3Z9mz1eE38sQ5SFMrvnQpxGcrvuTfwy9wu578pto35oV");
#[program]
mod catalyst {
use super::*;
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {
Ok(())
}
pub fn set_x(ctx: Context<Set>, new_x: u64) -> Result<()> {
msg!("Changed data to: {}!", new_x); // Message will show up in the tx logs
ctx.accounts.catalyst_storage.x = new_x;
Ok(())
}
//pub fn spawn(ctx: Context<Catalyst>, )
}
#[derive(Accounts)]
pub struct Initialize<'info> {
#[account(init,
payer = signer,
space = size_of::<CatalystStorage>() + 8)]
pub catalyst_storage: Account<'info, CatalystStorage>,
#[account(mut)]
pub signer: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Set<'info> {
#[account(mut)]
pub catalyst_storage: Account<'info, CatalystStorage>,
}
#[account]
pub struct CatalystStorage {
x: u64,
}
contract SomeStore {
struct CatalystStorage {
uint64 x;
}
CatalystStorage public stg;
constructor() {
stg = CatalystStorage({x: 0});
}
function setX(uint64 newX) {
stg.x = newX;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment