lib.rs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. use anchor_spl::metadata::Metadata;
  2. use bolt_lang::*;
  3. use position::Position;
  4. use velocity::Velocity;
  5. declare_id!("6LHhFVwif6N9Po3jHtSmMVtPjF6zRfL3xMosSzcrQAS8");
  6. #[system]
  7. pub mod system_apply_velocity {
  8. pub fn execute(ctx: Context<Components>, _args: Vec<u8>) -> Result<Components> {
  9. ctx.accounts.velocity.x = 10;
  10. let mut clock = Clock::get()?;
  11. if let Ok(clock_account_info) = ctx.sysvar_clock() {
  12. clock = Clock::from_account_info(clock_account_info)?;
  13. ctx.accounts.position.z = 300;
  14. }
  15. ctx.accounts.velocity.last_applied = clock.unix_timestamp;
  16. ctx.accounts.position.x += 10 * (ctx.accounts.velocity.x + 2) + 3;
  17. msg!("last applied: {}", ctx.accounts.velocity.last_applied);
  18. msg!("Position: {}", ctx.accounts.position.x);
  19. msg!("Remaining accounts len: {}", ctx.remaining_accounts.len());
  20. msg!("Remaining accounts: {:?}", ctx.remaining_accounts);
  21. msg!("Authority: {}", ctx.accounts.authority.key);
  22. Ok(ctx.accounts)
  23. }
  24. #[system_input]
  25. pub struct Components {
  26. pub velocity: Velocity,
  27. pub position: Position,
  28. }
  29. #[extra_accounts]
  30. pub struct ExtraAccounts {
  31. #[account(address = bolt_lang::solana_program::sysvar::clock::id())]
  32. pub sysvar_clock: AccountInfo,
  33. #[account(address = pubkey!("tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD"))]
  34. pub some_extra_account: AccountInfo,
  35. #[account(address = Metadata::id())]
  36. pub program_metadata: Program<Metadata>,
  37. }
  38. }