@@ -86,39 +86,56 @@ fd_exec_txn_ctx_delete( void * mem ) {
86
86
int
87
87
fd_exec_txn_ctx_get_account_at_index ( fd_exec_txn_ctx_t * ctx ,
88
88
uchar idx ,
89
- fd_txn_account_t * * account ) {
89
+ fd_txn_account_t * * account ,
90
+ int (* condition )( fd_exec_txn_ctx_t * ctx ,
91
+ int idx ,
92
+ fd_txn_account_t * acc ) ) {
90
93
if ( FD_UNLIKELY ( idx >=ctx -> accounts_cnt ) ) {
91
94
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ;
92
95
}
93
96
94
97
fd_txn_account_t * txn_account = & ctx -> accounts [idx ];
95
98
* account = txn_account ;
96
99
100
+ if ( condition != NULL ) {
101
+ if ( FD_UNLIKELY ( !condition ( ctx , idx , * account ) ) )
102
+ return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ;
103
+ }
104
+
97
105
return FD_ACC_MGR_SUCCESS ;
98
106
}
99
107
100
108
int
101
109
fd_exec_txn_ctx_get_account_with_key ( fd_exec_txn_ctx_t * ctx ,
102
110
fd_pubkey_t const * pubkey ,
103
- fd_txn_account_t * * account ) {
111
+ fd_txn_account_t * * account ,
112
+ int (* condition )( fd_exec_txn_ctx_t * ctx ,
113
+ int idx ,
114
+ fd_txn_account_t * acc ) ) {
104
115
int index = fd_exec_txn_ctx_find_index_of_account ( ctx , pubkey );
105
116
if ( FD_UNLIKELY ( index == -1 ) ) {
106
117
return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ;
107
118
}
108
119
109
- return fd_exec_txn_ctx_get_account_at_index ( ctx , (uchar )index , account );
120
+ return fd_exec_txn_ctx_get_account_at_index ( ctx ,
121
+ (uchar )index ,
122
+ account ,
123
+ condition );
110
124
}
111
125
112
126
int
113
127
fd_exec_txn_ctx_get_executable_account ( fd_exec_txn_ctx_t * ctx ,
114
128
fd_pubkey_t const * pubkey ,
115
- fd_txn_account_t * * account ) {
129
+ fd_txn_account_t * * account ,
130
+ int (* condition )( fd_exec_txn_ctx_t * ctx ,
131
+ int idx ,
132
+ fd_txn_account_t * acc ) ) {
116
133
/* First try to fetch the executable account from the existing borrowed accounts.
117
134
If the pubkey is in the account keys, then we want to re-use that
118
135
borrowed account since it reflects changes from prior instructions. Referencing the
119
136
read-only executable accounts list is incorrect behavior when the program
120
137
data account is written to in a prior instruction (e.g. program upgrade + invoke within the same txn) */
121
- int err = fd_exec_txn_ctx_get_account_with_key ( ctx , pubkey , account );
138
+ int err = fd_exec_txn_ctx_get_account_with_key ( ctx , pubkey , account , condition );
122
139
if ( FD_UNLIKELY ( err == FD_ACC_MGR_SUCCESS ) ) {
123
140
return FD_ACC_MGR_SUCCESS ;
124
141
}
@@ -128,8 +145,10 @@ fd_exec_txn_ctx_get_executable_account( fd_exec_txn_ctx_t * ctx,
128
145
fd_txn_account_t * txn_account = & ctx -> executable_accounts [i ];
129
146
* account = txn_account ;
130
147
131
- if ( FD_UNLIKELY ( !fd_acc_exists ( txn_account -> const_meta ) ) )
132
- return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ;
148
+ if ( condition != NULL ) {
149
+ if ( FD_UNLIKELY ( !condition ( ctx , (int )i , * account ) ) )
150
+ return FD_ACC_MGR_ERR_UNKNOWN_ACCOUNT ;
151
+ }
133
152
134
153
return FD_ACC_MGR_SUCCESS ;
135
154
}
0 commit comments