@@ -73,7 +73,7 @@ func ExecuteCallbacksTransactions(chainID flow.Chain, processEvents flow.EventsL
7373 // event.EventIndex
7474
7575 // skip any fee events or other events that are not pending execution events
76- if ! isPendingExecutionEvent (env , event ) {
76+ if ! IsPendingExecutionEvent (env , event ) {
7777 continue
7878 }
7979
@@ -114,19 +114,42 @@ func executeCallbackTransaction(
114114// callback scheduler contract and has the following signature:
115115// event PendingExecution(id: UInt64, priority: UInt8, executionEffort: UInt64, fees: UFix64, callbackOwner: Address)
116116func callbackArgsFromEvent (event flow.Event ) ([]byte , uint64 , error ) {
117+ cadenceId , cadenceEffort , err := ParsePendingExecutionEvent (event )
118+ if err != nil {
119+ return nil , 0 , err
120+ }
121+
122+ effort := uint64 (cadenceEffort )
123+
124+ if effort > flow .DefaultMaxTransactionGasLimit {
125+ log .Warn ().Uint64 ("effort" , effort ).Msg ("effort is greater than max transaction gas limit, setting to max" )
126+ effort = flow .DefaultMaxTransactionGasLimit
127+ }
128+
129+ encID , err := jsoncdc .Encode (cadenceId )
130+ if err != nil {
131+ return nil , 0 , fmt .Errorf ("failed to encode id: %w" , err )
132+ }
133+
134+ return encID , uint64 (effort ), nil
135+ }
136+
137+ // ParsePendingExecutionEvent decodes the PendingExecution event payload and returns the scheduled
138+ // transaction's id and effort.
139+ func ParsePendingExecutionEvent (event flow.Event ) (cadence.UInt64 , cadence.UInt64 , error ) {
117140 const (
118141 processedCallbackIDFieldName = "id"
119142 processedCallbackEffortFieldName = "executionEffort"
120143 )
121144
122145 eventData , err := ccf .Decode (nil , event .Payload )
123146 if err != nil {
124- return nil , 0 , fmt .Errorf ("failed to decode event: %w" , err )
147+ return 0 , 0 , fmt .Errorf ("failed to decode event: %w" , err )
125148 }
126149
127150 cadenceEvent , ok := eventData .(cadence.Event )
128151 if ! ok {
129- return nil , 0 , fmt .Errorf ("event data is not a cadence event" )
152+ return 0 , 0 , fmt .Errorf ("event data is not a cadence event" )
130153 }
131154
132155 idValue := cadence .SearchFieldByName (
@@ -139,32 +162,21 @@ func callbackArgsFromEvent(event flow.Event) ([]byte, uint64, error) {
139162 processedCallbackEffortFieldName ,
140163 )
141164
142- id , ok := idValue .(cadence.UInt64 )
165+ cadenceId , ok := idValue .(cadence.UInt64 )
143166 if ! ok {
144- return nil , 0 , fmt .Errorf ("id is not uint64" )
167+ return 0 , 0 , fmt .Errorf ("id is not uint64" )
145168 }
146169
147170 cadenceEffort , ok := effortValue .(cadence.UInt64 )
148171 if ! ok {
149- return nil , 0 , fmt .Errorf ("effort is not uint64" )
150- }
151-
152- effort := uint64 (cadenceEffort )
153-
154- if effort > flow .DefaultMaxTransactionGasLimit {
155- log .Warn ().Uint64 ("effort" , effort ).Msg ("effort is greater than max transaction gas limit, setting to max" )
156- effort = flow .DefaultMaxTransactionGasLimit
172+ return 0 , 0 , fmt .Errorf ("effort is not uint64" )
157173 }
158174
159- encID , err := jsoncdc .Encode (id )
160- if err != nil {
161- return nil , 0 , fmt .Errorf ("failed to encode id: %w" , err )
162- }
163-
164- return encID , uint64 (effort ), nil
175+ return cadenceId , cadenceEffort , nil
165176}
166177
167- func isPendingExecutionEvent (env templates.Environment , event flow.Event ) bool {
178+ // IsPendingExecutionEvent returns true if the event is a pending execution event.
179+ func IsPendingExecutionEvent (env templates.Environment , event flow.Event ) bool {
168180 processedEventType := PendingExecutionEventType (env )
169181 return event .Type == processedEventType
170182}
0 commit comments