lib.rs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. use anchor_lang::prelude::*;
  2. declare_id!("Fg6PaFpoGXkYsidMpWTK6W2BeZ7FEfcYkg476zPFsLnS");
  3. #[program]
  4. pub mod account_command {
  5. use super::*;
  6. pub fn initialize(
  7. ctx: Context<Initialize>,
  8. balance: f32,
  9. amount: u32,
  10. memo: String,
  11. values: Vec<u128>,
  12. ) -> Result<()> {
  13. let my_account = &mut ctx.accounts.my_account;
  14. my_account.balance = balance;
  15. my_account.delegate_pubkey = ctx.accounts.user.key().clone();
  16. my_account.sub = Sub {
  17. values,
  18. state: State::Confirmed { amount, memo },
  19. };
  20. Ok(())
  21. }
  22. }
  23. #[derive(Clone, AnchorDeserialize, AnchorSerialize)]
  24. pub enum State {
  25. Pending,
  26. Confirmed { amount: u32, memo: String },
  27. }
  28. #[derive(Clone, AnchorDeserialize, AnchorSerialize)]
  29. pub struct Sub {
  30. pub values: Vec<u128>,
  31. pub state: State,
  32. }
  33. #[account]
  34. pub struct MyAccount {
  35. pub balance: f32,
  36. pub delegate_pubkey: Pubkey,
  37. pub sub: Sub,
  38. }
  39. #[derive(Accounts)]
  40. pub struct Initialize<'info> {
  41. #[account(init, payer = user, space = 8 + 1000)]
  42. pub my_account: Account<'info, MyAccount>,
  43. #[account(mut)]
  44. pub user: Signer<'info>,
  45. pub system_program: Program<'info, System>,
  46. }