diff --git a/crates/bolt-lang/attribute/bolt-program/src/lib.rs b/crates/bolt-lang/attribute/bolt-program/src/lib.rs index 58dc478..7f3e2c1 100644 --- a/crates/bolt-lang/attribute/bolt-program/src/lib.rs +++ b/crates/bolt-lang/attribute/bolt-program/src/lib.rs @@ -110,15 +110,10 @@ fn generate_initialize(component_type: &Type) -> (TokenStream2, TokenStream2) { ( quote! { #[automatically_derived] - pub fn initialize(ctx: Context) -> Result<()> { - ctx.accounts.data.set_inner(<#component_type>::default()); - if let Some(authority) = &ctx.accounts.authority { - if authority.key != ctx.accounts.payer.key { - panic!("The authority does not match the payer."); - } - ctx.accounts.data.bolt_metadata.authority = *authority.key; - } - Ok(()) + pub fn initialize(ctx: Context) -> Result> { + let mut serialized_data = Vec::new(); + <#component_type>::default().serialize(&mut serialized_data).expect("Failed to serialize"); + Ok(serialized_data) } }, quote! { @@ -127,8 +122,8 @@ fn generate_initialize(component_type: &Type) -> (TokenStream2, TokenStream2) { pub struct Initialize<'info> { #[account(mut)] pub payer: Signer<'info>, - #[account(init_if_needed, payer = payer, space = <#component_type>::size(), seeds = [<#component_type>::seed(), entity.key().as_ref()], bump)] - pub data: Account<'info, #component_type>, + #[account(init_if_needed, owner=World::id(), payer = payer, space = <#component_type>::size(), seeds = [<#component_type>::seed(), entity.key().as_ref()], bump)] + pub data: AccountInfo<'info>, #[account()] pub entity: Account<'info, Entity>, #[account()] diff --git a/crates/bolt-lang/attribute/system/src/lib.rs b/crates/bolt-lang/attribute/system/src/lib.rs index 28aaedd..3a184f4 100644 --- a/crates/bolt-lang/attribute/system/src/lib.rs +++ b/crates/bolt-lang/attribute/system/src/lib.rs @@ -16,8 +16,6 @@ struct SystemTransform; /// ```ignore /// #[system] /// pub mod system_fly { -/// use super::*; -/// /// pub fn execute(ctx: Context, _args: Vec) -> Result { /// let pos = Position { /// x: ctx.accounts.position.x, diff --git a/crates/bolt-lang/src/lib.rs b/crates/bolt-lang/src/lib.rs index 7eb00f2..81808d5 100644 --- a/crates/bolt-lang/src/lib.rs +++ b/crates/bolt-lang/src/lib.rs @@ -8,6 +8,7 @@ pub use bolt_attribute_bolt_system::system; pub use bolt_system; pub use world; pub use world::Entity; +pub use world::program::World; pub use serde; pub use serde::{Deserialize as BoltDeserialize, Serialize as BoltSerialize}; diff --git a/examples/component-position/src/lib.rs b/examples/component-position/src/lib.rs index 81f8921..0446e58 100644 --- a/examples/component-position/src/lib.rs +++ b/examples/component-position/src/lib.rs @@ -7,5 +7,5 @@ declare_id!("Fn1JzzEdyb55fsyduWS94mYHizGhJZuhvjX6DVvrmGbQ"); pub struct Position { pub x: i64, pub y: i64, - pub z: i64, + pub z: i64 } diff --git a/examples/system-apply-velocity/src/lib.rs b/examples/system-apply-velocity/src/lib.rs index ebdf8f3..a58b013 100644 --- a/examples/system-apply-velocity/src/lib.rs +++ b/examples/system-apply-velocity/src/lib.rs @@ -20,8 +20,6 @@ pub mod system_apply_velocity { #[derive(Accounts)] pub struct Component<'info> { - #[account()] pub velocity: Account<'info, Velocity>, - #[account()] pub position: Account<'info, Position>, } diff --git a/examples/system-simple-movement/src/lib.rs b/examples/system-simple-movement/src/lib.rs index 471988c..9ac9326 100644 --- a/examples/system-simple-movement/src/lib.rs +++ b/examples/system-simple-movement/src/lib.rs @@ -4,9 +4,10 @@ declare_id!("FSa6qoJXFBR3a7ThQkTAMrC15p6NkchPEjBdd4n6dXxA"); #[system] pub mod system_simple_movement { + pub fn execute(ctx: Context, args_p: Vec) -> Result { let args = parse_args::(&args_p); - + let mut position = Position::from_account_info(&ctx.accounts.position)?; // Compute the new position based on the direction @@ -26,7 +27,6 @@ pub mod system_simple_movement { // Define the Account to parse from the component #[derive(Accounts)] pub struct Component<'info> { - /// CHECK: check that the component is the expected account pub position: AccountInfo<'info>, } diff --git a/programs/bolt-component/src/lib.rs b/programs/bolt-component/src/lib.rs index c1d022f..764a05c 100644 --- a/programs/bolt-component/src/lib.rs +++ b/programs/bolt-component/src/lib.rs @@ -1,4 +1,5 @@ use anchor_lang::prelude::*; +use std::str::FromStr; declare_id!("CmP2djJgABZ4cRokm4ndxuq6LerqpNHLBsaUv2XKEJua"); @@ -6,15 +7,13 @@ declare_id!("CmP2djJgABZ4cRokm4ndxuq6LerqpNHLBsaUv2XKEJua"); pub mod bolt_component { use super::*; - pub fn initialize(ctx: Context) -> Result<()> { - // ctx.accounts.data.to_account_info().assign(::ID); TODO: Test delegate to the world program - if let Some(authority) = &ctx.accounts.authority { - if authority.key != ctx.accounts.payer.key { - panic!("Authority mismatch"); - } - ctx.accounts.data.bolt_metadata.authority = *authority.key; - } - Ok(()) + pub fn initialize(_ctx: Context) -> Result> { + let mut component = Component::default(); + component.bolt_metadata.authority = Pubkey::from_str("WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n").unwrap(); + let mut serialized_data = Vec::new(); + anchor_lang::AccountSerialize::try_serialize(&component, &mut serialized_data).expect("Failed to serialize"); + //component.serialize(&mut serialized_data).expect("Failed to serialize"); + Ok(serialized_data) } pub fn apply(_ctx: Context, _args: Vec) -> Result<()> { @@ -56,8 +55,8 @@ pub mod bolt_component { pub struct Initialize<'info> { #[account(mut)] pub payer: Signer<'info>, - #[account(init_if_needed, payer = payer, space = Component::size(), seeds = [Component::seed(), entity.key().as_ref()], bump)] - pub data: Account<'info, Component>, + #[account(init_if_needed, owner = Pubkey::from_str("WorLD15A7CrDwLcLy4fRqtaTb9fbd8o8iqiEMUDse2n").unwrap(), payer = payer, space = Component::size(), seeds = [Component::seed(), entity.key().as_ref()], bump)] + pub data: AccountInfo<'info>, #[account()] /// CHECK: A generic entity account pub entity: AccountInfo<'info>, diff --git a/programs/bolt-system/src/lib.rs b/programs/bolt-system/src/lib.rs index 3eddb48..20e0ce9 100644 --- a/programs/bolt-system/src/lib.rs +++ b/programs/bolt-system/src/lib.rs @@ -1,6 +1,5 @@ use anchor_lang::prelude::borsh::{BorshDeserialize, BorshSerialize}; use anchor_lang::prelude::*; -//use bolt_helpers_system_template::*; declare_id!("7X4EFsDJ5aYTcEjKzJ94rD8FRKgQeXC89fkpeTS4KaqP"); diff --git a/programs/world/src/lib.rs b/programs/world/src/lib.rs index 7eac83b..144f993 100644 --- a/programs/world/src/lib.rs +++ b/programs/world/src/lib.rs @@ -37,7 +37,9 @@ pub mod world { } pub fn initialize_component(ctx: Context) -> Result<()> { - bolt_component::cpi::initialize(ctx.accounts.build())?; + let data = bolt_component::cpi::initialize(ctx.accounts.build())?; + let component_data = &mut *ctx.accounts.data.data.borrow_mut(); + component_data.copy_from_slice(&data.get()); Ok(()) }