Skip to content

Commit 7e0c3b1

Browse files
committed
update: migrate quasar programs to latest API
1 parent 4d2f313 commit 7e0c3b1

146 files changed

Lines changed: 3306 additions & 3188 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

basics/account-data/quasar/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ client = []
2222
debug = []
2323

2424
[dependencies]
25-
quasar-lang = "0.0"
25+
quasar-lang = { git = "https://github.com/blueshift-gg/quasar", branch = "master" }
2626
solana-instruction = { version = "3.2.0" }
2727

2828
[dev-dependencies]

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,29 @@ use {
77
/// Dynamic accounts use owned `Account<T>` rather than `&'info mut Account<T>` because
88
/// dynamic types carry cached byte offsets that cannot be represented as a pointer cast.
99
#[derive(Accounts)]
10-
pub struct CreateAddressInfo<'info> {
10+
pub struct CreateAddressInfo {
1111
#[account(mut)]
12-
pub payer: &'info mut Signer,
13-
#[account(mut, init, payer = payer, seeds = [b"address_info", payer], bump)]
14-
pub address_info: Account<AddressInfo<'info>>,
15-
pub system_program: &'info Program<System>,
12+
pub payer: Signer,
13+
#[account(mut, init, payer = payer, seeds = AddressInfo::seeds(payer), bump)]
14+
pub address_info: Account<AddressInfo<'_>>,
15+
pub system_program: Program<System>,
1616
}
1717

18-
#[inline(always)]
19-
pub fn handle_create_address_info(
20-
accounts: &mut CreateAddressInfo, name: &str,
21-
house_number: u8,
22-
street: &str,
23-
city: &str,
24-
) -> Result<(), ProgramError> {
25-
accounts.address_info.set_inner(
26-
house_number,
27-
name,
28-
street,
29-
city,
30-
accounts.payer.to_account_view(),
31-
None,
32-
)
18+
impl CreateAddressInfo {
19+
#[inline(always)]
20+
pub fn create_address_info(
21+
&mut self, name: &str,
22+
house_number: u8,
23+
street: &str,
24+
city: &str,
25+
) -> Result<(), ProgramError> {
26+
self.address_info.set_inner(
27+
house_number,
28+
name,
29+
street,
30+
city,
31+
self.payer.to_account_view(),
32+
None,
33+
)
34+
}
3335
}

basics/account-data/quasar/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(test), no_std)]
1+
#![no_std]
22

33
use quasar_lang::prelude::*;
44

@@ -30,6 +30,6 @@ mod quasar_account_data {
3030
street: String,
3131
city: String,
3232
) -> Result<(), ProgramError> {
33-
instructions::handle_create_address_info(&mut ctx.accounts, name, house_number, street, city)
33+
ctx.accounts.create_address_info(name, house_number, street, city)
3434
}
3535
}

basics/account-data/quasar/src/state.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use quasar_lang::prelude::*;
66
///
77
/// Note: Quasar requires all fixed-size fields to precede dynamic (String/Vec) fields.
88
#[account(discriminator = 1)]
9+
#[seeds(b"address_info", payer: Address)]
910
pub struct AddressInfo<'a> {
1011
pub house_number: u8,
1112
pub name: String<u8, 50>,

basics/checking-accounts/quasar/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ client = []
2222
debug = []
2323

2424
[dependencies]
25-
quasar-lang = "0.0"
25+
quasar-lang = { git = "https://github.com/blueshift-gg/quasar", branch = "master" }
2626
solana-instruction = { version = "3.2.0" }
2727

2828
[dev-dependencies]

basics/checking-accounts/quasar/src/instructions/check_accounts.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,24 @@ use quasar_lang::prelude::*;
88
/// Note: Anchor's `#[account(owner = id())]` owner constraint is not directly available
99
/// in Quasar. Owner checks can be done manually in the instruction body if needed.
1010
#[derive(Accounts)]
11-
pub struct CheckAccounts<'info> {
11+
pub struct CheckAccounts {
1212
/// Checks that this account signed the transaction.
13-
pub payer: &'info Signer,
13+
pub payer: Signer,
1414
/// No checks performed — the caller is responsible for validation.
1515
#[account(mut)]
16-
pub account_to_create: &'info mut UncheckedAccount,
16+
pub account_to_create: UncheckedAccount,
1717
/// No automatic owner check in Quasar; see note above.
1818
#[account(mut)]
19-
pub account_to_change: &'info mut UncheckedAccount,
19+
pub account_to_change: UncheckedAccount,
2020
/// Checks the account is executable and matches the system program address.
21-
pub system_program: &'info Program<System>,
21+
pub system_program: Program<System>,
2222
}
2323

24-
#[inline(always)]
25-
pub fn handle_check_accounts(accounts: &CheckAccounts) -> Result<(), ProgramError> {
26-
// All validation happens declaratively via the account types above.
27-
// If any check fails, the runtime rejects the transaction before this runs.
28-
Ok(())
24+
impl CheckAccounts {
25+
#[inline(always)]
26+
pub fn check_accounts(&mut self) -> Result<(), ProgramError> {
27+
// All validation happens declaratively via the account types above.
28+
// If any check fails, the runtime rejects the transaction before this runs.
29+
Ok(())
30+
}
2931
}

basics/checking-accounts/quasar/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![cfg_attr(not(test), no_std)]
1+
#![no_std]
22

33
use quasar_lang::prelude::*;
44

@@ -19,6 +19,6 @@ mod quasar_checking_accounts {
1919
/// - Program<System>: checks account is executable and is the system program
2020
#[instruction(discriminator = 0)]
2121
pub fn check_accounts(ctx: Ctx<CheckAccounts>) -> Result<(), ProgramError> {
22-
instructions::handle_check_accounts(&mut ctx.accounts)
22+
ctx.accounts.check_accounts()
2323
}
2424
}

basics/close-account/quasar/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ client = []
2020
debug = []
2121

2222
[dependencies]
23-
quasar-lang = "0.0"
23+
quasar-lang = { git = "https://github.com/blueshift-gg/quasar", branch = "master" }
2424
solana-instruction = { version = "3.2.0" }
2525

2626
[dev-dependencies]

basics/close-account/quasar/src/instructions/close_user.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,16 @@ use {
88
/// In Quasar, we call `close()` explicitly — it zeros the discriminator, drains lamports
99
/// to the destination, reassigns the owner to the system program, and resizes to 0.
1010
#[derive(Accounts)]
11-
pub struct CloseUser<'info> {
11+
pub struct CloseUser {
1212
#[account(mut)]
13-
pub user: &'info mut Signer,
13+
pub user: Signer,
1414
#[account(mut)]
15-
pub user_account: Account<UserState<'info>>,
15+
pub user_account: Account<UserState<'_>>,
1616
}
1717

18-
#[inline(always)]
19-
pub fn handle_close_user(accounts: &mut CloseUser) -> Result<(), ProgramError> {
20-
accounts.user_account.close(accounts.user.to_account_view())
18+
impl CloseUser {
19+
#[inline(always)]
20+
pub fn close_user(&mut self) -> Result<(), ProgramError> {
21+
self.user_account.close(self.user.to_account_view())
22+
}
2123
}

basics/close-account/quasar/src/instructions/create_user.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,24 @@ use {
55

66
/// Accounts for creating a new user.
77
#[derive(Accounts)]
8-
pub struct CreateUser<'info> {
8+
pub struct CreateUser {
99
#[account(mut)]
10-
pub user: &'info mut Signer,
11-
#[account(mut, init, payer = user, seeds = [b"USER", user], bump)]
12-
pub user_account: Account<UserState<'info>>,
13-
pub system_program: &'info Program<System>,
10+
pub user: Signer,
11+
#[account(mut, init, payer = user, seeds = UserState::seeds(user), bump)]
12+
pub user_account: Account<UserState<'_>>,
13+
pub system_program: Program<System>,
1414
}
1515

16-
#[inline(always)]
17-
pub fn handle_create_user(accounts: &mut CreateUser, name: &str, bump: u8) -> Result<(), ProgramError> {
18-
let user_address = *accounts.user.to_account_view().address();
19-
accounts.user_account.set_inner(
20-
bump,
21-
user_address,
22-
name,
23-
accounts.user.to_account_view(),
24-
None,
25-
)
16+
impl CreateUser {
17+
#[inline(always)]
18+
pub fn create_user(&mut self, name: &str, bump: u8) -> Result<(), ProgramError> {
19+
let user_address = *self.user.to_account_view().address();
20+
self.user_account.set_inner(
21+
bump,
22+
user_address,
23+
name,
24+
self.user.to_account_view(),
25+
None,
26+
)
27+
}
2628
}

0 commit comments

Comments
 (0)