Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CheckWitness on invokescript #1122

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 53 additions & 5 deletions neo/Network/RPC/RpcServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,49 @@ namespace Neo.Network.RPC
{
public sealed class RpcServer : IDisposable
{
public Wallet Wallet { get; set; }
private class CheckWitnessHashes : IVerifiable
{
private readonly UInt160[] _scriptHashesForVerifying;
public Witness[] Witnesses { get; set; }
public int Size { get; }

public CheckWitnessHashes(UInt160[] scriptHashesForVerifying)
{
_scriptHashesForVerifying = scriptHashesForVerifying;
}

public void Serialize(BinaryWriter writer)
{
throw new NotImplementedException();
}

public void Deserialize(BinaryReader reader)
{
throw new NotImplementedException();
}

public void DeserializeUnsigned(BinaryReader reader)
{
throw new NotImplementedException();
}

public UInt160[] GetScriptHashesForVerifying(Snapshot snapshot)
{
return _scriptHashesForVerifying;
}

public void SerializeUnsigned(BinaryWriter writer)
{
throw new NotImplementedException();
}

public byte[] GetMessage()
{
throw new NotImplementedException();
}
}

public Wallet Wallet { get; set; }
public Fixed8 MaxGasInvoke { get; }

private IWebHost host;
Expand Down Expand Up @@ -71,9 +113,9 @@ public void Dispose()
}
}

private JObject GetInvokeResult(byte[] script)
private JObject GetInvokeResult(byte[] script, IVerifiable checkWitnessHashes = null)
{
ApplicationEngine engine = ApplicationEngine.Run(script, extraGAS: MaxGasInvoke);
ApplicationEngine engine = ApplicationEngine.Run(script, checkWitnessHashes, extraGAS: MaxGasInvoke);
JObject json = new JObject();
json["script"] = script.ToHexString();
json["state"] = engine.State;
Expand Down Expand Up @@ -219,8 +261,14 @@ private JObject Process(string method, JArray _params)
case "invokescript":
{
byte[] script = _params[0].AsString().HexToBytes();
return InvokeScript(script);
}
CheckWitnessHashes checkWitnessHashes = null;
if (_params.Count > 1)
{
UInt160[] scriptHashesForVerifying = _params.Skip(1).Select(u => UInt160.Parse(u.AsString())).ToArray();
checkWitnessHashes = new CheckWitnessHashes(scriptHashesForVerifying);
}
return GetInvokeResult(script, checkWitnessHashes);
}
case "listplugins":
{
return ListPlugins();
Expand Down