diff --git a/src/Directory.Build.props b/src/Directory.Build.props index f571077d6..4b3679871 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -15,7 +15,7 @@ - + diff --git a/src/RpcClient/ContractClient.cs b/src/RpcClient/ContractClient.cs index 296c2e12b..280ea08a1 100644 --- a/src/RpcClient/ContractClient.cs +++ b/src/RpcClient/ContractClient.cs @@ -41,7 +41,7 @@ public ContractClient(RpcClient rpc, uint? magic = null) /// public Task TestInvokeAsync(UInt160 scriptHash, string operation, params object[] args) { - byte[] script = scriptHash.MakeScript(operation, args); + byte[] script = scriptHash.MakeScript(operation, true, args); return rpcClient.InvokeScriptAsync(script); } @@ -57,7 +57,7 @@ public async Task CreateDeployContractTxAsync(byte[] nefFile, Contr byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { - sb.EmitAppCall(NativeContract.ContractManagement.Hash, "deploy", nefFile, manifest.ToString()); + sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", true, nefFile, manifest.ToString()); script = sb.ToArray(); } UInt160 sender = Contract.CreateSignatureRedeemScript(key.PublicKey).ToScriptHash(); diff --git a/src/RpcClient/Nep17API.cs b/src/RpcClient/Nep17API.cs index 69a3b7d53..14312e841 100644 --- a/src/RpcClient/Nep17API.cs +++ b/src/RpcClient/Nep17API.cs @@ -77,9 +77,9 @@ public async Task TotalSupplyAsync(UInt160 scriptHash) public async Task GetTokenInfoAsync(UInt160 scriptHash) { byte[] script = Concat( - scriptHash.MakeScript("symbol"), - scriptHash.MakeScript("decimals"), - scriptHash.MakeScript("totalSupply")); + scriptHash.MakeScript("symbol", true), + scriptHash.MakeScript("decimals", true), + scriptHash.MakeScript("totalSupply", true)); var contractState = await rpcClient.GetContractStateAsync(scriptHash.ToString()).ConfigureAwait(false); var name = contractState.Manifest.Name; @@ -110,7 +110,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, KeyPair var sender = Contract.CreateSignatureRedeemScript(fromKey.PublicKey).ToScriptHash(); Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); @@ -137,7 +137,7 @@ public async Task CreateTransferTxAsync(UInt160 scriptHash, int m, var sender = Contract.CreateMultiSigContract(m, pubKeys).ScriptHash; Signer[] signers = new[] { new Signer { Scopes = WitnessScope.CalledByEntry, Account = sender } }; - byte[] script = scriptHash.MakeScript("transfer", sender, to, amount, data); + byte[] script = scriptHash.MakeScript("transfer", true, sender, to, amount, data); TransactionManagerFactory factory = new TransactionManagerFactory(rpcClient, magic); TransactionManager manager = await factory.MakeTransactionAsync(script, signers).ConfigureAwait(false); diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 475a12bf6..5dc4aa831 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -125,9 +125,9 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar }; using ApplicationEngine engine = ApplicationEngine.Create(TriggerType.Verification, tx, snapshot.Clone()); - engine.LoadContract(contract, methodName, CallFlags.None); + engine.LoadContract(contract, methodName, CallFlags.None, true, 0); - engine.LoadScript(new ScriptBuilder().EmitAppCall(scriptHash, methodName, args).ToArray(), CallFlags.AllowCall); + engine.LoadScript(new ScriptBuilder().EmitDynamicCall(scriptHash, methodName, true, args).ToArray()); JObject json = new JObject(); json["script"] = Convert.ToBase64String(contract.Script); @@ -169,7 +169,7 @@ protected virtual JObject InvokeFunction(JArray _params) byte[] script; using (ScriptBuilder sb = new ScriptBuilder()) { - script = sb.EmitAppCall(script_hash, operation, args).ToArray(); + script = sb.EmitDynamicCall(script_hash, operation, true, args).ToArray(); } return GetInvokeResult(script, signers); } diff --git a/tests/Neo.Network.RPC.Tests/RpcTestCases.json b/tests/Neo.Network.RPC.Tests/RpcTestCases.json index c62c64d5e..4ffadec7a 100644 --- a/tests/Neo.Network.RPC.Tests/RpcTestCases.json +++ b/tests/Neo.Network.RPC.Tests/RpcTestCases.json @@ -1135,6 +1135,33 @@ } } }, + { + "Name": "invokescriptasync", + "Request": { + "jsonrpc": "2.0", + "id": 1, + "method": "invokescript", + "params": [ + "EBEfDAhkZWNpbWFscwwU++3+LtIiZZK2SMTal7nJzV3BpqZBYn1bUg==" + ] + }, + "Response": { + "jsonrpc": "2.0", + "id": 1, + "result": { + "script": "EBEfDAhkZWNpbWFscwwU++3+LtIiZZK2SMTal7nJzV3BpqZBYn1bUg==", + "state": "HALT", + "gasconsumed": "0.0099918", + "exception": null, + "stack": [ + { + "type": "Integer", + "value": "8" + } + ] + } + } + }, { "Name": "getnewaddressasync", "Request": { diff --git a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs index 06b331595..6007d1b27 100644 --- a/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_ContractClient.cs @@ -27,7 +27,7 @@ public void TestSetup() [TestMethod] public async Task TestInvoke() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, UInt160.Zero); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.ByteArray, Value = "00e057eb481b".HexToBytes() }); ContractClient contractClient = new ContractClient(rpcClientMock.Object); @@ -55,7 +55,7 @@ public async Task TestDeployContract() }; using (ScriptBuilder sb = new ScriptBuilder()) { - sb.EmitAppCall(NativeContract.ContractManagement.Hash, "deploy", new byte[1], manifest.ToString()); + sb.EmitDynamicCall(NativeContract.ContractManagement.Hash, "deploy", true, new byte[1], manifest.ToString()); script = sb.ToArray(); } diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index a4f2d93f8..4d4582f11 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -31,7 +31,7 @@ public void TestSetup() [TestMethod] public async Task TestBalanceOf() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", UInt160.Zero); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, UInt160.Zero); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(10000) }); var balance = await nep17API.BalanceOfAsync(NativeContract.GAS.Hash, UInt160.Zero); @@ -41,7 +41,7 @@ public async Task TestBalanceOf() [TestMethod] public async Task TestGetSymbol() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("symbol"); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("symbol", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol }); var result = await nep17API.SymbolAsync(NativeContract.GAS.Hash); @@ -51,7 +51,7 @@ public async Task TestGetSymbol() [TestMethod] public async Task TestGetDecimals() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("decimals"); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("decimals", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(NativeContract.GAS.Decimals) }); var result = await nep17API.DecimalsAsync(NativeContract.GAS.Hash); @@ -61,7 +61,7 @@ public async Task TestGetDecimals() [TestMethod] public async Task TestGetTotalSupply() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("totalSupply"); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("totalSupply", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); var result = await nep17API.TotalSupplyAsync(NativeContract.GAS.Hash); @@ -72,9 +72,9 @@ public async Task TestGetTotalSupply() public async Task TestGetTokenInfo() { UInt160 scriptHash = NativeContract.GAS.Hash; - byte[] testScript = scriptHash.MakeScript("symbol") - .Concat(scriptHash.MakeScript("decimals")) - .Concat(scriptHash.MakeScript("totalSupply")) + byte[] testScript = scriptHash.MakeScript("symbol", true) + .Concat(scriptHash.MakeScript("decimals", true)) + .Concat(scriptHash.MakeScript("totalSupply", true)) .ToArray(); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.GAS.Symbol }, @@ -82,9 +82,9 @@ public async Task TestGetTokenInfo() new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); scriptHash = NativeContract.NEO.Hash; - testScript = scriptHash.MakeScript("symbol") - .Concat(scriptHash.MakeScript("decimals")) - .Concat(scriptHash.MakeScript("totalSupply")) + testScript = scriptHash.MakeScript("symbol", true) + .Concat(scriptHash.MakeScript("decimals", true)) + .Concat(scriptHash.MakeScript("totalSupply", true)) .ToArray(); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.String, Value = NativeContract.NEO.Symbol }, @@ -120,12 +120,12 @@ public async Task TestGetTokenInfo() [TestMethod] public async Task TestTransfer() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000), null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter()); var result = await nep17API.CreateTransferTxAsync(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000)); - testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, new BigInteger(1_00000000), string.Empty); + testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, new BigInteger(1_00000000), string.Empty); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter()); result = await nep17API.CreateTransferTxAsync(NativeContract.GAS.Hash, keyPair1, UInt160.Zero, new BigInteger(1_00000000), string.Empty); diff --git a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs index 245636e93..9a32320de 100644 --- a/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_PolicyAPI.cs @@ -29,7 +29,7 @@ public void TestSetup() [TestMethod] public async Task TestGetMaxTransactionsPerBlock() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxTransactionsPerBlock"); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxTransactionsPerBlock", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(512) }); var result = await policyAPI.GetMaxTransactionsPerBlockAsync(); @@ -39,7 +39,7 @@ public async Task TestGetMaxTransactionsPerBlock() [TestMethod] public async Task TestGetMaxBlockSize() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxBlockSize"); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getMaxBlockSize", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1024u * 256u) }); var result = await policyAPI.GetMaxBlockSizeAsync(); @@ -49,7 +49,7 @@ public async Task TestGetMaxBlockSize() [TestMethod] public async Task TestGetFeePerByte() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1000) }); var result = await policyAPI.GetFeePerByteAsync(); @@ -59,7 +59,7 @@ public async Task TestGetFeePerByte() [TestMethod] public async Task TestIsBlocked() { - byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", UInt160.Zero); + byte[] testScript = NativeContract.Policy.Hash.MakeScript("isBlocked", true, UInt160.Zero); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Boolean, Value = true }); var result = await policyAPI.IsBlockedAsync(UInt160.Zero); Assert.AreEqual(true, result); diff --git a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs index bc740fd1c..06010849a 100644 --- a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs +++ b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs @@ -54,13 +54,13 @@ public static Mock MockRpcClient(UInt160 sender, byte[] script) .Verifiable(); // MockGasBalance - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", sender); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, sender); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; MockInvokeScript(mockRpc, balanceScript, balanceResult); // MockFeePerByte - byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); + byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); var policyResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("1000") }; MockInvokeScript(mockRpc, policyScript, policyResult); @@ -87,13 +87,13 @@ public static Mock MockMultiSig(UInt160 multiHash, byte[] script) .Verifiable(); // MockGasBalance - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", multiHash); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, multiHash); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; MockInvokeScript(mockRpc, balanceScript, balanceResult); // MockFeePerByte - byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte"); + byte[] policyScript = NativeContract.Policy.Hash.MakeScript("getFeePerByte", true); var policyResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("1000") }; MockInvokeScript(mockRpc, policyScript, policyResult); diff --git a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs index 7ec348ebe..594f02654 100644 --- a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs @@ -36,7 +36,7 @@ public void TestSetup() [TestMethod] public async Task TestGetUnclaimedGas() { - byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", sender, 99); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("unclaimedGas", true, sender, 99); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetUnclaimedGasAsync(address1); @@ -46,7 +46,7 @@ public async Task TestGetUnclaimedGas() [TestMethod] public async Task TestGetNeoBalance() { - byte[] testScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("balanceOf", true, sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); var balance = await walletAPI.GetNeoBalanceAsync(address1); @@ -56,7 +56,7 @@ public async Task TestGetNeoBalance() [TestMethod] public async Task TestGetGasBalance() { - byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", sender); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetGasBalanceAsync(address1); @@ -66,7 +66,7 @@ public async Task TestGetGasBalance() [TestMethod] public async Task TestGetTokenBalance() { - byte[] testScript = UInt160.Zero.MakeScript("balanceOf", sender); + byte[] testScript = UInt160.Zero.MakeScript("balanceOf", true, sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var balance = await walletAPI.GetTokenBalanceAsync(UInt160.Zero.ToString(), address1); @@ -76,10 +76,10 @@ public async Task TestGetTokenBalance() [TestMethod] public async Task TestClaimGas() { - byte[] balanceScript = NativeContract.NEO.Hash.MakeScript("balanceOf", sender); + byte[] balanceScript = NativeContract.NEO.Hash.MakeScript("balanceOf", true, sender); UT_TransactionManager.MockInvokeScript(rpcClientMock, balanceScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_00000000) }); - byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", sender, sender, new BigInteger(1_00000000), null); + byte[] testScript = NativeContract.NEO.Hash.MakeScript("transfer", true, sender, sender, new BigInteger(1_00000000), null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -93,10 +93,10 @@ public async Task TestClaimGas() [TestMethod] public async Task TestTransfer() { - byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); + byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", sender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, sender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -110,15 +110,15 @@ public async Task TestTransfer() [TestMethod] public async Task TestTransferfromMultiSigAccount() { - byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", multiSender); + byte[] balanceScript = NativeContract.GAS.Hash.MakeScript("balanceOf", true, multiSender); var balanceResult = new ContractParameter() { Type = ContractParameterType.Integer, Value = BigInteger.Parse("10000000000000000") }; UT_TransactionManager.MockInvokeScript(rpcClientMock, balanceScript, balanceResult); - byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals"); + byte[] decimalsScript = NativeContract.GAS.Hash.MakeScript("decimals", true); UT_TransactionManager.MockInvokeScript(rpcClientMock, decimalsScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(8) }); - byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); + byte[] testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, null); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); var json = new JObject(); @@ -138,7 +138,7 @@ public async Task TestTransferfromMultiSigAccount() Assert.AreEqual(e.Message, $"Need at least 2 KeyPairs for signing!"); } - testScript = NativeContract.GAS.Hash.MakeScript("transfer", multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty); + testScript = NativeContract.GAS.Hash.MakeScript("transfer", true, multiSender, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty); UT_TransactionManager.MockInvokeScript(rpcClientMock, testScript, new ContractParameter { Type = ContractParameterType.Integer, Value = new BigInteger(1_10000000) }); tranaction = await walletAPI.TransferAsync(NativeContract.GAS.Hash, 1, new[] { keyPair1.PublicKey }, new[] { keyPair1 }, UInt160.Zero, NativeContract.GAS.Factor * 100, string.Empty);