From 1932922452e48c53b1712831fe6647b80262b060 Mon Sep 17 00:00:00 2001 From: Hecate2 <2474101468@qq.com> Date: Tue, 10 Sep 2024 17:00:26 +0800 Subject: [PATCH] DebugScriptWithSession --- Fairy.Debugger.cs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/Fairy.Debugger.cs b/Fairy.Debugger.cs index 422dbfb..99341ca 100644 --- a/Fairy.Debugger.cs +++ b/Fairy.Debugger.cs @@ -55,6 +55,32 @@ protected virtual JToken DebugFunctionWithSession(JArray _params) return DumpDebugResultJson(newEngine, breakReason); } + [RpcMethod] + protected virtual JToken DebugScriptWithSession(JArray _params) + { + string session = _params[0]!.AsString(); + bool writeSnapshot = _params[1]!.AsBoolean(); + byte[] script = Convert.FromBase64String(_params[2]!.AsString()); + Signer[]? signers = _params.Count >= 4 ? SignersFromJson((JArray)_params[3]!, system.Settings) : null; + Witness[]? witnesses = _params.Count >= 5 ? WitnessesFromJson((JArray)_params[4]!) : null; + Transaction? tx = signers == null ? null : new Transaction + { + Signers = signers, + Attributes = System.Array.Empty(), + Witnesses = witnesses, + }; + FairySession testSession = GetOrCreateFairySession(session); + FairyEngine newEngine; + logs.Clear(); + FairyEngine.Log += CacheLog!; + BreakReason breakReason = BreakReason.None; + newEngine = DebugRun(script, testSession.engine.Snapshot.CreateSnapshot(), out breakReason, container: tx, settings: system.Settings, gas: settings.MaxGasInvoke, oldEngine: testSession.engine); + FairyEngine.Log -= CacheLog!; + if (writeSnapshot) + sessionStringToFairySession[session].debugEngine = newEngine; + return DumpDebugResultJson(newEngine, breakReason); + } + [RpcMethod] protected virtual JToken DebugContinue(JArray _params) {