From d5791dedd39eb1b434c90518192e70cf7f58c621 Mon Sep 17 00:00:00 2001 From: mikemaccana-edwardbot Date: Thu, 14 May 2026 22:13:24 +0000 Subject: [PATCH] chore(close-account): rename UserState to User Applies the repo-wide convention that state structs do not carry the 'State' suffix. The struct is the data; 'state' is implicit in being an on-chain account (compare: Offer, not OfferState; Counter, not CounterState). Affected: - Anchor: programs/close-account/src/state/user_state.rs renamed to state/user.rs; pub struct UserState -> pub struct User; module pub mod user_state; -> pub mod user;. All callers updated. - Quasar: src/state.rs pub struct UserState -> pub struct User; the set_inner-generated UserStateInner becomes UserInner. All callers updated. - basics/close-account/anchor/README.md updated to match. Not changed: - state.rs / state/ module and directory names keep their names. The 'state' module is a fine container for state types; only the *struct* names are being renamed. Verification: cargo check clean on both basics/close-account/anchor and basics/close-account/quasar. --- basics/close-account/anchor/README.md | 8 ++++---- .../programs/close-account/src/instructions/close_user.rs | 2 +- .../close-account/src/instructions/create_user.rs | 6 +++--- .../anchor/programs/close-account/src/state/mod.rs | 4 ++-- .../close-account/src/state/{user_state.rs => user.rs} | 2 +- .../close-account/quasar/src/instructions/close_user.rs | 4 ++-- .../close-account/quasar/src/instructions/create_user.rs | 8 ++++---- basics/close-account/quasar/src/state.rs | 2 +- 8 files changed, 18 insertions(+), 18 deletions(-) rename basics/close-account/anchor/programs/close-account/src/state/{user_state.rs => user.rs} (92%) diff --git a/basics/close-account/anchor/README.md b/basics/close-account/anchor/README.md index 030e494aa..8d9c5ed15 100644 --- a/basics/close-account/anchor/README.md +++ b/basics/close-account/anchor/README.md @@ -1,6 +1,6 @@ # Close Account -Two instruction handlers: `create_user` initializes a PDA `UserState` account, and `close_user` closes it and returns the rent to the user. +Two instruction handlers: `create_user` initializes a PDA `User` account, and `close_user` closes it and returns the rent to the user. 1. `create_user` initializes the PDA with Anchor's `init` constraint: @@ -8,11 +8,11 @@ Two instruction handlers: `create_user` initializes a PDA `UserState` account, a #[account( init, payer = user, - space = UserState::DISCRIMINATOR.len() + UserState::INIT_SPACE, + space = User::DISCRIMINATOR.len() + User::INIT_SPACE, seeds = [b"USER", user.key().as_ref()], bump, )] - pub user_account: Account<'info, UserState>, + pub user_account: Account<'info, User>, ``` See [`programs/close-account/src/instructions/create_user.rs`](programs/close-account/src/instructions/create_user.rs). @@ -26,7 +26,7 @@ Two instruction handlers: `create_user` initializes a PDA `UserState` account, a bump = user_account.bump, close = user, // close account and return lamports to user )] - pub user_account: Account<'info, UserState>, + pub user_account: Account<'info, User>, ``` See [`programs/close-account/src/instructions/close_user.rs`](programs/close-account/src/instructions/close_user.rs). diff --git a/basics/close-account/anchor/programs/close-account/src/instructions/close_user.rs b/basics/close-account/anchor/programs/close-account/src/instructions/close_user.rs index 449a6f778..978cfe24d 100644 --- a/basics/close-account/anchor/programs/close-account/src/instructions/close_user.rs +++ b/basics/close-account/anchor/programs/close-account/src/instructions/close_user.rs @@ -15,7 +15,7 @@ pub struct CloseUserContext<'info> { bump = user_account.bump, close = user, // close account and return lamports to user )] - pub user_account: Account<'info, UserState>, + pub user_account: Account<'info, User>, } pub fn handle_close_user(_context: Context) -> Result<()> { diff --git a/basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs b/basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs index 3aec5995b..6e54fb96a 100644 --- a/basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs +++ b/basics/close-account/anchor/programs/close-account/src/instructions/create_user.rs @@ -9,19 +9,19 @@ pub struct CreateUserContext<'info> { #[account( init, payer = user, - space = UserState::DISCRIMINATOR.len() + UserState::INIT_SPACE, + space = User::DISCRIMINATOR.len() + User::INIT_SPACE, seeds = [ b"USER", user.key().as_ref(), ], bump )] - pub user_account: Account<'info, UserState>, + pub user_account: Account<'info, User>, pub system_program: Program<'info, System>, } pub fn handle_create_user(context: Context, name: String) -> Result<()> { - *context.accounts.user_account = UserState { + *context.accounts.user_account = User { bump: context.bumps.user_account, user: context.accounts.user.key(), name, diff --git a/basics/close-account/anchor/programs/close-account/src/state/mod.rs b/basics/close-account/anchor/programs/close-account/src/state/mod.rs index 679cefb17..82a8f00c6 100644 --- a/basics/close-account/anchor/programs/close-account/src/state/mod.rs +++ b/basics/close-account/anchor/programs/close-account/src/state/mod.rs @@ -1,2 +1,2 @@ -pub mod user_state; -pub use user_state::*; +pub mod user; +pub use user::*; diff --git a/basics/close-account/anchor/programs/close-account/src/state/user_state.rs b/basics/close-account/anchor/programs/close-account/src/state/user.rs similarity index 92% rename from basics/close-account/anchor/programs/close-account/src/state/user_state.rs rename to basics/close-account/anchor/programs/close-account/src/state/user.rs index d9fba3218..6548d53dc 100644 --- a/basics/close-account/anchor/programs/close-account/src/state/user_state.rs +++ b/basics/close-account/anchor/programs/close-account/src/state/user.rs @@ -2,7 +2,7 @@ use anchor_lang::prelude::*; #[account] #[derive(InitSpace)] // automatically calculate the space required for the struct -pub struct UserState { +pub struct User { pub bump: u8, // 1 byte pub user: Pubkey, // 32 bytes #[max_len(50)] // set a max length for the string diff --git a/basics/close-account/quasar/src/instructions/close_user.rs b/basics/close-account/quasar/src/instructions/close_user.rs index 98f694f8a..6fdfe4902 100644 --- a/basics/close-account/quasar/src/instructions/close_user.rs +++ b/basics/close-account/quasar/src/instructions/close_user.rs @@ -1,4 +1,4 @@ -use {crate::state::UserState, quasar_lang::prelude::*}; +use {crate::state::User, quasar_lang::prelude::*}; /// Accounts for closing a user account. /// The `close(dest = user)` attribute mirrors Anchor's `close = user`: at the @@ -9,7 +9,7 @@ pub struct CloseUser { #[account(mut)] pub user: Signer, #[account(mut, close(dest = user))] - pub user_account: Account, + pub user_account: Account, } #[inline(always)] diff --git a/basics/close-account/quasar/src/instructions/create_user.rs b/basics/close-account/quasar/src/instructions/create_user.rs index 9a0a16ef6..94c131c8b 100644 --- a/basics/close-account/quasar/src/instructions/create_user.rs +++ b/basics/close-account/quasar/src/instructions/create_user.rs @@ -1,5 +1,5 @@ use { - crate::state::{UserState, UserStateInner}, + crate::state::{User, UserInner}, quasar_lang::{prelude::*, sysvars::Sysvar}, }; @@ -8,8 +8,8 @@ use { pub struct CreateUser { #[account(mut)] pub user: Signer, - #[account(mut, init, payer = user, address = UserState::seeds(user.address()))] - pub user_account: Account, + #[account(mut, init, payer = user, address = User::seeds(user.address()))] + pub user_account: Account, pub system_program: Program, } @@ -22,7 +22,7 @@ pub fn handle_create_user( let user_address = *accounts.user.to_account_view().address(); let rent = Rent::get()?; accounts.user_account.set_inner( - UserStateInner { bump, user: user_address, name }, + UserInner { bump, user: user_address, name }, accounts.user.to_account_view(), rent.lamports_per_byte(), rent.exemption_threshold_raw(), diff --git a/basics/close-account/quasar/src/state.rs b/basics/close-account/quasar/src/state.rs index 6e3c71590..1735f5a33 100644 --- a/basics/close-account/quasar/src/state.rs +++ b/basics/close-account/quasar/src/state.rs @@ -4,7 +4,7 @@ use quasar_lang::prelude::*; /// Fixed fields (bump, user) must precede dynamic fields (name). #[account(discriminator = 1, set_inner)] #[seeds(b"USER", user: Address)] -pub struct UserState { +pub struct User { pub bump: u8, pub user: Address, pub name: String<50>,