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_txn_ctx; 71 : typedef struct fd_exec_txn_ctx fd_exec_txn_ctx_t; 72 : 73 : struct fd_exec_instr_ctx; 74 : typedef struct fd_exec_instr_ctx fd_exec_instr_ctx_t; 75 : 76 : struct fd_acc_mgr; 77 : typedef struct fd_acc_mgr fd_acc_mgr_t; 78 : 79 : struct fd_capture_ctx; 80 : typedef struct fd_capture_ctx fd_capture_ctx_t; 81 : 82 : struct fd_borrowed_account; 83 : typedef struct fd_borrowed_account fd_borrowed_account_t; 84 : 85 : struct fd_txn_account; 86 : typedef struct fd_txn_account fd_txn_account_t; 87 : 88 : struct fd_exec_accounts; 89 : typedef struct fd_exec_accounts fd_exec_accounts_t; 90 : 91 : union fd_features; 92 : typedef union fd_features fd_features_t; 93 : 94 : struct fd_progcache; 95 : typedef struct fd_progcache fd_progcache_t; 96 : 97 : union fd_runtime_stack; 98 : typedef union fd_runtime_stack fd_runtime_stack_t; 99 : 100 : struct fd_exec_stack; 101 : typedef struct fd_exec_stack fd_exec_stack_t; 102 : 103 : struct fd_account_meta { 104 : uchar owner[32]; 105 : ulong lamports; 106 : ulong slot; 107 : uint dlen; 108 : uchar executable; 109 : uchar padding[3]; 110 : }; 111 : typedef struct fd_account_meta fd_account_meta_t; 112 : 113 : /* fd_rawtxn_b_t is a convenience type to store a pointer to a 114 : serialized transaction. Should probably be removed in the future. */ 115 : 116 : struct fd_rawtxn_b { 117 : void * raw; 118 : ushort txn_sz; 119 : }; 120 : typedef struct fd_rawtxn_b fd_rawtxn_b_t; 121 : 122 : FD_PROTOTYPES_BEGIN 123 : 124 : /* fd_acct_addr_cstr converts the given Solana address into a base58- 125 : encoded cstr. Returns cstr. On return cstr contains a string with 126 : length in [32,44] (excluding NULL terminator). */ 127 : 128 : static inline char * 129 : fd_acct_addr_cstr( char cstr[ FD_BASE58_ENCODED_32_SZ ], 130 0 : uchar const addr[ 32 ] ) { 131 : return fd_base58_encode_32( addr, NULL, cstr ); 132 0 : } 133 : 134 : FD_PROTOTYPES_END 135 : 136 : #endif /* HEADER_fd_src_flamenco_fd_flamenco_base_h */