Skip to content

Commit 20f7ffa

Browse files
committed
🐛 Enforce systems approval in macro expansion
1 parent 3fc9ab9 commit 20f7ffa

File tree

2 files changed

+13
-2
lines changed
  • crates/bolt-helpers/attribute/world-apply/src
  • examples/system-apply-velocity/src

2 files changed

+13
-2
lines changed

crates/bolt-helpers/attribute/world-apply/src/lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,16 @@ pub fn apply_system(attr: TokenStream, item: TokenStream) -> TokenStream {
4343
if !ctx.accounts.authority.is_signer && ctx.accounts.authority.key != &ID {
4444
return Err(WorldError::InvalidAuthority.into());
4545
}
46+
if !ctx.accounts.world.permissionless
47+
&& !ctx
48+
.accounts
49+
.world
50+
.systems()
51+
.approved_systems
52+
.contains(&ctx.accounts.bolt_system.key())
53+
{
54+
return Err(WorldError::SystemNotApproved.into());
55+
}
4656
let remaining_accounts: Vec<AccountInfo<'info>> = ctx.remaining_accounts.to_vec();
4757
let res = bolt_system::cpi::#execute_func_name(
4858
ctx.accounts

examples/system-apply-velocity/src/lib.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ pub mod system_apply_velocity {
1919
ctx.accounts.position.x += 10 * (ctx.accounts.velocity.x + 2) + 3;
2020
msg!("last applied: {}", ctx.accounts.velocity.last_applied);
2121
msg!("Position: {}", ctx.accounts.position.x);
22-
msg!("Remaining accounts: {}", ctx.remaining_accounts.len());
22+
msg!("Remaining accounts len: {}", ctx.remaining_accounts.len());
23+
msg!("Remaining accounts: {:?}", ctx.remaining_accounts);
2324
msg!("Authority: {}", ctx.accounts.authority.key);
2425
Ok(ctx.accounts)
2526
}
@@ -34,7 +35,7 @@ pub mod system_apply_velocity {
3435
pub struct ExtraAccounts {
3536
#[account(address = bolt_lang::solana_program::sysvar::clock::id())]
3637
pub sysvar_clock: AccountInfo,
37-
#[account(address = pubkey!("6LHhFVwif6N9Po3jHtSmMVtPjF6zRfL3xMosSzcrQAS8"))]
38+
#[account(address = pubkey!("tEsT3eV6RFCWs1BZ7AXTzasHqTtMnMLCB2tjQ42TDXD"))]
3839
pub some_extra_account: AccountInfo,
3940
#[account(address = Metadata::id())]
4041
pub program_metadata: Program<Metadata>,

0 commit comments

Comments
 (0)