@@ -35,7 +35,6 @@ func (context *asyncContext) executeAsyncLocalCalls() error {
3535 return nil
3636}
3737
38- // TODO split this method into smaller ones
3938func (context * asyncContext ) executeAsyncLocalCall (asyncCall * vmhost.AsyncCall ) error {
4039 destinationCallInput , err := context .createContractCallInput (asyncCall )
4140 if err != nil {
@@ -79,56 +78,54 @@ func (context *asyncContext) executeAsyncLocalCall(asyncCall *vmhost.AsyncCall)
7978 asyncCall .UpdateStatus (vmOutput .ReturnCode )
8079
8180 if isComplete {
81+ callbackGasRemaining := uint64 (0 )
8282 if asyncCall .HasCallback () {
8383 // Restore gas locked while still on the caller instance; otherwise, the
8484 // locked gas will appear to have been used twice by the caller instance.
85- isCallbackComplete , callbackVMOutput := context .ExecuteSyncCallbackAndFinishOutput (asyncCall , vmOutput , destinationCallInput , 0 , err )
85+ isCallbackComplete , callbackVMOutput := context .ExecuteLocalCallbackAndFinishOutput (asyncCall , vmOutput , destinationCallInput , 0 , err )
8686 if callbackVMOutput == nil {
8787 return vmhost .ErrAsyncNoOutputFromCallback
8888 }
8989
9090 context .host .CompleteLogEntriesWithCallType (callbackVMOutput , vmhost .AsyncCallbackString )
9191
9292 if isCallbackComplete {
93- callbackGasRemaining : = callbackVMOutput .GasRemaining
93+ callbackGasRemaining = callbackVMOutput .GasRemaining
9494 callbackVMOutput .GasRemaining = 0
95- return context .completeChild (asyncCall .CallID , callbackGasRemaining )
9695 }
97- } else {
98- return context .completeChild (asyncCall .CallID , 0 )
9996 }
97+
98+ return context .completeChild (asyncCall .CallID , callbackGasRemaining )
10099 }
101100
102101 return nil
103102}
104103
105- // ExecuteSyncCallbackAndFinishOutput executes the callback and finishes the output
106- // TODO rename to executeLocalCallbackAndFinishOutput
107- func (context * asyncContext ) ExecuteSyncCallbackAndFinishOutput (
104+ // ExecuteLocalCallbackAndFinishOutput executes the callback and finishes the output
105+ func (context * asyncContext ) ExecuteLocalCallbackAndFinishOutput (
108106 asyncCall * vmhost.AsyncCall ,
109107 vmOutput * vmcommon.VMOutput ,
110108 _ * vmcommon.ContractCallInput ,
111109 gasAccumulated uint64 ,
112110 err error ) (bool , * vmcommon.VMOutput ) {
113- callbackVMOutput , isComplete , _ := context .executeSyncCallback (asyncCall , vmOutput , gasAccumulated , err )
111+ callbackVMOutput , isComplete , _ := context .executeLocalCallback (asyncCall , vmOutput , gasAccumulated , err )
114112 context .finishAsyncLocalCallbackExecution ()
115113 return isComplete , callbackVMOutput
116114}
117115
118- // TODO rename to executeLocalCallback
119- func (context * asyncContext ) executeSyncCallback (
116+ func (context * asyncContext ) executeLocalCallback (
120117 asyncCall * vmhost.AsyncCall ,
121118 destinationVMOutput * vmcommon.VMOutput ,
122119 gasAccumulated uint64 ,
123120 destinationErr error ,
124121) (* vmcommon.VMOutput , bool , error ) {
125122 callbackInput , err := context .createCallbackInput (asyncCall , destinationVMOutput , gasAccumulated , destinationErr )
126123 if err != nil {
127- logAsync .Trace ("executeSyncCallback " , "error" , err )
124+ logAsync .Trace ("executeLocalCallback " , "error" , err )
128125 return nil , true , err
129126 }
130127
131- logAsync .Trace ("executeSyncCallback " ,
128+ logAsync .Trace ("executeLocalCallback " ,
132129 "caller" , callbackInput .CallerAddr ,
133130 "dest" , callbackInput .RecipientAddr ,
134131 "func" , callbackInput .Function ,
@@ -183,7 +180,7 @@ func (context *asyncContext) executeSyncHalfOfBuiltinFunction(asyncCall *vmhost.
183180 if vmOutput .ReturnCode != vmcommon .Ok {
184181 asyncCall .Reject ()
185182 if asyncCall .HasCallback () {
186- _ , _ , _ = context .executeSyncCallback (asyncCall , vmOutput , 0 , err )
183+ _ , _ , _ = context .executeLocalCallback (asyncCall , vmOutput , 0 , err )
187184 context .finishAsyncLocalCallbackExecution ()
188185 }
189186 }
@@ -240,7 +237,6 @@ func (context *asyncContext) createContractCallInput(asyncCall *vmhost.AsyncCall
240237 return contractCallInput , nil
241238}
242239
243- // TODO function too large; refactor needed
244240func (context * asyncContext ) createCallbackInput (
245241 asyncCall * vmhost.AsyncCall ,
246242 vmOutput * vmcommon.VMOutput ,
@@ -255,32 +251,29 @@ func (context *asyncContext) createCallbackInput(
255251 }
256252
257253 arguments := context .getArgumentsForCallback (vmOutput , destinationErr )
258-
259254 returnWithError := false
260255 if destinationErr != nil || vmOutput .ReturnCode != vmcommon .Ok {
261256 returnWithError = true
262257 }
263258
264259 callbackFunction := asyncCall .GetCallbackName ()
265-
266260 dataLength := computeDataLengthFromArguments (callbackFunction , arguments )
267261 gasLimit , err := context .computeGasLimitForCallback (asyncCall , vmOutput , dataLength )
268262 if err != nil {
269263 return nil , err
270264 }
271265
272266 originalCaller := runtime .GetOriginalCallerAddress ()
273-
274267 caller := context .address
275- lastTransferInfo := context .extractLastTransferWithoutData (caller , vmOutput )
268+ lastTransferData := context .extractLastTransferWithoutData (caller , vmOutput )
276269
277270 // Return to the sender SC, calling its specified callback method.
278271 contractCallInput := & vmcommon.ContractCallInput {
279272 VMInput : vmcommon.VMInput {
280273 OriginalCallerAddr : originalCaller ,
281274 CallerAddr : actualCallbackInitiator ,
282275 Arguments : arguments ,
283- CallValue : lastTransferInfo .callValue ,
276+ CallValue : lastTransferData .callValue ,
284277 CallType : vm .AsynchronousCallBack ,
285278 GasPrice : runtime .GetVMInput ().GasPrice ,
286279 GasProvided : gasLimit ,
@@ -289,7 +282,7 @@ func (context *asyncContext) createCallbackInput(
289282 OriginalTxHash : runtime .GetOriginalTxHash (),
290283 PrevTxHash : runtime .GetPrevTxHash (),
291284 ReturnCallAfterError : returnWithError ,
292- ESDTTransfers : lastTransferInfo .lastESDTTransfers ,
285+ ESDTTransfers : lastTransferData .lastESDTTransfers ,
293286 },
294287 RecipientAddr : caller ,
295288 Function : callbackFunction ,
0 commit comments