/// <summary> /// Returns the result after passing a script through the VM. /// This RPC call does not affect the blockchain in any way. /// </summary> public RpcInvokeResult InvokeScript(byte[] script, params UInt160[] scriptHashesForVerifying) { List <JObject> parameters = new List <JObject> { script.ToHexString() }; if (scriptHashesForVerifying.Length > 0) { parameters.Add(scriptHashesForVerifying.Select(p => (JObject)p.ToString()).ToArray()); } return(RpcInvokeResult.FromJson(RpcSend("invokescript", parameters.ToArray()))); }
/// <summary> /// Returns the result after calling a smart contract at scripthash with the given operation and parameters. /// This RPC call does not affect the blockchain in any way. /// </summary> public RpcInvokeResult InvokeFunction(string scriptHash, string operation, RpcStack[] stacks, params UInt160[] scriptHashesForVerifying) { List <JObject> parameters = new List <JObject> { scriptHash, operation, stacks.Select(p => p.ToJson()).ToArray() }; if (scriptHashesForVerifying.Length > 0) { parameters.Add(scriptHashesForVerifying.Select(p => (JObject)p.ToString()).ToArray()); } return(RpcInvokeResult.FromJson(RpcSend("invokefunction", parameters.ToArray()))); }
public static RpcInvokeResult FromJson(JObject json) { RpcInvokeResult invokeScriptResult = new RpcInvokeResult(); invokeScriptResult.Script = json["script"].AsString(); invokeScriptResult.State = json["state"].TryGetEnum <VMState>(); invokeScriptResult.GasConsumed = json["gas_consumed"].AsString(); try { invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => ContractParameter.FromJson(p)).ToArray(); } catch { } invokeScriptResult.Tx = json["tx"]?.AsString(); return(invokeScriptResult); }
private static Fixed8 GetGasConsumed(byte[] script) { RpcInvokeResult response = rpcClient.InvokeScript(script); if (Fixed8.TryParse(response.GasConsumed, out Fixed8 result)) { Fixed8 gas = result - Fixed8.FromDecimal(10); if (gas <= Fixed8.Zero) { return(Fixed8.Zero); } else { return(gas.Ceiling()); } } throw new Exception(); }