forked from coral-xyz/anchor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.rs
51 lines (40 loc) · 1.24 KB
/
lib.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use anchor_lang::prelude::*;
declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
#[program]
pub mod floats {
use super::*;
pub fn create(ctx: Context<Create>, data_f32: f32, data_f64: f64) -> ProgramResult {
let account = &mut ctx.accounts.account;
let authority = &mut ctx.accounts.authority;
account.data_f32 = data_f32;
account.data_f64 = data_f64;
account.authority = authority.key();
Ok(())
}
pub fn update(ctx: Context<Update>, data_f32: f32, data_f64: f64) -> ProgramResult {
let account = &mut ctx.accounts.account;
account.data_f32 = data_f32;
account.data_f64 = data_f64;
Ok(())
}
}
#[derive(Accounts)]
pub struct Create<'info> {
#[account(init, payer = authority, space = 8 + 8 + 4 + 32)]
pub account: Account<'info, FloatDataAccount>,
#[account(mut)]
pub authority: Signer<'info>,
pub system_program: Program<'info, System>,
}
#[derive(Accounts)]
pub struct Update<'info> {
#[account(mut, has_one = authority)]
pub account: Account<'info, FloatDataAccount>,
pub authority: Signer<'info>,
}
#[account]
pub struct FloatDataAccount {
pub data_f64: f64,
pub data_f32: f32,
pub authority: Pubkey,
}