Line data Source code
1 : #ifndef HEADER_fd_src_flamenco_fd_flamenco_base_h 2 : #define HEADER_fd_src_flamenco_fd_flamenco_base_h 3 : 4 : #include "../ballet/base58/fd_base58.h" 5 : #include "types/fd_cast.h" 6 : 7 : #define FD_DEFAULT_SLOTS_PER_EPOCH ( 432000UL ) 8 : #define FD_DEFAULT_SHREDS_PER_EPOCH ( ( 1 << 15UL ) * FD_DEFAULT_SLOTS_PER_EPOCH ) 9 48 : #define FD_SLOT_NULL ( ULONG_MAX ) 10 0 : #define FD_SHRED_IDX_NULL ( UINT_MAX ) 11 : 12 : #if FD_HAS_ALLOCA 13 : 14 : /* FD_BASE58_ENC_{32,64}_ALLOCA is a shorthand for fd_base58_encode_{32,64}, 15 : including defining a temp buffer. With additional support for passing 16 : NULL. Useful for printf-like functions. 17 : Example: 18 : 19 : fd_pubkey_t pk = ... ; 20 : printf("%s", FD_BASE58_ENC_32_ALLOCA( pk ) ); 21 : 22 : The temp buffer is allocated on the stack and therefore invalidated 23 : when the function this is used in returns. NULL will result in 24 : "<NULL>". 25 : Do NOT use this marco in a long loop or a recursive function. 26 : */ 27 : 28 : static inline char * 29 : fd_base58_enc_32_fmt( char * out, 30 69 : uchar const * in ) { 31 69 : if( FD_UNLIKELY( !in ) ) { 32 3 : strcpy( out, "<NULL>"); 33 66 : } else { 34 66 : fd_base58_encode_32( in, NULL, out ); 35 66 : } 36 69 : return out; 37 69 : } 38 : 39 6 : #define FD_BASE58_ENC_32_ALLOCA( x ) __extension__({ \ 40 6 : char * _out = fd_alloca_check( 1UL, FD_BASE58_ENCODED_32_SZ ); \ 41 6 : fd_base58_enc_32_fmt( _out, (uchar const *)(x) ); \ 42 6 : }) 43 : 44 : static inline char * 45 : fd_base58_enc_64_fmt( char * out, 46 6 : uchar const * in ) { 47 6 : if( FD_UNLIKELY( !in ) ) { 48 3 : strcpy( out, "<NULL>"); 49 3 : } else { 50 3 : fd_base58_encode_64( in, NULL, out ); 51 3 : } 52 6 : return out; 53 6 : } 54 : 55 6 : #define FD_BASE58_ENC_64_ALLOCA( x ) __extension__({ \ 56 6 : char * _out = fd_alloca_check( 1UL, FD_BASE58_ENCODED_64_SZ ); \ 57 6 : fd_base58_enc_64_fmt( _out, (uchar const *)(x) ); \ 58 6 : }) 59 : 60 : #endif /* FD_HAS_ALLOCA */ 61 : 62 : /* Forward declarations */ 63 : 64 : struct fd_bank; 65 : typedef struct fd_bank fd_bank_t; 66 : 67 : struct fd_banks; 68 : typedef struct fd_banks fd_banks_t; 69 : 70 : struct fd_exec_instr_ctx; 71 : typedef struct fd_exec_instr_ctx fd_exec_instr_ctx_t; 72 : 73 : struct fd_acc_mgr; 74 : typedef struct fd_acc_mgr fd_acc_mgr_t; 75 : 76 : struct fd_capture_ctx; 77 : typedef struct fd_capture_ctx fd_capture_ctx_t; 78 : 79 : struct fd_borrowed_account; 80 : typedef struct fd_borrowed_account fd_borrowed_account_t; 81 : 82 : struct fd_txn_account; 83 : typedef struct fd_txn_account fd_txn_account_t; 84 : 85 : struct fd_exec_accounts; 86 : typedef struct fd_exec_accounts fd_exec_accounts_t; 87 : 88 : union fd_features; 89 : typedef union fd_features fd_features_t; 90 : 91 : struct fd_progcache; 92 : typedef struct fd_progcache fd_progcache_t; 93 : 94 : union fd_runtime_stack; 95 : typedef union fd_runtime_stack fd_runtime_stack_t; 96 : 97 : struct fd_runtime; 98 : typedef struct fd_runtime fd_runtime_t; 99 : 100 : struct fd_txn_in; 101 : typedef struct fd_txn_in fd_txn_in_t; 102 : 103 : struct fd_txn_out; 104 : typedef struct fd_txn_out fd_txn_out_t; 105 : 106 : struct fd_log_collector; 107 : typedef struct fd_log_collector fd_log_collector_t; 108 : 109 : struct fd_account_meta { 110 : uchar owner[32]; 111 : ulong lamports; 112 : ulong slot; 113 : uint dlen; 114 : uchar executable; 115 : uchar padding[3]; 116 : }; 117 : typedef struct fd_account_meta fd_account_meta_t; 118 : 119 : FD_PROTOTYPES_BEGIN 120 : 121 : /* fd_acct_addr_cstr converts the given Solana address into a base58- 122 : encoded cstr. Returns cstr. On return cstr contains a string with 123 : length in [32,44] (excluding NULL terminator). */ 124 : 125 : static inline char * 126 : fd_acct_addr_cstr( char cstr[ FD_BASE58_ENCODED_32_SZ ], 127 0 : uchar const addr[ 32 ] ) { 128 : return fd_base58_encode_32( addr, NULL, cstr ); 129 0 : } 130 : 131 : FD_PROTOTYPES_END 132 : 133 : #endif /* HEADER_fd_src_flamenco_fd_flamenco_base_h */