lib.rs 2.6 KB

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