-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
👷 Reorganizing templates, using bolt.workspace an… (#95)
- Loading branch information
Showing
44 changed files
with
924 additions
and
1,040 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
[workspace] | ||
resolver = "2" | ||
members = [ | ||
"cli", | ||
"programs/*", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use bolt_lang::*; | ||
|
||
declare_id!("{program_id}"); | ||
|
||
#[component] | ||
#[derive(Default)] | ||
pub struct {program_name} {{ | ||
pub x: i64, | ||
pub y: i64, | ||
pub z: i64, | ||
#[max_len(20)] | ||
pub description: String, | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[constant] | ||
pub const SEED: &str = "anchor"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[error_code] | ||
pub enum ErrorCode { | ||
#[msg("Custom error message")] | ||
CustomError, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
#[derive(Accounts)] | ||
pub struct Initialize {} | ||
|
||
pub fn handler(_ctx: Context<Initialize>) -> Result<()> { | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod initialize; | ||
|
||
pub use initialize::*; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use anchor_cli::Files; | ||
use heck::ToSnakeCase; | ||
use std::path::Path; // Import the trait | ||
|
||
pub fn create_program_template_single(name: &str, program_path: &Path) -> Files { | ||
let program_id = anchor_cli::rust_template::get_or_create_program_id(name); | ||
let program_name = name.to_snake_case(); | ||
vec![( | ||
program_path.join("src").join("lib.rs"), | ||
format!(include_str!("single.lib.rs"), program_id=program_id, program_name=program_name), | ||
)] | ||
} | ||
|
||
/// Create a program with multiple files for instructions, state... | ||
pub fn create_program_template_multiple(name: &str, program_path: &Path) -> Files { | ||
let src_path = program_path.join("src"); | ||
let program_id = anchor_cli::rust_template::get_or_create_program_id(name); | ||
let program_name = name.to_snake_case(); | ||
vec![ | ||
( | ||
src_path.join("lib.rs"), | ||
format!(include_str!("multiple.lib.rs"), program_id=program_id, program_name=program_name), | ||
), | ||
( | ||
src_path.join("constants.rs"), | ||
include_str!("constants.rs").into(), | ||
), | ||
( | ||
src_path.join("error.rs"), | ||
include_str!("error.rs").into(), | ||
), | ||
( | ||
src_path.join("instructions").join("mod.rs"), | ||
include_str!("instructions/mod.rs").into(), | ||
), | ||
( | ||
src_path.join("instructions").join("initialize.rs"), | ||
include_str!("instructions/initialize.rs").into(), | ||
), | ||
( | ||
src_path.join("state").join("mod.rs"), | ||
include_str!("state/mod.rs").into(), | ||
), | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
pub mod constants; | ||
pub mod error; | ||
pub mod instructions; | ||
pub mod state; | ||
|
||
use anchor_lang::prelude::*; | ||
|
||
pub use constants::*; | ||
pub use instructions::*; | ||
pub use state::*; | ||
|
||
declare_id!("{program_id}"); | ||
|
||
#[program] | ||
pub mod {program_name} {{ | ||
use super::*; | ||
|
||
pub fn initialize(ctx: Context<Initialize>) -> Result<()> {{ | ||
initialize::handler(ctx) | ||
}} | ||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
use anchor_lang::prelude::*; | ||
|
||
declare_id!("{program_id}"); | ||
|
||
#[program] | ||
pub mod {program_name} {{ | ||
use super::*; | ||
|
||
pub fn initialize(_ctx: Context<Initialize>) -> Result<()> {{ | ||
Ok(()) | ||
}} | ||
}} | ||
|
||
#[derive(Accounts)] | ||
pub struct Initialize {{}} |
Empty file.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use bolt_lang::*; | ||
use position::Position; | ||
|
||
declare_id!("{program_id}"); | ||
|
||
#[system] | ||
pub mod {program_name} {{ | ||
|
||
pub fn execute(ctx: Context<Components>, _args_p: Vec<u8>) -> Result<Components> {{ | ||
let position = &mut ctx.accounts.position; | ||
position.x += 1; | ||
position.y += 1; | ||
Ok(ctx.accounts) | ||
}} | ||
|
||
#[system_input] | ||
pub struct Components {{ | ||
pub position: Position, | ||
}} | ||
|
||
}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use anchor_cli::Files; | ||
use heck::ToSnakeCase; | ||
use std::path::Path; | ||
|
||
/// Create a system which operates on a Position component. | ||
pub fn create_system_template_simple(name: &str, program_path: &Path) -> Files { | ||
let program_id = anchor_cli::rust_template::get_or_create_program_id(name); | ||
let program_name = name.to_snake_case(); | ||
vec![( | ||
program_path.join("src").join("lib.rs"), | ||
format!(include_str!("lib.rs"), program_id=program_id, program_name=program_name) | ||
)] | ||
} |
Oops, something went wrong.