lib.rs 2.3 KB

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