|
@@ -260,12 +260,12 @@ pub mod world {
|
|
|
if !ctx.accounts.authority.is_signer && ctx.accounts.authority.key != &ID {
|
|
|
return Err(WorldError::InvalidAuthority.into());
|
|
|
}
|
|
|
- bolt_component::cpi::initialize(ctx.accounts.build(&[World::cpi_auth_seeds().as_slice()]))?;
|
|
|
+ bolt_component::cpi::initialize(ctx.accounts.build(&[World::cpi_auth_seeds().as_array().as_slice()]))?;
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
|
pub fn destroy_component(ctx: Context<DestroyComponent>) -> Result<()> {
|
|
|
- bolt_component::cpi::destroy(ctx.accounts.build(&[World::cpi_auth_seeds().as_slice()]))?;
|
|
|
+ bolt_component::cpi::destroy(ctx.accounts.build(&[World::cpi_auth_seeds().as_array().as_slice()]))?;
|
|
|
Ok(())
|
|
|
}
|
|
|
|
|
@@ -297,7 +297,7 @@ pub mod world {
|
|
|
#[account()]
|
|
|
pub bolt_system: UncheckedAccount<'info>,
|
|
|
/// CHECK: authority check
|
|
|
- #[account()]
|
|
|
+ #[account(mut)]
|
|
|
pub authority: Signer<'info>,
|
|
|
#[account()]
|
|
|
/// CHECK: cpi auth check
|
|
@@ -347,7 +347,7 @@ pub mod world {
|
|
|
#[account()]
|
|
|
pub bolt_system: UncheckedAccount<'info>,
|
|
|
/// CHECK: authority check
|
|
|
- #[account()]
|
|
|
+ #[account(mut)]
|
|
|
pub authority: Signer<'info>,
|
|
|
#[account()]
|
|
|
/// CHECK: cpi auth check
|
|
@@ -458,7 +458,7 @@ fn apply_impl<'info>(
|
|
|
from: authority.to_account_info(),
|
|
|
to: buffer.to_account_info(),
|
|
|
},
|
|
|
- &[World::buffer_seeds().as_slice()],
|
|
|
+ &[World::buffer_seeds(authority.key).as_array().as_slice()],
|
|
|
),
|
|
|
lamports,
|
|
|
size as u64,
|
|
@@ -480,7 +480,7 @@ fn apply_impl<'info>(
|
|
|
cpi_auth: cpi_auth.to_account_info(),
|
|
|
component: component.to_account_info(),
|
|
|
},
|
|
|
- &[World::cpi_auth_seeds().as_slice()],
|
|
|
+ &[World::cpi_auth_seeds().as_array().as_slice()],
|
|
|
),
|
|
|
*bolt_system.key,
|
|
|
)?;
|
|
@@ -493,7 +493,7 @@ fn apply_impl<'info>(
|
|
|
buffer: buffer.to_account_info(),
|
|
|
component: component.to_account_info(),
|
|
|
},
|
|
|
- &[World::cpi_auth_seeds().as_slice()],
|
|
|
+ &[World::cpi_auth_seeds().as_array().as_slice()],
|
|
|
),
|
|
|
)?;
|
|
|
}
|
|
@@ -517,7 +517,7 @@ fn apply_impl<'info>(
|
|
|
cpi_auth: cpi_auth.to_account_info(),
|
|
|
component: component.to_account_info(),
|
|
|
},
|
|
|
- &[World::cpi_auth_seeds().as_slice()],
|
|
|
+ &[World::cpi_auth_seeds().as_array().as_slice()],
|
|
|
),
|
|
|
program.key(),
|
|
|
)?;
|
|
@@ -534,7 +534,7 @@ fn apply_impl<'info>(
|
|
|
buffer: buffer.to_account_info(),
|
|
|
component: component.to_account_info(),
|
|
|
},
|
|
|
- &[World::cpi_auth_seeds().as_slice()],
|
|
|
+ &[World::cpi_auth_seeds().as_array().as_slice()],
|
|
|
),
|
|
|
)?;
|
|
|
}
|
|
@@ -777,6 +777,37 @@ pub struct WorldSystems {
|
|
|
pub approved_systems: BTreeSet<Pubkey>,
|
|
|
}
|
|
|
|
|
|
+pub struct BufferSeeds<'buffer, 'owner> {
|
|
|
+ pub buffer: &'buffer [u8],
|
|
|
+ pub owner: &'owner [u8],
|
|
|
+ pub bump: [u8; 1],
|
|
|
+}
|
|
|
+
|
|
|
+impl<'buffer, 'owner> BufferSeeds<'buffer, 'owner> {
|
|
|
+ pub fn new(buffer: &'buffer [u8], owner: &'owner [u8], bump: u8) -> Self {
|
|
|
+ Self { buffer, owner, bump: [bump] }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn as_array(&self) -> [&[u8]; 3] {
|
|
|
+ [&self.buffer, &self.owner, &self.bump]
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+pub struct CpiAuthSeeds<'cpi_auth> {
|
|
|
+ pub cpi_auth: &'cpi_auth [u8],
|
|
|
+ pub bump: [u8; 1],
|
|
|
+}
|
|
|
+
|
|
|
+impl<'cpi_auth> CpiAuthSeeds<'cpi_auth> {
|
|
|
+ pub fn new(cpi_auth: &'cpi_auth [u8], bump: u8) -> Self {
|
|
|
+ Self { cpi_auth, bump: [bump] }
|
|
|
+ }
|
|
|
+
|
|
|
+ pub fn as_array(&self) -> [&[u8]; 2] {
|
|
|
+ [&self.cpi_auth, &self.bump]
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
impl World {
|
|
|
pub fn seed() -> &'static [u8] {
|
|
|
b"world"
|
|
@@ -790,16 +821,18 @@ impl World {
|
|
|
Pubkey::find_program_address(&[World::seed(), &self.id.to_be_bytes()], &crate::ID)
|
|
|
}
|
|
|
|
|
|
- pub fn buffer_seeds() -> [&'static [u8]; 2] {
|
|
|
- [b"buffer", &[255]] // 251 is the pre-computed bump for buffer.
|
|
|
+ pub fn buffer_seeds<'buffer, 'owner>(owner: &'owner Pubkey) -> BufferSeeds<'buffer, 'owner> {
|
|
|
+ let (_, bump) = Pubkey::find_program_address(&[b"buffer", owner.as_ref()], &crate::ID);
|
|
|
+ BufferSeeds::new(b"buffer", owner.as_ref(), bump)
|
|
|
}
|
|
|
|
|
|
- pub fn cpi_auth_seeds() -> [&'static [u8]; 2] {
|
|
|
- [b"cpi_auth", &[251]] // 251 is the pre-computed bump for cpi_auth.
|
|
|
+ pub fn cpi_auth_seeds<'cpi_auth>() -> CpiAuthSeeds<'cpi_auth> {
|
|
|
+ let (_, bump) = Pubkey::find_program_address(&[b"cpi_auth"], &crate::ID);
|
|
|
+ CpiAuthSeeds::new(b"cpi_auth", bump)
|
|
|
}
|
|
|
|
|
|
- pub const fn cpi_auth_address() -> Pubkey {
|
|
|
- Pubkey::from_str_const("B2f2y3QTBv346wE6nWKor72AUhUvFF6mPk7TWCF2QVhi") // This is the pre-computed address for cpi_auth.
|
|
|
+ pub fn cpi_auth_address() -> Pubkey {
|
|
|
+ Pubkey::find_program_address(&[b"cpi_auth"], &crate::ID).0
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -828,44 +861,3 @@ impl SystemWhitelist {
|
|
|
8 + Registry::INIT_SPACE
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-// /// Builds the context for updating a component.
|
|
|
-// pub fn build_update_context<'a, 'b, 'c, 'info>(
|
|
|
-// component_program: AccountInfo<'info>,
|
|
|
-// bolt_component: AccountInfo<'info>,
|
|
|
-// authority: Signer<'info>,
|
|
|
-// cpi_auth: UncheckedAccount<'info>,
|
|
|
-// signer_seeds: &'a [&'b [&'c [u8]]],
|
|
|
-// ) -> CpiContext<'a, 'b, 'c, 'info, bolt_component::cpi::accounts::Update<'info>> {
|
|
|
-// let authority = authority.to_account_info();
|
|
|
-// let cpi_auth = cpi_auth.to_account_info();
|
|
|
-// let cpi_program = component_program;
|
|
|
-// bolt_component::cpi::accounts::Update {
|
|
|
-// bolt_component,
|
|
|
-// authority,
|
|
|
-// cpi_auth,
|
|
|
-// }
|
|
|
-// .build_cpi_context(cpi_program, signer_seeds)
|
|
|
-// }
|
|
|
-
|
|
|
-// /// Builds the context for updating a component.
|
|
|
-// pub fn build_update_context_with_session<'a, 'b, 'c, 'info>(
|
|
|
-// component_program: AccountInfo<'info>,
|
|
|
-// bolt_component: AccountInfo<'info>,
|
|
|
-// authority: Signer<'info>,
|
|
|
-// cpi_auth: UncheckedAccount<'info>,
|
|
|
-// session_token: UncheckedAccount<'info>,
|
|
|
-// signer_seeds: &'a [&'b [&'c [u8]]],
|
|
|
-// ) -> CpiContext<'a, 'b, 'c, 'info, bolt_component::cpi::accounts::UpdateWithSession<'info>> {
|
|
|
-// let authority = authority.to_account_info();
|
|
|
-// let cpi_auth = cpi_auth.to_account_info();
|
|
|
-// let cpi_program = component_program;
|
|
|
-// let session_token = session_token.to_account_info();
|
|
|
-// bolt_component::cpi::accounts::UpdateWithSession {
|
|
|
-// bolt_component,
|
|
|
-// authority,
|
|
|
-// cpi_auth,
|
|
|
-// session_token,
|
|
|
-// }
|
|
|
-// .build_cpi_context(cpi_program, signer_seeds)
|
|
|
-// }
|