Skip to content

Commit

Permalink
✨ Update components/systems API
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielePicco committed Feb 15, 2024
1 parent 01797fe commit 8bef18c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 24 deletions.
9 changes: 1 addition & 8 deletions src/getting_started/create_component.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,7 @@ use bolt_lang::*;

declare_id!("Fn1JzzEdyb55fsyduWS94mYHizGhJZuhvjX6DVvrmGbQ");

#[component(Position)]
#[program]
pub mod component_position {
use super::*;
}

#[account]
#[bolt_account(component_id = "component-position")]
#[component]
#[derive(Copy)]
pub struct Position {
pub x: i64,
Expand Down
25 changes: 9 additions & 16 deletions src/getting_started/create_system.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ which will add a new system to your workspace:

```rust
use bolt_lang::*;
use component_position::Position;

declare_id!("FSa6qoJXFBR3a7ThQkTAMrC15p6NkchPEjBdd4n6dXxA");

Expand All @@ -20,28 +21,20 @@ declare_id!("FSa6qoJXFBR3a7ThQkTAMrC15p6NkchPEjBdd4n6dXxA");
pub mod system_movement {
use super::*;

pub fn execute(ctx: Context<Component>, args_p: Vec<u8>) -> Result<Position> {
pub fn execute(ctx: Context<Components>, args_p: Vec<u8>) -> Result<Components> {

let mut position = Position::from_account_info(&ctx.accounts.position)?;
let position = &mut ctx.accounts.position;

position.x += 1;
position.y += 1;

Ok(position)
Ok(ctx.accounts)
}
}

// 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>,
}

#[component_deserialize]
pub struct Position {
pub x: i64,
pub y: i64,
pub z: i64,
// Define the input components
#[system_input]
pub struct Components {
pub position: Position,
}
}
```

0 comments on commit 8bef18c

Please sign in to comment.