Skip to content

Commit ddea756

Browse files
author
Edward (Mike's bot)
committed
fix(cpi/lever): migrate to current Quasar API
WHAT: Update the lever program (basics/cross-program-invocation/quasar/lever) to compile against the current quasar-lang and quasar-spl APIs: - Drop `<'info>` lifetime parameters from account context structs - Replace `&'info mut Signer` / `&'info mut Account<...>` / `&'info Program<...>` reference fields with their owned counterparts (`Signer`, `Account<...>`, `Program<...>`) - Move PDA seed declaration onto the state struct via `#[seeds(b"power")]` and reference it as `seeds = PowerStatus::seeds()` in the accounts derive - Mark `PowerStatus` with `set_inner` and call `set_inner(PowerStatusInner { .. })` from the initialize handler (matches the counter pattern for fixed-size Pod accounts) - Bind the `name` instruction arg to `String<50>` (Quasar's PodString needs a capacity generic; plain `String` no longer compiles) WHY: cursor[bot] flagged the lever crate as still using the pre-migration Quasar API even after PR #8 updated lever's Cargo.toml. The crate is excluded from CI via .ghaignore (the workflow expects a root Quasar.toml per project but cross-program-invocation/quasar uses hand/ + lever/ subdirectories), so the breakage was masked. Verified locally: `quasar build && cargo test --release` passes for both lever (4 tests) and hand (3 tests). Addresses cursor[bot] comment #8 on PR #8 (discussion_r3157509603).
1 parent 37bc808 commit ddea756

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use {
2-
crate::state::PowerStatus,
2+
crate::state::{PowerStatus, PowerStatusInner},
33
quasar_lang::prelude::*,
44
};
55

66
/// Accounts for initialising the power status (PDA seeded by "power").
77
#[derive(Accounts)]
8-
pub struct InitializeLever<'info> {
8+
pub struct InitializeLever {
99
#[account(mut)]
10-
pub payer: &'info mut Signer,
11-
#[account(mut, init, payer = payer, seeds = [b"power"], bump)]
12-
pub power: &'info mut Account<PowerStatus>,
13-
pub system_program: &'info Program<System>,
10+
pub payer: Signer,
11+
#[account(mut, init, payer = payer, seeds = PowerStatus::seeds(), bump)]
12+
pub power: Account<PowerStatus>,
13+
pub system_program: Program<System>,
1414
}
1515

1616
#[inline(always)]
1717
pub fn handle_initialize(accounts: &mut InitializeLever) -> Result<(), ProgramError> {
18-
// Power starts off (false).
19-
accounts.power.set_inner(PodBool::from(false));
18+
// Power starts off (false). Counter-style fixed-size set_inner takes only the inner value.
19+
accounts.power.set_inner(PowerStatusInner { is_on: PodBool::from(false) });
2020
Ok(())
2121
}

basics/cross-program-invocation/quasar/lever/src/instructions/switch_power.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use {
55

66
/// Accounts for toggling the power switch.
77
#[derive(Accounts)]
8-
pub struct SwitchPower<'info> {
8+
pub struct SwitchPower {
99
#[account(mut)]
10-
pub power: &'info mut Account<PowerStatus>,
10+
pub power: Account<PowerStatus>,
1111
}
1212

1313
#[inline(always)]

basics/cross-program-invocation/quasar/lever/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ mod quasar_lever {
2222

2323
/// Toggle the power switch. Logs who is pulling the lever.
2424
#[instruction(discriminator = 1)]
25-
pub fn switch_power(ctx: Ctx<SwitchPower>, name: String) -> Result<(), ProgramError> {
25+
pub fn switch_power(ctx: Ctx<SwitchPower>, name: String<50>) -> Result<(), ProgramError> {
2626
instructions::handle_switch_power(&mut ctx.accounts, name)
2727
}
2828
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
use quasar_lang::prelude::*;
22

33
/// Onchain power status: a single boolean toggle.
4-
#[account(discriminator = 1)]
4+
/// Derived as a PDA from the seed "power" (single global account).
5+
#[account(discriminator = 1, set_inner)]
6+
#[seeds(b"power")]
57
pub struct PowerStatus {
68
pub is_on: PodBool,
79
}

0 commit comments

Comments
 (0)