bolt_lang/
lib.rs

1pub mod prelude;
2
3pub use anchor_lang;
4pub use anchor_lang::error::ErrorCode::AccountDidNotDeserialize as AccountDidNotDeserializeErrorCode;
5pub use anchor_lang::prelude::*;
6pub use anchor_lang::{
7    AccountDeserialize, AccountSerialize, AnchorDeserialize, AnchorSerialize, Bumps, Result,
8};
9
10pub use session_keys;
11
12pub use bolt_attribute_bolt_arguments::arguments;
13pub use bolt_attribute_bolt_component::component;
14pub use bolt_attribute_bolt_component_deserialize::component_deserialize;
15pub use bolt_attribute_bolt_component_id::component_id;
16pub use bolt_attribute_bolt_delegate::delegate;
17pub use bolt_attribute_bolt_extra_accounts::extra_accounts;
18pub use bolt_attribute_bolt_extra_accounts::pubkey;
19pub use bolt_attribute_bolt_program::bolt_program;
20pub use bolt_attribute_bolt_system::system;
21pub use bolt_attribute_bolt_system_input::system_input;
22
23pub use bolt_system;
24pub use world;
25pub use world::program::World;
26pub use world::Entity;
27
28pub use ephemeral_rollups_sdk::anchor::{DelegationProgram, MagicProgram};
29pub use ephemeral_rollups_sdk::consts::{MAGIC_CONTEXT_ID, MAGIC_PROGRAM_ID};
30pub use ephemeral_rollups_sdk::cpi::{
31    delegate_account, undelegate_account, DelegateAccounts, DelegateConfig,
32};
33pub use ephemeral_rollups_sdk::ephem::commit_and_undelegate_accounts;
34
35pub use serde;
36
37use std::str;
38use std::str::FromStr;
39
40mod errors;
41pub use crate::errors::BoltError;
42
43/// Export of the solana_program crate.
44pub mod solana_program {
45    pub use anchor_lang::solana_program::*;
46}
47
48/// Parses the arguments from a byte array.
49pub fn parse_args<T: serde::de::DeserializeOwned>(args_p: &[u8]) -> T {
50    let args_string = str::from_utf8(args_p).expect("Failed to convert to string");
51    let args: T = serde_json::from_str(args_string)
52        .unwrap_or_else(|_| panic!("Failed to deserialize args: {:?}", args_string));
53    args
54}
55
56// Useful traits for the components
57
58/// Trait used to add the seed and size functions to the component.
59pub trait ComponentTraits {
60    fn seed() -> &'static [u8];
61    fn size() -> usize;
62}
63
64/// Allows to deserialize a component AccountInfo into a struct.
65pub trait ComponentDeserialize: Sized {
66    /// Deserializes an `AccountInfo` into a `Self`.
67    /// `Account`.
68    fn from_account_info(account: &anchor_lang::prelude::AccountInfo) -> Result<Self>;
69}
70
71/// Metadata for the component.
72#[derive(InitSpace, AnchorSerialize, AnchorDeserialize, Default, Copy, Clone)]
73pub struct BoltMetadata {
74    pub authority: Pubkey,
75}
76
77/// Wrapper method to create a pubkey from a string
78pub fn pubkey_from_str(s: &str) -> solana_program::pubkey::Pubkey {
79    solana_program::pubkey::Pubkey::from_str(s).unwrap()
80}