Skip to content

Commit 24e633f

Browse files
authored
Feat: improve init_account signature (#300)
* improve init_account signature * update changelog * simplify sig
1 parent d33737a commit 24e633f

File tree

11 files changed

+31
-28
lines changed

11 files changed

+31
-28
lines changed

CHANGELOG.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- Updated CLI template `increment_rs`: Changed authority validation to use `Authority` type wrapper instead of raw `Pubkey` in `IncrementAccounts` (#297)
1313
- Updated CLI template `states_rs`: Changed `AccountValidate` implementation for `CounterAccount` to use `Authority` type parameter instead of `&Pubkey`, and updated reference type from `Self::Ref<'_>` to `Self::Ptr` (#297)
14-
- Updated CLI template `initialize_rs`: Changed `Seeds` argument in `idl` macro to use `FindCounterAccountSeeds` instead of `FindCounterSeeds` (#297)
14+
- Updated CLI template `initialize_rs`: Changed `Seeds` argument in `idl` macro to use `FindCounterAccountSeeds` instead of `FindCounterSeeds` (#297)
15+
16+
### Changed
17+
18+
- Used `Option<&[&[u8]]>` instead of `Option<Vec<&[u8]>>` for `CanInitAccount::init_account` (#300)
1519
- CLI template: ensure crate name uses underscores in `cargo_toml`. Added `{name_lowercase_underscore}` placeholder and generator replacement to convert hyphens to underscores in generated project names. (#296)
1620

1721
## [0.27.0] - 2025-11-07
@@ -32,7 +36,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3236
### Fixed
3337

3438
- Fixed errors in cli template caused due to breaking changes made in star_frame (#283)
35-
3639
- Fixed errors in cli test template caused due to breaking changes made in star_frame (#284)
3740

3841
## [0.26.2] - 2025-10-15

star_frame/src/account_set/account.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ where
282282
fn init_account<const IF_NEEDED: bool>(
283283
&mut self,
284284
_arg: (),
285-
account_seeds: Option<Vec<&[u8]>>,
285+
account_seeds: Option<&[&[u8]]>,
286286
ctx: &Context,
287287
) -> Result<()> {
288288
self.init_account::<IF_NEEDED>(|| DefaultInit, account_seeds, ctx)
@@ -298,7 +298,7 @@ where
298298
fn init_account<const IF_NEEDED: bool>(
299299
&mut self,
300300
arg: (&Funder,),
301-
account_seeds: Option<Vec<&[u8]>>,
301+
account_seeds: Option<&[&[u8]]>,
302302
ctx: &Context,
303303
) -> Result<()> {
304304
self.init_account::<IF_NEEDED>((|| DefaultInit, arg.0), account_seeds, ctx)
@@ -315,7 +315,7 @@ where
315315
fn init_account<const IF_NEEDED: bool>(
316316
&mut self,
317317
arg: InitFn,
318-
account_seeds: Option<Vec<&[u8]>>,
318+
account_seeds: Option<&[&[u8]]>,
319319
ctx: &Context,
320320
) -> Result<()> {
321321
let funder = ctx.get_funder().ok_or_else(|| {
@@ -339,7 +339,7 @@ where
339339
fn init_account<const IF_NEEDED: bool>(
340340
&mut self,
341341
arg: (InitFn, &Funder),
342-
account_seeds: Option<Vec<&[u8]>>,
342+
account_seeds: Option<&[&[u8]]>,
343343
ctx: &Context,
344344
) -> Result<()> {
345345
if IF_NEEDED {
@@ -357,7 +357,7 @@ where
357357
funder,
358358
T::OwnerProgram::ID,
359359
<AccountDiscriminant<T>>::INIT_BYTES,
360-
&account_seeds,
360+
account_seeds,
361361
ctx,
362362
)
363363
.ctx("system_create_account failed")?;

star_frame/src/account_set/borsh_account.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ where
258258
fn init_account<const IF_NEEDED: bool>(
259259
&mut self,
260260
_arg: (),
261-
account_seeds: Option<Vec<&[u8]>>,
261+
account_seeds: Option<&[&[u8]]>,
262262
ctx: &Context,
263263
) -> Result<()> {
264264
self.init_account::<IF_NEEDED>(|| Default::default(), account_seeds, ctx)
@@ -274,7 +274,7 @@ where
274274
fn init_account<const IF_NEEDED: bool>(
275275
&mut self,
276276
arg: InitFn,
277-
account_seeds: Option<Vec<&[u8]>>,
277+
account_seeds: Option<&[&[u8]]>,
278278
ctx: &Context,
279279
) -> Result<()> {
280280
let funder = ctx.get_funder().ok_or_else(|| {
@@ -295,7 +295,7 @@ where
295295
fn init_account<const IF_NEEDED: bool>(
296296
&mut self,
297297
arg: (&Funder,),
298-
account_seeds: Option<Vec<&[u8]>>,
298+
account_seeds: Option<&[&[u8]]>,
299299
ctx: &Context,
300300
) -> Result<()> {
301301
self.init_account::<IF_NEEDED>((|| Default::default(), arg.0), account_seeds, ctx)
@@ -311,7 +311,7 @@ where
311311
fn init_account<const IF_NEEDED: bool>(
312312
&mut self,
313313
arg: (InitValue, &Funder),
314-
account_seeds: Option<Vec<&[u8]>>,
314+
account_seeds: Option<&[&[u8]]>,
315315
ctx: &Context,
316316
) -> Result<()> {
317317
if IF_NEEDED {
@@ -327,7 +327,7 @@ where
327327
let (init_value, funder) = arg;
328328
let data = init_value();
329329
let space = size_of::<OwnerProgramDiscriminant<T>>() + object_length(&data)?;
330-
self.system_create_account(funder, T::OwnerProgram::ID, space, &account_seeds, ctx)
330+
self.system_create_account(funder, T::OwnerProgram::ID, space, account_seeds, ctx)
331331
.ctx("system_create_account failed")?;
332332
self.account_data_mut()?[..size_of::<OwnerProgramDiscriminant<T>>()]
333333
.copy_from_slice(bytemuck::bytes_of(&T::DISCRIMINANT));

star_frame/src/account_set/impls/boxed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ where
157157
fn init_account<const IF_NEEDED: bool>(
158158
&mut self,
159159
arg: A,
160-
account_seeds: Option<Vec<&[u8]>>,
160+
account_seeds: Option<&[&[u8]]>,
161161
ctx: &Context,
162162
) -> Result<()> {
163163
T::init_account::<IF_NEEDED>(self, arg, account_seeds, ctx)

star_frame/src/account_set/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ pub trait CanSystemCreateAccount {
378378
funder: &(impl CanFundRent + ?Sized),
379379
owner: Pubkey,
380380
space: usize,
381-
account_seeds: &Option<Vec<&[u8]>>,
381+
account_seeds: Option<&[&[u8]]>,
382382
ctx: &Context,
383383
) -> Result<()>;
384384
}

star_frame/src/account_set/modifiers/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub trait CanInitAccount<A>: SingleAccountSet {
5252
fn init_account<const IF_NEEDED: bool>(
5353
&mut self,
5454
arg: A,
55-
account_seeds: Option<Vec<&[u8]>>,
55+
account_seeds: Option<&[&[u8]]>,
5656
ctx: &Context,
5757
) -> Result<()>;
5858
}

star_frame/src/account_set/modifiers/seeded.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ where
314314
fn init_account<const IF_NEEDED: bool>(
315315
&mut self,
316316
arg: A,
317-
account_seeds: Option<Vec<&[u8]>>,
317+
account_seeds: Option<&[&[u8]]>,
318318
ctx: &Context,
319319
) -> Result<()> {
320320
// override seeds. Init should be called after seeds are set
@@ -335,7 +335,7 @@ where
335335
)
336336
})?;
337337
self.account
338-
.init_account::<IF_NEEDED>(arg, Some(seeds), ctx)
338+
.init_account::<IF_NEEDED>(arg, Some(&seeds), ctx)
339339
}
340340
}
341341

star_frame/src/account_set/single_set.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ where
332332
funder: &(impl CanFundRent + ?Sized),
333333
owner: Pubkey,
334334
space: usize,
335-
account_seeds: &Option<Vec<&[u8]>>,
335+
account_seeds: Option<&[&[u8]]>,
336336
ctx: &Context,
337337
) -> Result<()> {
338338
let account = *self.account_info();

star_frame_proc/src/account_set/struct_impl/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ pub(super) fn derive_account_set_impl_struct(
369369
fn init_account<const #if_needed: bool>(
370370
&mut self,
371371
arg: #init_gen,
372-
account_seeds: Option<Vec<&[u8]>>,
372+
account_seeds: Option<&[&[u8]]>,
373373
ctx: &#prelude::Context,
374374
) -> #result<()> {
375375
<#field_ty as #prelude::CanInitAccount<#init_gen>>::init_account::<#if_needed>(&mut self.#field_name, arg, account_seeds, ctx)

star_frame_spl/src/associated_token.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ pub mod state {
341341
fn init_account<const IF_NEEDED: bool>(
342342
&mut self,
343343
arg: InitAta<'a, WalletInfo, MintInfo>,
344-
account_seeds: Option<Vec<&[u8]>>,
344+
account_seeds: Option<&[&[u8]]>,
345345
ctx: &Context,
346346
) -> Result<()> {
347347
let funder = ctx.get_funder().ok_or_else(|| {
@@ -364,7 +364,7 @@ pub mod state {
364364
fn init_account<const IF_NEEDED: bool>(
365365
&mut self,
366366
(init_ata, funder): (InitAta<'a, WalletInfo, MintInfo>, &Funder),
367-
account_seeds: Option<Vec<&[u8]>>,
367+
account_seeds: Option<&[&[u8]]>,
368368
ctx: &Context,
369369
) -> Result<()> {
370370
if IF_NEEDED && self.owner_pubkey() == Token::ID {

0 commit comments

Comments
 (0)