@@ -192,6 +192,12 @@ static bool initContractExec()
192192 if (!contractActionTracker.allocBuffer ())
193193 return false ;
194194
195+ if (!allocPoolWithErrorLog (L" userProcedureRegistry" , sizeof (*userProcedureRegistry), (void **)&userProcedureRegistry, __LINE__))
196+ {
197+ return false ;
198+ }
199+ userProcedureRegistry->init ();
200+
195201 return true ;
196202}
197203
@@ -218,6 +224,9 @@ static void deinitContractExec()
218224 freePool (contractStateChangeFlags);
219225 }
220226
227+ if (userProcedureRegistry)
228+ freePool (userProcedureRegistry);
229+
221230 contractActionTracker.freeBuffer ();
222231}
223232
@@ -917,6 +926,16 @@ void QPI::QpiContextForInit::__registerUserProcedure(USER_PROCEDURE userProcedur
917926 contractUserProcedureLocalsSizes[_currentContractIndex][inputType] = localsSize;
918927}
919928
929+ void QPI::QpiContextForInit::__registerUserProcedureNotification (USER_PROCEDURE userProcedure, unsigned int procedureId, unsigned short inputSize, unsigned short outputSize, unsigned int localsSize) const
930+ {
931+ ASSERT (userProcedureRegistry);
932+ if (!userProcedureRegistry->add (procedureId, { userProcedure, _currentContractIndex, localsSize, inputSize, outputSize }))
933+ {
934+ #if !defined(NDEBUG)
935+ addDebugMessage (L" __registerUserProcedureNotification() failed. You should increase MAX_CONTRACT_PROCEDURES_REGISTERED." );
936+ #endif
937+ }
938+ }
920939
921940
922941// QPI context used to call contract system procedure from qubic core (contract processor)
@@ -1266,15 +1285,6 @@ struct QpiContextUserFunctionCall : public QPI::QpiContextFunctionCall
12661285};
12671286
12681287
1269- struct UserProcedureNotification
1270- {
1271- unsigned int contractIndex;
1272- USER_PROCEDURE procedure;
1273- const void * inputPtr;
1274- unsigned short inputSize;
1275- unsigned int localsSize;
1276- };
1277-
12781288// QPI context used to call contract user procedure as a notification from qubic core (contract processor).
12791289// This means, it isn't triggered by a transaction, but following an event after having setup the notification
12801290// callback in the contract code.
@@ -1283,16 +1293,16 @@ struct UserProcedureNotification
12831293// The procedure pointer, the expected inputSize, and the expected localsSize, which are passed via
12841294// UserProcedureNotification, must be consistent. The code using notifications is responible for ensuring that.
12851295// Use cases:
1286- // - oracle notifications (managed by oracleEngine)
1296+ // - oracle notifications (managed by oracleEngine and userProcedureRegistry )
12871297struct QpiContextUserProcedureNotificationCall : public QPI ::QpiContextProcedureCall
12881298{
1289- QpiContextUserProcedureNotificationCall (const UserProcedureNotification & notification) : QPI::QpiContextProcedureCall(notif .contractIndex, NULL_ID, 0 , USER_PROCEDURE_NOTIFICATION_CALL), notif(notification)
1299+ QpiContextUserProcedureNotificationCall (const UserProcedureRegistry::UserProcedureData & notification) : QPI::QpiContextProcedureCall(notification .contractIndex, NULL_ID, 0 , USER_PROCEDURE_NOTIFICATION_CALL), notif(notification)
12901300 {
12911301 contractActionTracker.init ();
12921302 }
12931303
12941304 // Run user procedure notification
1295- void call ()
1305+ void call (const void * inputPtr )
12961306 {
12971307 ASSERT (_currentContractIndex < contractCount);
12981308
@@ -1330,7 +1340,7 @@ struct QpiContextUserProcedureNotificationCall : public QPI::QpiContextProcedure
13301340 __qpiAbort (ContractErrorAllocInputOutputFailed);
13311341 }
13321342 char * locals = input + notif.inputSize ;
1333- copyMem (input, notif. inputPtr , notif.inputSize );
1343+ copyMem (input, inputPtr, notif.inputSize );
13341344 setMem (locals, notif.localsSize , 0 );
13351345
13361346 // call user procedure
@@ -1353,5 +1363,5 @@ struct QpiContextUserProcedureNotificationCall : public QPI::QpiContextProcedure
13531363 }
13541364
13551365private:
1356- const UserProcedureNotification & notif;
1366+ const UserProcedureRegistry::UserProcedureData & notif;
13571367};
0 commit comments