@@ -154,6 +154,7 @@ class Functions {
154154 const timestamp = _ . get ( options , 'timestamp' , null ) ;
155155 const blockNumber = _ . get ( options , 'blockNumber' , null ) ;
156156 const blockTime = _ . get ( options , 'blockTime' , null ) ;
157+ const eventSource = _ . get ( options , 'eventSource' , null ) ;
157158 let triggerCount = 0 ;
158159 let failCount = 0 ;
159160 const promises = [ ] ;
@@ -190,7 +191,6 @@ class Functions {
190191 const newAuth = Object . assign (
191192 { } , auth , { fid : functionEntry . function_id , fids : this . getFids ( ) } ) ;
192193 let result = null ;
193- const eventSource = _ . get ( options , 'eventSource' , null ) ;
194194 try {
195195 result = nativeFunction . func (
196196 value ,
@@ -208,11 +208,11 @@ class Functions {
208208 blockNumber,
209209 blockTime,
210210 options,
211+ eventSource,
211212 auth : newAuth ,
212213 opResultList : [ ] ,
213214 otherGasAmount : 0 ,
214215 ...blockchainParams ,
215- eventSource,
216216 } ) ;
217217 funcResults [ functionEntry . function_id ] = result ;
218218 if ( DevFlags . enableRichFunctionLogging ) {
@@ -236,51 +236,64 @@ class Functions {
236236 }
237237 }
238238 } else if ( functionEntry . function_type === FunctionTypes . REST ) {
239- if ( NodeConfigs . ENABLE_REST_FUNCTION_CALL && functionEntry . function_url &&
240- CommonUtil . isWhitelistedUrl ( functionEntry . function_url , this . db . getRestFunctionsUrlWhitelist ( ) ) ) {
241- if ( DevFlags . enableRichFunctionLogging ) {
239+ // NOTE: Skipped when the event source is null.
240+ if ( NodeConfigs . ENABLE_REST_FUNCTION_CALL &&
241+ eventSource !== null &&
242+ functionEntry . function_url ) {
243+ const restFunctionUrlWhitelist = this . db . getRestFunctionsUrlWhitelist ( ) ;
244+ if ( ! CommonUtil . isWhitelistedUrl ( functionEntry . function_url , restFunctionUrlWhitelist ) ) {
245+ // NOTE: Skipped when the function url is not in the whitelist.
242246 logger . info (
243- ` ==> Triggering REST function [[ ${ functionEntry . function_id } ]] of ` +
244- `function_url '${ functionEntry . function_url } ' with:\n` +
247+ `Skipped triggering REST function [[ ${ functionEntry . function_id } ]] of ` +
248+ `function_url '${ functionEntry . function_url } ' which is NOT in the whitelist: \n` +
249+ `${ JSON . stringify ( restFunctionUrlWhitelist ) } ` +
245250 formattedParams ) ;
246- }
247- const newAuth = Object . assign (
248- { } , auth , { fid : functionEntry . function_id , fids : this . getFids ( ) } ) ;
249- promises . push ( axios . post ( functionEntry . function_url , {
250- fid : functionEntry . function_id ,
251- function : functionEntry ,
252- valuePath,
253- functionPath,
254- value,
255- prevValue,
256- params,
257- timestamp,
258- executedAt,
259- transaction,
260- blockNumber,
261- blockTime,
262- options,
263- auth : newAuth ,
264- chainId : blockchainParams . chainId ,
265- networkId : blockchainParams . networkId ,
266- } , {
267- timeout : NodeConfigs . REST_FUNCTION_CALL_TIMEOUT_MS
268- } ) . catch ( ( error ) => {
251+ } else {
269252 if ( DevFlags . enableRichFunctionLogging ) {
270- logger . error (
271- `Failed to trigger REST function [[ ${ functionEntry . function_id } ]] of ` +
272- `function_url '${ functionEntry . function_url } ' with error: \n` +
273- `${ JSON . stringify ( error ) } ` +
253+ logger . info (
254+ ` ==> Triggering REST function [[ ${ functionEntry . function_id } ]] of ` +
255+ `function_url '${ functionEntry . function_url } ' with:\n` +
274256 formattedParams ) ;
275257 }
276- failCount ++ ;
277- return true ;
278- } ) ) ;
279- funcResults [ functionEntry . function_id ] = {
280- code : FunctionResultCode . SUCCESS ,
281- bandwidth_gas_amount : blockchainParams . restFunctionCallGasAmount ,
282- } ;
283- triggerCount ++ ;
258+ const newAuth = Object . assign (
259+ { } , auth , { fid : functionEntry . function_id , fids : this . getFids ( ) } ) ;
260+ promises . push ( axios . post ( functionEntry . function_url , {
261+ fid : functionEntry . function_id ,
262+ function : functionEntry ,
263+ valuePath,
264+ functionPath,
265+ value,
266+ prevValue,
267+ params,
268+ timestamp,
269+ executedAt,
270+ transaction,
271+ blockNumber,
272+ blockTime,
273+ options,
274+ eventSource,
275+ auth : newAuth ,
276+ chainId : blockchainParams . chainId ,
277+ networkId : blockchainParams . networkId ,
278+ } , {
279+ timeout : NodeConfigs . REST_FUNCTION_CALL_TIMEOUT_MS
280+ } ) . catch ( ( error ) => {
281+ if ( DevFlags . enableRichFunctionLogging ) {
282+ logger . error (
283+ `Failed to trigger REST function [[ ${ functionEntry . function_id } ]] of ` +
284+ `function_url '${ functionEntry . function_url } ' with error: \n` +
285+ `${ JSON . stringify ( error ) } ` +
286+ formattedParams ) ;
287+ }
288+ failCount ++ ;
289+ return true ;
290+ } ) ) ;
291+ funcResults [ functionEntry . function_id ] = {
292+ code : FunctionResultCode . SUCCESS ,
293+ bandwidth_gas_amount : blockchainParams . restFunctionCallGasAmount ,
294+ } ;
295+ triggerCount ++ ;
296+ }
284297 }
285298 }
286299 }
0 commit comments