lib.rs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #![feature(adt_const_params)]
  2. #![allow(warnings)]
  3. pub use rocksalt::*;
  4. // Lacking:
  5. //
  6. // - Error is a lacking as its just a basic enum, maybe use errorcode.
  7. // - Client generation incomplete.
  8. // We need a few Solana things in scope in order to properly abstract Solana.
  9. use solana_program::{
  10. account_info::{
  11. next_account_info,
  12. AccountInfo,
  13. },
  14. entrypoint,
  15. entrypoint::ProgramResult,
  16. instruction::{
  17. AccountMeta,
  18. Instruction,
  19. },
  20. program::invoke_signed,
  21. program_error::ProgramError,
  22. program_pack::Pack,
  23. pubkey::Pubkey,
  24. rent::Rent,
  25. system_instruction,
  26. system_program,
  27. sysvar::{
  28. self,
  29. SysvarId,
  30. },
  31. };
  32. use std::{
  33. io::{
  34. ErrorKind,
  35. Write,
  36. },
  37. marker::PhantomData,
  38. ops::{
  39. Deref,
  40. DerefMut,
  41. },
  42. slice::Iter,
  43. string::FromUtf8Error,
  44. };
  45. pub use borsh::{
  46. BorshDeserialize,
  47. BorshSerialize,
  48. };
  49. // Expose all submodules for consumption.
  50. pub mod error;
  51. pub mod macros;
  52. pub mod processors;
  53. pub mod types;
  54. // We can also re-export a set of types at module scope, this defines the intended API we expect
  55. // people to be able to use from top-level.
  56. pub use crate::{
  57. error::{
  58. ErrBox,
  59. Result,
  60. SolitaireError,
  61. },
  62. macros::*,
  63. processors::{
  64. keyed::Keyed,
  65. peel::Peel,
  66. persist::Persist,
  67. seeded::{
  68. invoke_seeded,
  69. AccountOwner,
  70. AccountSize,
  71. Creatable,
  72. Owned,
  73. Seeded,
  74. },
  75. },
  76. types::*,
  77. };
  78. /// Library name and version to print in entrypoint. Must be evaluated in this crate in order to do the right thing
  79. pub const PKG_NAME_VERSION: &'static str =
  80. concat!(env!("CARGO_PKG_NAME"), " ", env!("CARGO_PKG_VERSION"));
  81. pub struct ExecutionContext<'a, 'b: 'a> {
  82. /// A reference to the program_id of the current program.
  83. pub program_id: &'a Pubkey,
  84. /// All accounts passed into the program
  85. pub accounts: &'a [AccountInfo<'b>],
  86. }
  87. /// Lamports to pay to an account being created
  88. pub enum CreationLamports {
  89. Exempt,
  90. Amount(u64),
  91. }
  92. impl CreationLamports {
  93. /// Amount of lamports to be paid in account creation
  94. pub fn amount(self, size: usize) -> u64 {
  95. match self {
  96. CreationLamports::Exempt => Rent::default().minimum_balance(size),
  97. CreationLamports::Amount(v) => v,
  98. }
  99. }
  100. }
  101. pub trait InstructionContext<'a> {
  102. fn deps(&self) -> Vec<Pubkey> {
  103. vec![]
  104. }
  105. }
  106. /// Trait definition that describes types that can be constructed from a list of solana account
  107. /// references. A list of dependent accounts is produced as a side effect of the parsing stage.
  108. pub trait FromAccounts<'a, 'b: 'a, 'c> {
  109. fn from<T>(_: &'a Pubkey, _: &'c mut Iter<'a, AccountInfo<'b>>, _: &'a T) -> Result<Self>
  110. where
  111. Self: Sized;
  112. }