log.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. #pragma once
  2. /**
  3. * @brief Solana logging utilities
  4. */
  5. #include <sol/types.h>
  6. #include <sol/string.h>
  7. #include <sol/entrypoint.h>
  8. #ifdef __cplusplus
  9. extern "C" {
  10. #endif
  11. /**
  12. * Prints a string to stdout
  13. */
  14. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/log.inc AND RUN `cargo run --bin gen-headers` */
  15. #ifndef SOL_SBFV2
  16. void sol_log_(const char *, uint64_t);
  17. #else
  18. typedef void(*sol_log__pointer_type)(const char *, uint64_t);
  19. static void sol_log_(const char * arg1, uint64_t arg2) {
  20. sol_log__pointer_type sol_log__pointer = (sol_log__pointer_type) 544561597;
  21. sol_log__pointer(arg1, arg2);
  22. }
  23. #endif
  24. #define sol_log(message) sol_log_(message, sol_strlen(message))
  25. /**
  26. * Prints a 64 bit values represented in hexadecimal to stdout
  27. */
  28. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/log.inc AND RUN `cargo run --bin gen-headers` */
  29. #ifndef SOL_SBFV2
  30. void sol_log_64_(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
  31. #else
  32. typedef void(*sol_log_64__pointer_type)(uint64_t, uint64_t, uint64_t, uint64_t, uint64_t);
  33. static void sol_log_64_(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
  34. sol_log_64__pointer_type sol_log_64__pointer = (sol_log_64__pointer_type) 1546269048;
  35. sol_log_64__pointer(arg1, arg2, arg3, arg4, arg5);
  36. }
  37. #endif
  38. #define sol_log_64 sol_log_64_
  39. /**
  40. * Prints the current compute unit consumption to stdout
  41. */
  42. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/log.inc AND RUN `cargo run --bin gen-headers` */
  43. #ifndef SOL_SBFV2
  44. void sol_log_compute_units_();
  45. #else
  46. typedef void(*sol_log_compute_units__pointer_type)();
  47. static void sol_log_compute_units_() {
  48. sol_log_compute_units__pointer_type sol_log_compute_units__pointer = (sol_log_compute_units__pointer_type) 1387942038;
  49. sol_log_compute_units__pointer();
  50. }
  51. #endif
  52. #define sol_log_compute_units() sol_log_compute_units_()
  53. /**
  54. * Prints the hexadecimal representation of an array
  55. *
  56. * @param array The array to print
  57. */
  58. static void sol_log_array(const uint8_t *array, int len) {
  59. for (int j = 0; j < len; j++) {
  60. sol_log_64(0, 0, 0, j, array[j]);
  61. }
  62. }
  63. /**
  64. * Print the base64 representation of some arrays.
  65. */
  66. /* DO NOT MODIFY THIS GENERATED FILE. INSTEAD CHANGE platform-tools-sdk/sbf/c/inc/sol/inc/log.inc AND RUN `cargo run --bin gen-headers` */
  67. #ifndef SOL_SBFV2
  68. void sol_log_data(SolBytes *, uint64_t);
  69. #else
  70. typedef void(*sol_log_data_pointer_type)(SolBytes *, uint64_t);
  71. static void sol_log_data(SolBytes * arg1, uint64_t arg2) {
  72. sol_log_data_pointer_type sol_log_data_pointer = (sol_log_data_pointer_type) 1930933300;
  73. sol_log_data_pointer(arg1, arg2);
  74. }
  75. #endif
  76. /**
  77. * Prints the program's input parameters
  78. *
  79. * @param params Pointer to a SolParameters structure
  80. */
  81. static void sol_log_params(const SolParameters *params) {
  82. sol_log("- Program identifier:");
  83. sol_log_pubkey(params->program_id);
  84. sol_log("- Number of KeyedAccounts");
  85. sol_log_64(0, 0, 0, 0, params->ka_num);
  86. for (int i = 0; i < params->ka_num; i++) {
  87. sol_log(" - Is signer");
  88. sol_log_64(0, 0, 0, 0, params->ka[i].is_signer);
  89. sol_log(" - Is writable");
  90. sol_log_64(0, 0, 0, 0, params->ka[i].is_writable);
  91. sol_log(" - Key");
  92. sol_log_pubkey(params->ka[i].key);
  93. sol_log(" - Lamports");
  94. sol_log_64(0, 0, 0, 0, *params->ka[i].lamports);
  95. sol_log(" - data");
  96. sol_log_array(params->ka[i].data, params->ka[i].data_len);
  97. sol_log(" - Owner");
  98. sol_log_pubkey(params->ka[i].owner);
  99. sol_log(" - Executable");
  100. sol_log_64(0, 0, 0, 0, params->ka[i].executable);
  101. sol_log(" - Rent Epoch");
  102. sol_log_64(0, 0, 0, 0, params->ka[i].rent_epoch);
  103. }
  104. sol_log("- Instruction data\0");
  105. sol_log_array(params->data, params->data_len);
  106. }
  107. #ifdef SOL_TEST
  108. /**
  109. * Stub functions when building tests
  110. */
  111. #include <stdio.h>
  112. void sol_log_(const char *s, uint64_t len) {
  113. printf("Program log: %s\n", s);
  114. }
  115. void sol_log_64(uint64_t arg1, uint64_t arg2, uint64_t arg3, uint64_t arg4, uint64_t arg5) {
  116. printf("Program log: %llu, %llu, %llu, %llu, %llu\n", arg1, arg2, arg3, arg4, arg5);
  117. }
  118. void sol_log_compute_units_() {
  119. printf("Program consumption: __ units remaining\n");
  120. }
  121. #endif
  122. #ifdef __cplusplus
  123. }
  124. #endif
  125. /**@}*/