@@ -117,20 +117,23 @@ public void Dispose()
117117
118118 private JObject GetInvokeResult ( byte [ ] script , IVerifiable checkWitnessHashes = null )
119119 {
120- ApplicationEngine engine = ApplicationEngine . Run ( script , checkWitnessHashes , extraGAS : MaxGasInvoke ) ;
121- JObject json = new JObject ( ) ;
122- json [ "script" ] = script . ToHexString ( ) ;
123- json [ "state" ] = engine . State ;
124- json [ "gas_consumed" ] = engine . GasConsumed . ToString ( ) ;
125- try
120+ using ( ApplicationEngine engine = ApplicationEngine . Run ( script , checkWitnessHashes , extraGAS : MaxGasInvoke ) )
126121 {
127- json [ "stack" ] = new JArray ( engine . ResultStack . Select ( p => p . ToParameter ( ) . ToJson ( ) ) ) ;
128- }
129- catch ( InvalidOperationException )
130- {
131- json [ "stack" ] = "error: recursive reference" ;
122+ JObject json = new JObject ( ) ;
123+ json [ "script" ] = script . ToHexString ( ) ;
124+ json [ "state" ] = engine . State ;
125+ json [ "gas_consumed" ] = engine . GasConsumed . ToString ( ) ;
126+ try
127+ {
128+ json [ "stack" ] = new JArray ( engine . ResultStack . Select ( p => p . ToParameter ( ) . ToJson ( ) ) ) ;
129+ }
130+ catch ( InvalidOperationException )
131+ {
132+ json [ "stack" ] = "error: recursive reference" ;
133+ }
134+
135+ return json ;
132136 }
133- return json ;
134137 }
135138
136139 private static JObject GetRelayResult ( RelayResultReason reason )
@@ -251,14 +254,26 @@ private JObject Process(string method, JArray _params)
251254 {
252255 UInt160 script_hash = UInt160 . Parse ( _params [ 0 ] . AsString ( ) ) ;
253256 ContractParameter [ ] parameters = ( ( JArray ) _params [ 1 ] ) . Select ( p => ContractParameter . FromJson ( p ) ) . ToArray ( ) ;
254- return Invoke ( script_hash , parameters ) ;
257+ CheckWitnessHashes checkWitnessHashes = null ;
258+ if ( _params . Count > 2 )
259+ {
260+ UInt160 [ ] scriptHashesForVerifying = _params . Skip ( 2 ) . Select ( u => UInt160 . Parse ( u . AsString ( ) ) ) . ToArray ( ) ;
261+ checkWitnessHashes = new CheckWitnessHashes ( scriptHashesForVerifying ) ;
262+ }
263+ return Invoke ( script_hash , parameters , checkWitnessHashes ) ;
255264 }
256265 case "invokefunction" :
257266 {
258267 UInt160 script_hash = UInt160 . Parse ( _params [ 0 ] . AsString ( ) ) ;
259268 string operation = _params [ 1 ] . AsString ( ) ;
260269 ContractParameter [ ] args = _params . Count >= 3 ? ( ( JArray ) _params [ 2 ] ) . Select ( p => ContractParameter . FromJson ( p ) ) . ToArray ( ) : new ContractParameter [ 0 ] ;
261- return InvokeFunction ( script_hash , operation , args ) ;
270+ CheckWitnessHashes checkWitnessHashes = null ;
271+ if ( _params . Count > 3 )
272+ {
273+ UInt160 [ ] scriptHashesForVerifying = _params . Skip ( 3 ) . Select ( u => UInt160 . Parse ( u . AsString ( ) ) ) . ToArray ( ) ;
274+ checkWitnessHashes = new CheckWitnessHashes ( scriptHashesForVerifying ) ;
275+ }
276+ return InvokeFunction ( script_hash , operation , args , checkWitnessHashes ) ;
262277 }
263278 case "invokescript" :
264279 {
@@ -269,7 +284,7 @@ private JObject Process(string method, JArray _params)
269284 UInt160 [ ] scriptHashesForVerifying = _params . Skip ( 1 ) . Select ( u => UInt160 . Parse ( u . AsString ( ) ) ) . ToArray ( ) ;
270285 checkWitnessHashes = new CheckWitnessHashes ( scriptHashesForVerifying ) ;
271286 }
272- return InvokeScript ( script ) ;
287+ return InvokeScript ( script , checkWitnessHashes ) ;
273288 }
274289 case "listplugins" :
275290 {
@@ -666,29 +681,29 @@ private JObject GetVersion()
666681 return json ;
667682 }
668683
669- private JObject Invoke ( UInt160 script_hash , ContractParameter [ ] parameters )
684+ private JObject Invoke ( UInt160 script_hash , ContractParameter [ ] parameters , IVerifiable checkWitnessHashes = null )
670685 {
671686 byte [ ] script ;
672687 using ( ScriptBuilder sb = new ScriptBuilder ( ) )
673688 {
674689 script = sb . EmitAppCall ( script_hash , parameters ) . ToArray ( ) ;
675690 }
676- return GetInvokeResult ( script ) ;
691+ return GetInvokeResult ( script , checkWitnessHashes ) ;
677692 }
678693
679- private JObject InvokeFunction ( UInt160 script_hash , string operation , ContractParameter [ ] args )
694+ private JObject InvokeFunction ( UInt160 script_hash , string operation , ContractParameter [ ] args , IVerifiable checkWitnessHashes = null )
680695 {
681696 byte [ ] script ;
682697 using ( ScriptBuilder sb = new ScriptBuilder ( ) )
683698 {
684699 script = sb . EmitAppCall ( script_hash , operation , args ) . ToArray ( ) ;
685700 }
686- return GetInvokeResult ( script ) ;
701+ return GetInvokeResult ( script , checkWitnessHashes ) ;
687702 }
688703
689- private JObject InvokeScript ( byte [ ] script )
704+ private JObject InvokeScript ( byte [ ] script , IVerifiable checkWitnessHashes = null )
690705 {
691- return GetInvokeResult ( script ) ;
706+ return GetInvokeResult ( script , checkWitnessHashes ) ;
692707 }
693708
694709 private JObject ListPlugins ( )
0 commit comments