@@ -3,6 +3,8 @@ use anchor_lang::{prelude::*, system_program};
33use error:: WorldError ;
44use std:: collections:: BTreeSet ;
55
6+ static CPI_AUTH_ADDRESS : Pubkey = Pubkey :: from_str_const ( "B2f2y3QTBv346wE6nWKor72AUhUvFF6mPk7TWCF2QVhi" ) ;
7+
68#[ cfg( not( feature = "no-entrypoint" ) ) ]
79use solana_security_txt:: security_txt;
810
@@ -260,12 +262,12 @@ pub mod world {
260262 if !ctx. accounts . authority . is_signer && ctx. accounts . authority . key != & ID {
261263 return Err ( WorldError :: InvalidAuthority . into ( ) ) ;
262264 }
263- bolt_component:: cpi:: initialize ( ctx. accounts . build ( & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ) ) ?;
265+ bolt_component:: cpi:: initialize ( ctx. accounts . build ( & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ) ) ?;
264266 Ok ( ( ) )
265267 }
266268
267269 pub fn destroy_component ( ctx : Context < DestroyComponent > ) -> Result < ( ) > {
268- bolt_component:: cpi:: destroy ( ctx. accounts . build ( & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ) ) ?;
270+ bolt_component:: cpi:: destroy ( ctx. accounts . build ( & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ) ) ?;
269271 Ok ( ( ) )
270272 }
271273
@@ -275,6 +277,7 @@ pub mod world {
275277 ) -> Result < ( ) > {
276278 apply_impl (
277279 & ctx. accounts . buffer ,
280+ ctx. bumps . buffer ,
278281 & ctx. accounts . authority ,
279282 & ctx. accounts . world ,
280283 & ctx. accounts . bolt_system ,
@@ -291,7 +294,7 @@ pub mod world {
291294 #[ derive( Accounts ) ]
292295 pub struct Apply < ' info > {
293296 /// CHECK: buffer data check
294- #[ account( mut ) ]
297+ #[ account( mut , seeds = [ b"buffer" , authority . key . as_ref ( ) ] , bump ) ]
295298 pub buffer : AccountInfo < ' info > ,
296299 /// CHECK: bolt system program check
297300 #[ account( ) ]
@@ -325,6 +328,7 @@ pub mod world {
325328 ) -> Result < ( ) > {
326329 apply_impl (
327330 & ctx. accounts . buffer ,
331+ ctx. bumps . buffer ,
328332 & ctx. accounts . authority ,
329333 & ctx. accounts . world ,
330334 & ctx. accounts . bolt_system ,
@@ -341,7 +345,7 @@ pub mod world {
341345 #[ derive( Accounts ) ]
342346 pub struct ApplyWithSession < ' info > {
343347 /// CHECK: buffer data check
344- #[ account( mut ) ]
348+ #[ account( mut , seeds = [ b"buffer" , authority . key . as_ref ( ) ] , bump ) ]
345349 pub buffer : AccountInfo < ' info > ,
346350 /// CHECK: bolt system program check
347351 #[ account( ) ]
@@ -375,6 +379,7 @@ pub mod world {
375379#[ allow( clippy:: type_complexity) ]
376380fn apply_impl < ' info > (
377381 buffer : & AccountInfo < ' info > ,
382+ buffer_bump : u8 ,
378383 authority : & Signer < ' info > ,
379384 world : & Account < ' info , World > ,
380385 bolt_system : & UncheckedAccount < ' info > ,
@@ -458,7 +463,7 @@ fn apply_impl<'info>(
458463 from : authority. to_account_info ( ) ,
459464 to : buffer. to_account_info ( ) ,
460465 } ,
461- & [ World :: buffer_seeds ( authority. key ) . as_array ( ) . as_slice ( ) ] ,
466+ & [ & [ b"buffer" , authority. key . as_ref ( ) , & [ buffer_bump ] ] ] ,
462467 ) ,
463468 lamports,
464469 size as u64 ,
@@ -480,7 +485,7 @@ fn apply_impl<'info>(
480485 cpi_auth : cpi_auth. to_account_info ( ) ,
481486 component : component. to_account_info ( ) ,
482487 } ,
483- & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ,
488+ & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ,
484489 ) ,
485490 * bolt_system. key ,
486491 ) ?;
@@ -493,7 +498,7 @@ fn apply_impl<'info>(
493498 buffer : buffer. to_account_info ( ) ,
494499 component : component. to_account_info ( ) ,
495500 } ,
496- & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ,
501+ & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ,
497502 ) ,
498503 ) ?;
499504 }
@@ -517,7 +522,7 @@ fn apply_impl<'info>(
517522 cpi_auth : cpi_auth. to_account_info ( ) ,
518523 component : component. to_account_info ( ) ,
519524 } ,
520- & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ,
525+ & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ,
521526 ) ,
522527 program. key ( ) ,
523528 ) ?;
@@ -534,7 +539,7 @@ fn apply_impl<'info>(
534539 buffer : buffer. to_account_info ( ) ,
535540 component : component. to_account_info ( ) ,
536541 } ,
537- & [ World :: cpi_auth_seeds ( ) . as_array ( ) . as_slice ( ) ] ,
542+ & [ World :: cpi_auth_seeds ( ) . as_slice ( ) ] ,
538543 ) ,
539544 ) ?;
540545 }
@@ -777,37 +782,6 @@ pub struct WorldSystems {
777782 pub approved_systems : BTreeSet < Pubkey > ,
778783}
779784
780- pub struct BufferSeeds < ' buffer , ' owner > {
781- pub buffer : & ' buffer [ u8 ] ,
782- pub owner : & ' owner [ u8 ] ,
783- pub bump : [ u8 ; 1 ] ,
784- }
785-
786- impl < ' buffer , ' owner > BufferSeeds < ' buffer , ' owner > {
787- pub fn new ( buffer : & ' buffer [ u8 ] , owner : & ' owner [ u8 ] , bump : u8 ) -> Self {
788- Self { buffer, owner, bump : [ bump] }
789- }
790-
791- pub fn as_array ( & self ) -> [ & [ u8 ] ; 3 ] {
792- [ & self . buffer , & self . owner , & self . bump ]
793- }
794- }
795-
796- pub struct CpiAuthSeeds < ' cpi_auth > {
797- pub cpi_auth : & ' cpi_auth [ u8 ] ,
798- pub bump : [ u8 ; 1 ] ,
799- }
800-
801- impl < ' cpi_auth > CpiAuthSeeds < ' cpi_auth > {
802- pub fn new ( cpi_auth : & ' cpi_auth [ u8 ] , bump : u8 ) -> Self {
803- Self { cpi_auth, bump : [ bump] }
804- }
805-
806- pub fn as_array ( & self ) -> [ & [ u8 ] ; 2 ] {
807- [ & self . cpi_auth , & self . bump ]
808- }
809- }
810-
811785impl World {
812786 pub fn seed ( ) -> & ' static [ u8 ] {
813787 b"world"
@@ -821,18 +795,12 @@ impl World {
821795 Pubkey :: find_program_address ( & [ World :: seed ( ) , & self . id . to_be_bytes ( ) ] , & crate :: ID )
822796 }
823797
824- pub fn buffer_seeds < ' buffer , ' owner > ( owner : & ' owner Pubkey ) -> BufferSeeds < ' buffer , ' owner > {
825- let ( _, bump) = Pubkey :: find_program_address ( & [ b"buffer" , owner. as_ref ( ) ] , & crate :: ID ) ;
826- BufferSeeds :: new ( b"buffer" , owner. as_ref ( ) , bump)
827- }
828-
829- pub fn cpi_auth_seeds < ' cpi_auth > ( ) -> CpiAuthSeeds < ' cpi_auth > {
830- let ( _, bump) = Pubkey :: find_program_address ( & [ b"cpi_auth" ] , & crate :: ID ) ;
831- CpiAuthSeeds :: new ( b"cpi_auth" , bump)
798+ pub const fn cpi_auth_seeds ( ) -> [ & ' static [ u8 ] ; 2 ] {
799+ [ b"cpi_auth" , & [ 251 ] ] // 251 is the pre-computed bump for cpi_auth.
832800 }
833801
834- pub fn cpi_auth_address ( ) -> Pubkey {
835- Pubkey :: find_program_address ( & [ b"cpi_auth" ] , & crate :: ID ) . 0
802+ pub const fn cpi_auth_address ( ) -> & ' static Pubkey {
803+ & CPI_AUTH_ADDRESS // This is the pre-computed address for cpi_auth.
836804 }
837805}
838806
0 commit comments