Skip to main content

chain_id/
lib.rs

1#![allow(unexpected_cfgs)] // warning: unexpected `cfg` condition value: `anchor-debug`
2
3use anchor_lang::prelude::*;
4
5declare_id!("Cha1RcWkdcF1dmGuTui53JmSnVCacCc2Kx2SY7zSFhaN");
6
7pub const SEED: &[u8] = b"chain_id";
8
9#[program]
10pub mod chain_id {
11    use super::*;
12    pub fn set<'info>(ctx: Context<'_, '_, '_, 'info, Set<'info>>, chain_id: String) -> Result<()> {
13        ctx.accounts
14            .chain_id_account
15            .set_inner(ChainId { chain_id });
16        Ok(())
17    }
18}
19
20#[derive(Accounts)]
21#[instruction(chain_id: String)]
22pub struct Set<'info> {
23    #[account(mut)]
24    pub sponsor: Signer<'info>,
25    #[account(init, payer = sponsor, seeds = [SEED], bump, space = 8 + 4 + chain_id.len())]
26    pub chain_id_account: Account<'info, ChainId>,
27    pub system_program: Program<'info, System>,
28}
29
30#[account]
31pub struct ChainId {
32    pub chain_id: String,
33}