cpi.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. #pragma once
  2. /**
  3. * @brief Solana Cross-Program Invocation
  4. */
  5. #include <sol/types.h>
  6. #include <sol/pubkey.h>
  7. #include <sol/entrypoint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * Maximum CPI instruction data size. 10 KiB was chosen to ensure that CPI
  13. * instructions are not more limited than transaction instructions if the size
  14. * of transactions is doubled in the future.
  15. */
  16. static const uint64_t MAX_CPI_INSTRUCTION_DATA_LEN = 10240;
  17. /**
  18. * Maximum CPI instruction accounts. 255 was chosen to ensure that instruction
  19. * accounts are always within the maximum instruction account limit for SBF
  20. * program instructions.
  21. */
  22. static const uint8_t MAX_CPI_INSTRUCTION_ACCOUNTS = 255;
  23. /**
  24. * Maximum number of account info structs that can be used in a single CPI
  25. * invocation. A limit on account info structs is effectively the same as
  26. * limiting the number of unique accounts. 128 was chosen to match the max
  27. * number of locked accounts per transaction (MAX_TX_ACCOUNT_LOCKS).
  28. */
  29. static const uint16_t MAX_CPI_ACCOUNT_INFOS = 128;
  30. /**
  31. * Account Meta
  32. */
  33. typedef struct {
  34. SolPubkey *pubkey; /** An account's public key */
  35. bool is_writable; /** True if the `pubkey` can be loaded as a read-write account */
  36. bool is_signer; /** True if an Instruction requires a Transaction signature matching `pubkey` */
  37. } SolAccountMeta;
  38. /**
  39. * Instruction
  40. */
  41. typedef struct {
  42. SolPubkey *program_id; /** Pubkey of the instruction processor that executes this instruction */
  43. SolAccountMeta *accounts; /** Metadata for what accounts should be passed to the instruction processor */
  44. uint64_t account_len; /** Number of SolAccountMetas */
  45. uint8_t *data; /** Opaque data passed to the instruction processor */
  46. uint64_t data_len; /** Length of the data in bytes */
  47. } SolInstruction;
  48. /**
  49. * Internal cross-program invocation function
  50. */
  51. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/cpi.inc AND RUN `cargo run --bin gen-headers` */
  52. #ifndef SOL_SBFV2
  53. uint64_t sol_invoke_signed_c(
  54. const SolInstruction *,
  55. const SolAccountInfo *,
  56. int,
  57. const SolSignerSeeds *,
  58. int
  59. );
  60. #else
  61. typedef uint64_t(*sol_invoke_signed_c_pointer_type)(
  62. const SolInstruction *,
  63. const SolAccountInfo *,
  64. int,
  65. const SolSignerSeeds *,
  66. int
  67. );
  68. static uint64_t sol_invoke_signed_c(
  69. const SolInstruction * arg1,
  70. const SolAccountInfo * arg2,
  71. int arg3,
  72. const SolSignerSeeds * arg4,
  73. int
  74. arg5) {
  75. sol_invoke_signed_c_pointer_type sol_invoke_signed_c_pointer = (sol_invoke_signed_c_pointer_type) 2720767109;
  76. return sol_invoke_signed_c_pointer(arg1, arg2, arg3, arg4, arg5);
  77. }
  78. #endif
  79. /**
  80. * Invoke another program and sign for some of the keys
  81. *
  82. * @param instruction Instruction to process
  83. * @param account_infos Accounts used by instruction
  84. * @param account_infos_len Length of account_infos array
  85. * @param seeds Seed bytes used to sign program accounts
  86. * @param seeds_len Length of the seeds array
  87. */
  88. static uint64_t sol_invoke_signed(
  89. const SolInstruction *instruction,
  90. const SolAccountInfo *account_infos,
  91. int account_infos_len,
  92. const SolSignerSeeds *signers_seeds,
  93. int signers_seeds_len
  94. ) {
  95. return sol_invoke_signed_c(
  96. instruction,
  97. account_infos,
  98. account_infos_len,
  99. signers_seeds,
  100. signers_seeds_len
  101. );
  102. }
  103. /**
  104. * Invoke another program
  105. *
  106. * @param instruction Instruction to process
  107. * @param account_infos Accounts used by instruction
  108. * @param account_infos_len Length of account_infos array
  109. */
  110. static uint64_t sol_invoke(
  111. const SolInstruction *instruction,
  112. const SolAccountInfo *account_infos,
  113. int account_infos_len
  114. ) {
  115. const SolSignerSeeds signers_seeds[] = {{}};
  116. return sol_invoke_signed(
  117. instruction,
  118. account_infos,
  119. account_infos_len,
  120. signers_seeds,
  121. 0
  122. );
  123. }
  124. #ifdef __cplusplus
  125. }
  126. #endif
  127. /**@}*/