Skip to content

Commit af10959

Browse files
committed
fix
1 parent be261cf commit af10959

3 files changed

Lines changed: 9 additions & 24 deletions

File tree

basics/create-account/quasar/src/instructions/create_system_account.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,5 @@ pub fn handle_create_system_account(
2727
&system_program_address,
2828
None, // fetch Rent sysvar automatically
2929
)?
30-
.invoke()
30+
.invoke();
3131
}
Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,14 @@
1-
use quasar_lang::{
2-
cpi::{BufCpiCall, InstructionAccount},
3-
prelude::*,
4-
};
1+
use quasar_lang::prelude::*;
52

63
/// Accounts for the hand program's pull_lever instruction.
74
/// The lever_program uses `Program<LeverProgram>` with a custom marker type
85
/// that implements `Id` — this lets Quasar verify the program address and
96
/// the executable flag during account parsing.
107
#[derive(Accounts)]
11-
pub struct PullLever<'info> {
8+
pub struct PullLever {
129
#[account(mut)]
13-
pub power: &'info UncheckedAccount,
14-
pub lever_program: &'info Program<crate::LeverProgram>,
10+
pub power: UncheckedAccount,
11+
pub lever_program: Program<crate::LeverProgram>,
1512
}
1613

1714
#[inline(always)]
@@ -25,34 +22,22 @@ pub fn handle_pull_lever(accounts: &PullLever, name: &str) -> Result<(), Program
2522
let name_bytes = name.as_bytes();
2623
let data_len = 1 + 4 + name_bytes.len();
2724

28-
// Discriminator = 1 (switch_power)
2925
data[0] = 1;
3026

31-
// Name string: u32 little-endian length prefix + bytes
3227
let len_bytes = (name_bytes.len() as u32).to_le_bytes();
3328
data[1] = len_bytes[0];
3429
data[2] = len_bytes[1];
3530
data[3] = len_bytes[2];
3631
data[4] = len_bytes[3];
3732

38-
// Copy name bytes
3933
let mut i = 0;
4034
while i < name_bytes.len() {
4135
data[5 + i] = name_bytes[i];
4236
i += 1;
4337
}
4438

45-
let power_view = accounts.power.to_account_view();
46-
let lever_view = accounts.lever_program.to_account_view();
47-
48-
// Build CPI call with 1 account (power, writable, not a signer).
49-
let cpi = BufCpiCall::<1, 128>::new(
50-
lever_view.address(),
51-
[InstructionAccount::writable(power_view.address())],
52-
[power_view],
53-
data,
54-
data_len,
55-
);
56-
39+
let mut cpi = DynCpiCall::<1, 128>::new(accounts.lever_program.address());
40+
cpi.push_account(accounts.power.to_account_view(), false, true)?;
41+
cpi.set_data(&data[..data_len])?;
5742
cpi.invoke()
5843
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ mod quasar_hand {
2626

2727
/// Pull the lever by invoking the lever program's switch_power via CPI.
2828
#[instruction(discriminator = 0)]
29-
pub fn pull_lever(ctx: Ctx<PullLever>, name: String) -> Result<(), ProgramError> {
29+
pub fn pull_lever(ctx: Ctx<PullLever>, name: String<50>) -> Result<(), ProgramError> {
3030
instructions::handle_pull_lever(&mut ctx.accounts, name)
3131
}
3232
}

0 commit comments

Comments
 (0)