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

invoke* use base64 script #362

Merged
merged 13 commits into from
Oct 16, 2020
2 changes: 1 addition & 1 deletion src/RpcClient/RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public RpcInvokeResult InvokeFunction(string scriptHash, string operation, RpcSt
/// </summary>
public RpcInvokeResult InvokeScript(byte[] script, params Signer[] signers)
{
List<JObject> parameters = new List<JObject> { script.ToHexString() };
List<JObject> parameters = new List<JObject> { Convert.ToBase64String(script) };
if (signers.Length > 0)
{
parameters.Add(signers.Select(p => p.ToJson()).ToArray());
Expand Down
4 changes: 2 additions & 2 deletions src/RpcServer/RpcServer.SmartContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private JObject GetInvokeResult(byte[] script, UInt160 sender = null, Signers si
{
using ApplicationEngine engine = ApplicationEngine.Run(script, container: signers, gas: settings.MaxGasInvoke);
JObject json = new JObject();
json["script"] = script.ToHexString();
json["script"] = Convert.ToBase64String(script);
json["state"] = engine.State;
json["gasconsumed"] = engine.GasConsumed.ToString();
try
Expand Down Expand Up @@ -116,7 +116,7 @@ private JObject InvokeFunction(JArray _params)
[RpcMethod]
private JObject InvokeScript(JArray _params)
{
byte[] script = _params[0].AsString().HexToBytes();
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);
Expand Down
5 changes: 0 additions & 5 deletions src/RpcServer/RpcServer.Wallet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -341,11 +341,6 @@ private JObject SignAndRelay(Transaction tx)

internal static UInt160 AddressToScriptHash(string address)
{
if (UInt160.TryParse(address, out var scriptHash))
Tommo-L marked this conversation as resolved.
Show resolved Hide resolved
{
return scriptHash;
}

return address.ToScriptHash();
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/Neo.Network.RPC.Tests/RpcTestCases.json
Original file line number Diff line number Diff line change
Expand Up @@ -746,14 +746,14 @@
"Request": {
"jsonrpc": "2.0",
"method": "invokescript",
"params": [ "10c30c046e616d650c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0673796d626f6c0c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c08646563696d616c730c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0b746f74616c537570706c790c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52" ],
"params": [ "EMMMBG5hbWUMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1IQwwwGc3ltYm9sDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtSEMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtSEMMMC3RvdGFsU3VwcGx5DBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS" ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"script": "10c30c046e616d650c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0673796d626f6c0c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c08646563696d616c730c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b5210c30c0b746f74616c537570706c790c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52",
"script": "EMMMBG5hbWUMFDt9NxHG8Mz5sdypA9G/odiW8SOMQWJ9W1IQwwwGc3ltYm9sDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtSEMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtSEMMMC3RvdGFsU3VwcGx5DBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS",
"state": "HALT",
"gasconsumed": "5061560",
"stack": [
Expand Down Expand Up @@ -932,14 +932,14 @@
"Request": {
"jsonrpc": "2.0",
"method": "invokescript",
"params": [ "10c30c08646563696d616c730c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52" ],
"params": [ "EMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS" ],
"id": 1
},
"Response": {
"jsonrpc": "2.0",
"id": 1,
"result": {
"script": "10c30c08646563696d616c730c143b7d3711c6f0ccf9b1dca903d1bfa1d896f1238c41627d5b52",
"script": "EMMMCGRlY2ltYWxzDBQ7fTcRxvDM+bHcqQPRv6HYlvEjjEFifVtS",
"state": "HALT",
"gasconsumed": "5061560",
"stack": [
Expand Down
2 changes: 1 addition & 1 deletion tests/Neo.Network.RPC.Tests/UT_RpcClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ public void TestInvokeFunction()
public void TestInvokeScript()
{
var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.InvokeScript).ToLower());
var result = rpc.InvokeScript(test.Request.Params[0].AsString().HexToBytes());
var result = rpc.InvokeScript(Convert.FromBase64String(test.Request.Params[0].AsString()));
Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString());
}

Expand Down
5 changes: 2 additions & 3 deletions tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
using Neo.SmartContract.Native;
using Neo.VM;
using Neo.Wallets;
using Neo.Wallets.NEP6;
using System;
using System.Linq;
using System.Numerics;
Expand Down Expand Up @@ -111,11 +110,11 @@ public static void MockInvokeScript(Mock<RpcClient> mockClient, byte[] script, p
{
Stack = parameters.Select(p => p.ToStackItem()).ToArray(),
GasConsumed = "100",
Script = script.ToHexString(),
Script = Convert.ToBase64String(script),
State = VMState.HALT
};

mockClient.Setup(p => p.RpcSend("invokescript", It.Is<JObject[]>(j => j[0].AsString() == script.ToHexString())))
mockClient.Setup(p => p.RpcSend("invokescript", It.Is<JObject[]>(j => j[0].AsString() == Convert.ToBase64String(script))))
.Returns(result.ToJson())
.Verifiable();
}
Expand Down