Skip to content

Commit

Permalink
Remove sender from invoke method (neo-project#368)
Browse files Browse the repository at this point in the history
* remove sender from invoke method

* fix

* format

Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com>
  • Loading branch information
2 people authored and joeqian10 committed Apr 7, 2021
1 parent a80f970 commit b0e550c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 19 deletions.
17 changes: 8 additions & 9 deletions src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void SerializeUnsigned(BinaryWriter writer)
}
}

private JObject GetInvokeResult(byte[] script, UInt160 sender = null, Signers signers = null)
private JObject GetInvokeResult(byte[] script, Signers signers = null)
{
using ApplicationEngine engine = ApplicationEngine.Run(script, container: signers, gas: settings.MaxGasInvoke);
JObject json = new JObject();
Expand All @@ -76,7 +76,7 @@ private JObject GetInvokeResult(byte[] script, UInt160 sender = null, Signers si
{
json["stack"] = "error: recursive reference";
}
ProcessInvokeWithWallet(json, sender, signers);
ProcessInvokeWithWallet(json, signers);
return json;
}

Expand All @@ -103,23 +103,22 @@ protected virtual JObject InvokeFunction(JArray _params)
UInt160 script_hash = UInt160.Parse(_params[0].AsString());
string operation = _params[1].AsString();
ContractParameter[] args = _params.Count >= 3 ? ((JArray)_params[2]).Select(p => ContractParameter.FromJson(p)).ToArray() : new ContractParameter[0];
UInt160 sender = _params.Count >= 4 ? AddressToScriptHash(_params[3].AsString()) : null;
Signers signers = _params.Count >= 5 ? SignersFromJson((JArray)_params[4]) : null;
Signers signers = _params.Count >= 4 ? SignersFromJson((JArray)_params[3]) : null;

byte[] script;
using (ScriptBuilder sb = new ScriptBuilder())
{
script = sb.EmitAppCall(script_hash, operation, args).ToArray();
}
return GetInvokeResult(script, sender, signers);
return GetInvokeResult(script, signers);
}

[RpcMethod]
protected virtual JObject InvokeScript(JArray _params)
{
byte[] script = Convert.FromBase64String(_params[0].AsString());
UInt160 sender = _params.Count >= 2 ? AddressToScriptHash(_params[1].AsString()) : null;
Signers signers = _params.Count >= 3 ? SignersFromJson((JArray)_params[2]) : null;
return GetInvokeResult(script, sender, signers);
byte[] script = _params[0].AsString().HexToBytes();
Signers signers = _params.Count >= 2 ? SignersFromJson((JArray)_params[1]) : null;
return GetInvokeResult(script, signers);
}

[RpcMethod]
Expand Down
12 changes: 2 additions & 10 deletions src/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,13 @@ protected virtual JObject OpenWallet(JArray _params)
return true;
}

private void ProcessInvokeWithWallet(JObject result, UInt160 sender = null, Signers signers = null)
private void ProcessInvokeWithWallet(JObject result, Signers signers = null)
{
Transaction tx = null;
if (wallet != null && signers != null)
{
Signer[] witnessSigners = signers.GetSigners().ToArray();
UInt160[] signersAccounts = signers.GetScriptHashesForVerifying(null);
if (sender != null)
{
if (!signersAccounts.Contains(sender))
witnessSigners = witnessSigners.Prepend(new Signer() { Account = sender, Scopes = WitnessScope.CalledByEntry }).ToArray();
else if (signersAccounts[0] != sender)
throw new RpcException(-32602, "The sender must be the first element of signers.");
}

UInt160 sender = signers.Size > 0 ? signers.GetSigners()[0].Account : null;
if (witnessSigners.Count() > 0)
{
tx = wallet.MakeTransaction(Convert.FromBase64String(result["script"].AsString()), sender, witnessSigners);
Expand Down

0 comments on commit b0e550c

Please sign in to comment.