diff --git a/src/ApplicationLogs/LogReader.cs b/src/ApplicationLogs/LogReader.cs index 35b38f0b1..a2b5c4668 100644 --- a/src/ApplicationLogs/LogReader.cs +++ b/src/ApplicationLogs/LogReader.cs @@ -10,7 +10,7 @@ using Neo.IO; using Neo.IO.Data.LevelDB; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -57,14 +57,14 @@ protected override void OnSystemLoaded(NeoSystem system) } [RpcMethod] - public JObject GetApplicationLog(JArray _params) + public JToken GetApplicationLog(JArray _params) { UInt256 hash = UInt256.Parse(_params[0].AsString()); byte[] value = db.Get(ReadOptions.Default, hash.ToArray()); if (value is null) throw new RpcException(-100, "Unknown transaction/blockhash"); - var raw = JObject.Parse(Neo.Utility.StrictUTF8.GetString(value)); + JObject raw = (JObject)JToken.Parse(Neo.Utility.StrictUTF8.GetString(value)); //Additional optional "trigger" parameter to getapplicationlog for clients to be able to get just one execution result for a block. if (_params.Count >= 2 && Enum.TryParse(_params[1].AsString(), true, out TriggerType trigger)) { @@ -115,7 +115,7 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) return notification; }).ToArray(); - txJson["executions"] = new List() { trigger }.ToArray(); + txJson["executions"] = new[] { trigger }; return txJson; } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 43b09706d..ae4798497 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -2,7 +2,7 @@ - 3.3.1 + 3.4.0 net6.0 Neo.Plugins The Neo Project @@ -21,7 +21,7 @@ - + diff --git a/src/OracleService/OracleService.cs b/src/OracleService/OracleService.cs index f5b737a6d..bdc759ce1 100644 --- a/src/OracleService/OracleService.cs +++ b/src/OracleService/OracleService.cs @@ -14,7 +14,7 @@ using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; @@ -507,7 +507,7 @@ public static byte[] Filter(string input, string filterArgs) if (string.IsNullOrEmpty(filterArgs)) return Utility.StrictUTF8.GetBytes(input); - JObject beforeObject = JObject.Parse(input); + JToken beforeObject = JToken.Parse(input); JArray afterObjects = beforeObject.JsonPath(filterArgs); return afterObjects.ToByteArray(false); } diff --git a/src/OracleService/OracleService.csproj b/src/OracleService/OracleService.csproj index fae818cc8..92adaf45c 100644 --- a/src/OracleService/OracleService.csproj +++ b/src/OracleService/OracleService.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/OracleService/Protocols/OracleNeoFSProtocol.cs b/src/OracleService/Protocols/OracleNeoFSProtocol.cs index 5f2f7af79..fc1511fb2 100644 --- a/src/OracleService/Protocols/OracleNeoFSProtocol.cs +++ b/src/OracleService/Protocols/OracleNeoFSProtocol.cs @@ -12,7 +12,6 @@ using Neo.FileStorage.API.Client; using Neo.FileStorage.API.Cryptography; using Neo.FileStorage.API.Refs; -using Neo.IO.Json; using Neo.Network.P2P.Payloads; using Neo.Wallets; using System; @@ -112,7 +111,7 @@ private static async Task GetRangeAsync(Client client, Address addr, str private static async Task GetHeaderAsync(Client client, Address addr, CancellationToken cancellation) { var obj = await client.GetObjectHeader(addr, options: new CallOptions { Ttl = 2 }, context: cancellation); - return obj.ToJson().ToString(); + return obj.ToString(); } private static async Task GetHashAsync(Client client, Address addr, string[] ps, CancellationToken cancellation) diff --git a/src/RocksDBStore/RocksDBStore.csproj b/src/RocksDBStore/RocksDBStore.csproj index 2638314f8..2babadc61 100644 --- a/src/RocksDBStore/RocksDBStore.csproj +++ b/src/RocksDBStore/RocksDBStore.csproj @@ -6,7 +6,7 @@ - + diff --git a/src/RpcClient/Models/RpcAccount.cs b/src/RpcClient/Models/RpcAccount.cs index ab396279a..d38e446ea 100644 --- a/src/RpcClient/Models/RpcAccount.cs +++ b/src/RpcClient/Models/RpcAccount.cs @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 9f2041d10..29e22c8e6 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using Neo.VM; using Neo.VM.Types; @@ -42,7 +42,7 @@ public static RpcApplicationLog FromJson(JObject json, ProtocolSettings protocol { TxId = json["txid"] is null ? null : UInt256.Parse(json["txid"].AsString()), BlockHash = json["blockhash"] is null ? null : UInt256.Parse(json["blockhash"].AsString()), - Executions = ((JArray)json["executions"]).Select(p => Execution.FromJson(p, protocolSettings)).ToList(), + Executions = ((JArray)json["executions"]).Select(p => Execution.FromJson((JObject)p, protocolSettings)).ToList(), }; } } @@ -77,12 +77,12 @@ public static Execution FromJson(JObject json, ProtocolSettings protocolSettings { return new Execution { - Trigger = json["trigger"].TryGetEnum(), - VMState = json["vmstate"].TryGetEnum(), + Trigger = json["trigger"].GetEnum(), + VMState = json["vmstate"].GetEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), ExceptionMessage = json["exception"]?.AsString(), - Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).ToList(), - Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson(p, protocolSettings)).ToList() + Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson((JObject)p)).ToList(), + Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson((JObject)p, protocolSettings)).ToList() }; } } @@ -110,7 +110,7 @@ public static RpcNotifyEventArgs FromJson(JObject json, ProtocolSettings protoco { Contract = json["contract"].ToScriptHash(protocolSettings), EventName = json["eventname"].AsString(), - State = Utility.StackItemFromJson(json["state"]) + State = Utility.StackItemFromJson((JObject)json["state"]) }; } } diff --git a/src/RpcClient/Models/RpcBlock.cs b/src/RpcClient/Models/RpcBlock.cs index bcc9fe904..29182175b 100644 --- a/src/RpcClient/Models/RpcBlock.cs +++ b/src/RpcClient/Models/RpcBlock.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models diff --git a/src/RpcClient/Models/RpcBlockHeader.cs b/src/RpcClient/Models/RpcBlockHeader.cs index 8ef1f4dd6..3508ef601 100644 --- a/src/RpcClient/Models/RpcBlockHeader.cs +++ b/src/RpcClient/Models/RpcBlockHeader.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models diff --git a/src/RpcClient/Models/RpcContractState.cs b/src/RpcClient/Models/RpcContractState.cs index def5fba55..ce68831f3 100644 --- a/src/RpcClient/Models/RpcContractState.cs +++ b/src/RpcClient/Models/RpcContractState.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using Neo.SmartContract.Manifest; @@ -32,8 +32,8 @@ public static RpcContractState FromJson(JObject json) Id = (int)json["id"].AsNumber(), UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Nef = RpcNefFile.FromJson(json["nef"]), - Manifest = ContractManifest.FromJson(json["manifest"]) + Nef = RpcNefFile.FromJson((JObject)json["nef"]), + Manifest = ContractManifest.FromJson((JObject)json["manifest"]) } }; } diff --git a/src/RpcClient/Models/RpcFoundStates.cs b/src/RpcClient/Models/RpcFoundStates.cs index 755d771c8..c72fc5c6c 100644 --- a/src/RpcClient/Models/RpcFoundStates.cs +++ b/src/RpcClient/Models/RpcFoundStates.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,9 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Neo.Json; using System; using System.Linq; -using Neo.IO.Json; namespace Neo.Network.RPC.Models { @@ -32,12 +32,12 @@ public static RpcFoundStates FromJson(JObject json) Convert.FromBase64String(j["value"].AsString()) )) .ToArray(), - FirstProof = ProofFromJson(json["firstProof"]), - LastProof = ProofFromJson(json["lastProof"]), + FirstProof = ProofFromJson((JString)json["firstProof"]), + LastProof = ProofFromJson((JString)json["lastProof"]), }; } - static byte[] ProofFromJson(JObject json) + static byte[] ProofFromJson(JString json) => json == null ? null : Convert.FromBase64String(json.AsString()); } } diff --git a/src/RpcClient/Models/RpcInvokeResult.cs b/src/RpcClient/Models/RpcInvokeResult.cs index 4516b5923..faf436e8f 100644 --- a/src/RpcClient/Models/RpcInvokeResult.cs +++ b/src/RpcClient/Models/RpcInvokeResult.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.VM; using Neo.VM.Types; using System; @@ -58,14 +58,14 @@ public static RpcInvokeResult FromJson(JObject json) RpcInvokeResult invokeScriptResult = new() { Script = json["script"].AsString(), - State = json["state"].TryGetEnum(), + State = json["state"].GetEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), }; invokeScriptResult.Exception = json["exception"]?.AsString(); invokeScriptResult.Session = json["session"]?.AsString(); try { - invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).ToArray(); + invokeScriptResult.Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson((JObject)p)).ToArray(); } catch { } invokeScriptResult.Tx = json["tx"]?.AsString(); diff --git a/src/RpcClient/Models/RpcMethodToken.cs b/src/RpcClient/Models/RpcMethodToken.cs index 7734678b0..64325b103 100644 --- a/src/RpcClient/Models/RpcMethodToken.cs +++ b/src/RpcClient/Models/RpcMethodToken.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using System; diff --git a/src/RpcClient/Models/RpcNativeContract.cs b/src/RpcClient/Models/RpcNativeContract.cs index 996611635..3edc9a71a 100644 --- a/src/RpcClient/Models/RpcNativeContract.cs +++ b/src/RpcClient/Models/RpcNativeContract.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using Neo.SmartContract.Manifest; using System.Linq; @@ -29,9 +29,9 @@ public static RpcNativeContract FromJson(JObject json) { Id = (int)json["id"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Nef = RpcNefFile.FromJson(json["nef"]), - Manifest = ContractManifest.FromJson(json["manifest"]), - UpdateHistory = json["updatehistory"].GetArray().Select(u => (uint)u.GetInt32()).ToArray() + Nef = RpcNefFile.FromJson((JObject)json["nef"]), + Manifest = ContractManifest.FromJson((JObject)json["manifest"]), + UpdateHistory = ((JArray)json["updatehistory"]).Select(u => (uint)u.GetInt32()).ToArray() }; } diff --git a/src/RpcClient/Models/RpcNefFile.cs b/src/RpcClient/Models/RpcNefFile.cs index 34663fe13..7bf580aca 100644 --- a/src/RpcClient/Models/RpcNefFile.cs +++ b/src/RpcClient/Models/RpcNefFile.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using System; using System.Linq; @@ -23,7 +23,7 @@ public static NefFile FromJson(JObject json) { Compiler = json["compiler"].AsString(), Source = json["source"].AsString(), - Tokens = ((JArray)json["tokens"]).Select(p => RpcMethodToken.FromJson(p)).ToArray(), + Tokens = ((JArray)json["tokens"]).Select(p => RpcMethodToken.FromJson((JObject)p)).ToArray(), Script = Convert.FromBase64String(json["script"].AsString()), CheckSum = (uint)json["checksum"].AsNumber() }; diff --git a/src/RpcClient/Models/RpcNep17Balances.cs b/src/RpcClient/Models/RpcNep17Balances.cs index af5b3c483..698b5ea73 100644 --- a/src/RpcClient/Models/RpcNep17Balances.cs +++ b/src/RpcClient/Models/RpcNep17Balances.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Wallets; using System.Collections.Generic; using System.Linq; @@ -34,7 +34,7 @@ public static RpcNep17Balances FromJson(JObject json, ProtocolSettings protocolS { RpcNep17Balances nep17Balance = new() { - Balances = ((JArray)json["balance"]).Select(p => RpcNep17Balance.FromJson(p, protocolSettings)).ToList(), + Balances = ((JArray)json["balance"]).Select(p => RpcNep17Balance.FromJson((JObject)p, protocolSettings)).ToList(), UserScriptHash = json["address"].ToScriptHash(protocolSettings) }; return nep17Balance; diff --git a/src/RpcClient/Models/RpcNep17Transfers.cs b/src/RpcClient/Models/RpcNep17Transfers.cs index 3e8da04ea..7edae9334 100644 --- a/src/RpcClient/Models/RpcNep17Transfers.cs +++ b/src/RpcClient/Models/RpcNep17Transfers.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Wallets; using System.Collections.Generic; using System.Linq; @@ -37,8 +37,8 @@ public static RpcNep17Transfers FromJson(JObject json, ProtocolSettings protocol { RpcNep17Transfers transfers = new() { - Sent = ((JArray)json["sent"]).Select(p => RpcNep17Transfer.FromJson(p, protocolSettings)).ToList(), - Received = ((JArray)json["received"]).Select(p => RpcNep17Transfer.FromJson(p, protocolSettings)).ToList(), + Sent = ((JArray)json["sent"]).Select(p => RpcNep17Transfer.FromJson((JObject)p, protocolSettings)).ToList(), + Received = ((JArray)json["received"]).Select(p => RpcNep17Transfer.FromJson((JObject)p, protocolSettings)).ToList(), UserScriptHash = json["address"].ToScriptHash(protocolSettings) }; return transfers; diff --git a/src/RpcClient/Models/RpcPeers.cs b/src/RpcClient/Models/RpcPeers.cs index 95a41e4d9..79f3832cc 100644 --- a/src/RpcClient/Models/RpcPeers.cs +++ b/src/RpcClient/Models/RpcPeers.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using System.Linq; namespace Neo.Network.RPC.Models @@ -34,9 +34,9 @@ public static RpcPeers FromJson(JObject json) { return new RpcPeers { - Unconnected = ((JArray)json["unconnected"]).Select(p => RpcPeer.FromJson(p)).ToArray(), - Bad = ((JArray)json["bad"]).Select(p => RpcPeer.FromJson(p)).ToArray(), - Connected = ((JArray)json["connected"]).Select(p => RpcPeer.FromJson(p)).ToArray() + Unconnected = ((JArray)json["unconnected"]).Select(p => RpcPeer.FromJson((JObject)p)).ToArray(), + Bad = ((JArray)json["bad"]).Select(p => RpcPeer.FromJson((JObject)p)).ToArray(), + Connected = ((JArray)json["connected"]).Select(p => RpcPeer.FromJson((JObject)p)).ToArray() }; } } diff --git a/src/RpcClient/Models/RpcPlugin.cs b/src/RpcClient/Models/RpcPlugin.cs index d75bd0481..5b7614155 100644 --- a/src/RpcClient/Models/RpcPlugin.cs +++ b/src/RpcClient/Models/RpcPlugin.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using System.Linq; namespace Neo.Network.RPC.Models @@ -26,7 +26,7 @@ public JObject ToJson() JObject json = new(); json["name"] = Name; json["version"] = Version; - json["interfaces"] = new JArray(Interfaces.Select(p => (JObject)p)); + json["interfaces"] = new JArray(Interfaces.Select(p => (JToken)p)); return json; } diff --git a/src/RpcClient/Models/RpcRawMemPool.cs b/src/RpcClient/Models/RpcRawMemPool.cs index 6e2d9cdb6..cb85924bf 100644 --- a/src/RpcClient/Models/RpcRawMemPool.cs +++ b/src/RpcClient/Models/RpcRawMemPool.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using System.Collections.Generic; using System.Linq; @@ -26,8 +26,8 @@ public JObject ToJson() { JObject json = new(); json["height"] = Height; - json["verified"] = new JArray(Verified.Select(p => (JObject)p.ToString())); - json["unverified"] = new JArray(UnVerified.Select(p => (JObject)p.ToString())); + json["verified"] = new JArray(Verified.Select(p => (JToken)p.ToString())); + json["unverified"] = new JArray(UnVerified.Select(p => (JToken)p.ToString())); return json; } diff --git a/src/RpcClient/Models/RpcRequest.cs b/src/RpcClient/Models/RpcRequest.cs index e46dde283..a2205ff1e 100644 --- a/src/RpcClient/Models/RpcRequest.cs +++ b/src/RpcClient/Models/RpcRequest.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,20 +8,20 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using System.Linq; namespace Neo.Network.RPC.Models { public class RpcRequest { - public JObject Id { get; set; } + public JToken Id { get; set; } public string JsonRpc { get; set; } public string Method { get; set; } - public JObject[] Params { get; set; } + public JToken[] Params { get; set; } public static RpcRequest FromJson(JObject json) { diff --git a/src/RpcClient/Models/RpcResponse.cs b/src/RpcClient/Models/RpcResponse.cs index 898eb7f77..4ceb0bcf5 100644 --- a/src/RpcClient/Models/RpcResponse.cs +++ b/src/RpcClient/Models/RpcResponse.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,19 +8,19 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { public class RpcResponse { - public JObject Id { get; set; } + public JToken Id { get; set; } public string JsonRpc { get; set; } public RpcResponseError Error { get; set; } - public JObject Result { get; set; } + public JToken Result { get; set; } public string RawResponse { get; set; } @@ -35,7 +35,7 @@ public static RpcResponse FromJson(JObject json) if (json["error"] != null) { - response.Error = RpcResponseError.FromJson(json["error"]); + response.Error = RpcResponseError.FromJson((JObject)json["error"]); } return response; @@ -58,7 +58,7 @@ public class RpcResponseError public string Message { get; set; } - public JObject Data { get; set; } + public JToken Data { get; set; } public static RpcResponseError FromJson(JObject json) { diff --git a/src/RpcClient/Models/RpcStateRoot.cs b/src/RpcClient/Models/RpcStateRoot.cs index 9991c5173..3a8bad275 100644 --- a/src/RpcClient/Models/RpcStateRoot.cs +++ b/src/RpcClient/Models/RpcStateRoot.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,9 +8,9 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using System.Linq; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; +using System.Linq; namespace Neo.Network.RPC.Models { @@ -28,7 +28,7 @@ public static RpcStateRoot FromJson(JObject json) Version = (byte)json["version"].AsNumber(), Index = (uint)json["index"].AsNumber(), RootHash = UInt256.Parse(json["roothash"].AsString()), - Witness = ((JArray)json["witnesses"]).Select(p => Utility.WitnessFromJson(p)).FirstOrDefault() + Witness = ((JArray)json["witnesses"]).Select(p => Utility.WitnessFromJson((JObject)p)).FirstOrDefault() }; } } diff --git a/src/RpcClient/Models/RpcTransaction.cs b/src/RpcClient/Models/RpcTransaction.cs index b0a0daf06..0e93efa76 100644 --- a/src/RpcClient/Models/RpcTransaction.cs +++ b/src/RpcClient/Models/RpcTransaction.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.VM; @@ -53,7 +53,7 @@ public static RpcTransaction FromJson(JObject json, ProtocolSettings protocolSet transaction.BlockHash = UInt256.Parse(json["blockhash"].AsString()); transaction.Confirmations = (uint)json["confirmations"].AsNumber(); transaction.BlockTime = (ulong)json["blocktime"].AsNumber(); - transaction.VMState = json["vmstate"]?.TryGetEnum(); + transaction.VMState = json["vmstate"]?.GetEnum(); } return transaction; } diff --git a/src/RpcClient/Models/RpcTransferOut.cs b/src/RpcClient/Models/RpcTransferOut.cs index 742597068..afcb13d5e 100644 --- a/src/RpcClient/Models/RpcTransferOut.cs +++ b/src/RpcClient/Models/RpcTransferOut.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Wallets; namespace Neo.Network.RPC.Models diff --git a/src/RpcClient/Models/RpcUnclaimedGas.cs b/src/RpcClient/Models/RpcUnclaimedGas.cs index eb0c2d719..4ccb36ada 100644 --- a/src/RpcClient/Models/RpcUnclaimedGas.cs +++ b/src/RpcClient/Models/RpcUnclaimedGas.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { diff --git a/src/RpcClient/Models/RpcValidateAddressResult.cs b/src/RpcClient/Models/RpcValidateAddressResult.cs index 2c671d289..1061c2403 100644 --- a/src/RpcClient/Models/RpcValidateAddressResult.cs +++ b/src/RpcClient/Models/RpcValidateAddressResult.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { diff --git a/src/RpcClient/Models/RpcValidator.cs b/src/RpcClient/Models/RpcValidator.cs index 21b02a052..39e692337 100644 --- a/src/RpcClient/Models/RpcValidator.cs +++ b/src/RpcClient/Models/RpcValidator.cs @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using System.Numerics; namespace Neo.Network.RPC.Models diff --git a/src/RpcClient/Models/RpcVersion.cs b/src/RpcClient/Models/RpcVersion.cs index ef5327289..20529c97c 100644 --- a/src/RpcClient/Models/RpcVersion.cs +++ b/src/RpcClient/Models/RpcVersion.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { @@ -88,7 +88,7 @@ public static RpcVersion FromJson(JObject json) WsPort = (int)json["wsport"].AsNumber(), Nonce = (uint)json["nonce"].AsNumber(), UserAgent = json["useragent"].AsString(), - Protocol = RpcProtocol.FromJson(json["protocol"]) + Protocol = RpcProtocol.FromJson((JObject)json["protocol"]) }; } } diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 3ee432f9d..b21a17a36 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -9,12 +9,11 @@ // modifications are permitted. using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; using Neo.SmartContract; using Neo.SmartContract.Manifest; -using Neo.VM; using System; using System.Collections.Generic; using System.IO; @@ -79,7 +78,7 @@ public void Dispose() } #endregion - static RpcRequest AsRpcRequest(string method, params JObject[] paraArgs) + static RpcRequest AsRpcRequest(string method, params JToken[] paraArgs) { return new RpcRequest { @@ -91,7 +90,7 @@ static RpcRequest AsRpcRequest(string method, params JObject[] paraArgs) } static RpcResponse AsRpcResponse(string content) { - var response = RpcResponse.FromJson(JObject.Parse(content)); + var response = RpcResponse.FromJson((JObject)JToken.Parse(content)); response.RawResponse = content; if (response.Error != null) @@ -132,14 +131,14 @@ public async Task SendAsync(RpcRequest request) return AsRpcResponse(content); } - public virtual JObject RpcSend(string method, params JObject[] paraArgs) + public virtual JToken RpcSend(string method, params JToken[] paraArgs) { var request = AsRpcRequest(method, paraArgs); var response = Send(request); return response.Result; } - public virtual async Task RpcSendAsync(string method, params JObject[] paraArgs) + public virtual async Task RpcSendAsync(string method, params JToken[] paraArgs) { var request = AsRpcRequest(method, paraArgs); var response = await SendAsync(request).ConfigureAwait(false); @@ -183,7 +182,7 @@ public async Task GetBlockAsync(string hashOrIndex) ? await RpcSendAsync(GetRpcName(), index, true).ConfigureAwait(false) : await RpcSendAsync(GetRpcName(), hashOrIndex, true).ConfigureAwait(false); - return RpcBlock.FromJson(result, protocolSettings); + return RpcBlock.FromJson((JObject)result, protocolSettings); } /// @@ -233,7 +232,7 @@ public async Task GetBlockHeaderAsync(string hashOrIndex) ? await RpcSendAsync(GetRpcName(), index, true).ConfigureAwait(false) : await RpcSendAsync(GetRpcName(), hashOrIndex, true).ConfigureAwait(false); - return RpcBlockHeader.FromJson(result, protocolSettings); + return RpcBlockHeader.FromJson((JObject)result, protocolSettings); } /// @@ -242,7 +241,7 @@ public async Task GetBlockHeaderAsync(string hashOrIndex) public async Task GetContractStateAsync(string hash) { var result = await RpcSendAsync(GetRpcName(), hash).ConfigureAwait(false); - return ContractStateFromJson(result); + return ContractStateFromJson((JObject)result); } public static ContractState ContractStateFromJson(JObject json) @@ -252,8 +251,8 @@ public static ContractState ContractStateFromJson(JObject json) Id = (int)json["id"].AsNumber(), UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Nef = RpcNefFile.FromJson(json["nef"]), - Manifest = ContractManifest.FromJson(json["manifest"]) + Nef = RpcNefFile.FromJson((JObject)json["nef"]), + Manifest = ContractManifest.FromJson((JObject)json["manifest"]) }; } @@ -263,7 +262,7 @@ public static ContractState ContractStateFromJson(JObject json) public async Task GetNativeContractsAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return ((JArray)result).Select(p => RpcNativeContract.FromJson(p)).ToArray(); + return ((JArray)result).Select(p => RpcNativeContract.FromJson((JObject)p)).ToArray(); } /// @@ -282,7 +281,7 @@ public async Task GetRawMempoolAsync() public async Task GetRawMempoolBothAsync() { var result = await RpcSendAsync(GetRpcName(), true).ConfigureAwait(false); - return RpcRawMemPool.FromJson(result); + return RpcRawMemPool.FromJson((JObject)result); } /// @@ -301,7 +300,7 @@ public async Task GetRawTransactionHexAsync(string txHash) public async Task GetRawTransactionAsync(string txHash) { var result = await RpcSendAsync(GetRpcName(), txHash, true).ConfigureAwait(false); - return RpcTransaction.FromJson(result, protocolSettings); + return RpcTransaction.FromJson((JObject)result, protocolSettings); } /// @@ -342,7 +341,7 @@ public async Task GetTransactionHeightAsync(string txHash) public async Task GetNextBlockValidatorsAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return ((JArray)result).Select(p => RpcValidator.FromJson(p)).ToArray(); + return ((JArray)result).Select(p => RpcValidator.FromJson((JObject)p)).ToArray(); } /// @@ -373,7 +372,7 @@ public async Task GetConnectionCountAsync() public async Task GetPeersAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return RpcPeers.FromJson(result); + return RpcPeers.FromJson((JObject)result); } /// @@ -382,7 +381,7 @@ public async Task GetPeersAsync() public async Task GetVersionAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return RpcVersion.FromJson(result); + return RpcVersion.FromJson((JObject)result); } /// @@ -421,13 +420,13 @@ public async Task SubmitBlockAsync(byte[] block) /// public async Task InvokeFunctionAsync(string scriptHash, string operation, RpcStack[] stacks, params Signer[] signer) { - List parameters = new() { scriptHash.AsScriptHash(), operation, stacks.Select(p => p.ToJson()).ToArray() }; + List parameters = new() { scriptHash.AsScriptHash(), operation, stacks.Select(p => p.ToJson()).ToArray() }; if (signer.Length > 0) { parameters.Add(signer.Select(p => p.ToJson()).ToArray()); } var result = await RpcSendAsync(GetRpcName(), parameters.ToArray()).ConfigureAwait(false); - return RpcInvokeResult.FromJson(result); + return RpcInvokeResult.FromJson((JObject)result); } /// @@ -436,19 +435,19 @@ public async Task InvokeFunctionAsync(string scriptHash, string /// public async Task InvokeScriptAsync(ReadOnlyMemory script, params Signer[] signers) { - List parameters = new() { Convert.ToBase64String(script.Span) }; + List parameters = new() { Convert.ToBase64String(script.Span) }; if (signers.Length > 0) { parameters.Add(signers.Select(p => p.ToJson()).ToArray()); } var result = await RpcSendAsync(GetRpcName(), parameters.ToArray()).ConfigureAwait(false); - return RpcInvokeResult.FromJson(result); + return RpcInvokeResult.FromJson((JObject)result); } public async Task GetUnclaimedGasAsync(string address) { var result = await RpcSendAsync(GetRpcName(), address.AsScriptHash()).ConfigureAwait(false); - return RpcUnclaimedGas.FromJson(result); + return RpcUnclaimedGas.FromJson((JObject)result); } @@ -459,7 +458,7 @@ public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, s { var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); var array = (JArray)result; - foreach (var jObject in array) + foreach (JObject jObject in array) { yield return jObject; } @@ -480,7 +479,7 @@ public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, s var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); if (result is JArray { Count: > 0 } array) { - foreach (var jObject in array) + foreach (JObject jObject in array) { yield return jObject; } @@ -507,7 +506,7 @@ public async Task TerminateSessionAsync(string sessionId) public async Task ListPluginsAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return ((JArray)result).Select(p => RpcPlugin.FromJson(p)).ToArray(); + return ((JArray)result).Select(p => RpcPlugin.FromJson((JObject)p)).ToArray(); } /// @@ -516,7 +515,7 @@ public async Task ListPluginsAsync() public async Task ValidateAddressAsync(string address) { var result = await RpcSendAsync(GetRpcName(), address).ConfigureAwait(false); - return RpcValidateAddressResult.FromJson(result); + return RpcValidateAddressResult.FromJson((JObject)result); } #endregion Utilities @@ -578,7 +577,7 @@ public async Task GetWalletUnclaimedGasAsync() public async Task ImportPrivKeyAsync(string wif) { var result = await RpcSendAsync(GetRpcName(), wif).ConfigureAwait(false); - return RpcAccount.FromJson(result); + return RpcAccount.FromJson((JObject)result); } /// @@ -587,7 +586,7 @@ public async Task ImportPrivKeyAsync(string wif) public async Task> ListAddressAsync() { var result = await RpcSendAsync(GetRpcName()).ConfigureAwait(false); - return ((JArray)result).Select(p => RpcAccount.FromJson(p)).ToList(); + return ((JArray)result).Select(p => RpcAccount.FromJson((JObject)p)).ToList(); } /// @@ -606,7 +605,7 @@ public async Task OpenWalletAsync(string path, string password) /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. public async Task SendFromAsync(string assetId, string fromAddress, string toAddress, string amount) { - return await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), fromAddress.AsScriptHash(), + return (JObject)await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), fromAddress.AsScriptHash(), toAddress.AsScriptHash(), amount).ConfigureAwait(false); } @@ -616,14 +615,14 @@ public async Task SendFromAsync(string assetId, string fromAddress, str /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. public async Task SendManyAsync(string fromAddress, IEnumerable outputs) { - var parameters = new List(); + var parameters = new List(); if (!string.IsNullOrEmpty(fromAddress)) { parameters.Add(fromAddress.AsScriptHash()); } parameters.Add(outputs.Select(p => p.ToJson(protocolSettings)).ToArray()); - return await RpcSendAsync(GetRpcName(), paraArgs: parameters.ToArray()).ConfigureAwait(false); + return (JObject)await RpcSendAsync(GetRpcName(), paraArgs: parameters.ToArray()).ConfigureAwait(false); } /// @@ -632,7 +631,7 @@ public async Task SendManyAsync(string fromAddress, IEnumerableThis function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. public async Task SendToAddressAsync(string assetId, string address, string amount) { - return await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), address.AsScriptHash(), amount) + return (JObject)await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), address.AsScriptHash(), amount) .ConfigureAwait(false); } @@ -647,7 +646,7 @@ public async Task SendToAddressAsync(string assetId, string address, st public async Task GetApplicationLogAsync(string txHash) { var result = await RpcSendAsync(GetRpcName(), txHash).ConfigureAwait(false); - return RpcApplicationLog.FromJson(result, protocolSettings); + return RpcApplicationLog.FromJson((JObject)result, protocolSettings); } /// @@ -657,7 +656,7 @@ public async Task GetApplicationLogAsync(string txHash) public async Task GetApplicationLogAsync(string txHash, TriggerType triggerType) { var result = await RpcSendAsync(GetRpcName(), txHash, triggerType).ConfigureAwait(false); - return RpcApplicationLog.FromJson(result, protocolSettings); + return RpcApplicationLog.FromJson((JObject)result, protocolSettings); } /// @@ -673,7 +672,7 @@ public async Task GetNep17TransfersAsync(string address, ulon endTimestamp ??= DateTime.UtcNow.ToTimestampMS(); var result = await RpcSendAsync(GetRpcName(), address.AsScriptHash(), startTimestamp, endTimestamp) .ConfigureAwait(false); - return RpcNep17Transfers.FromJson(result, protocolSettings); + return RpcNep17Transfers.FromJson((JObject)result, protocolSettings); } /// @@ -684,7 +683,7 @@ public async Task GetNep17BalancesAsync(string address) { var result = await RpcSendAsync(GetRpcName(), address.AsScriptHash()) .ConfigureAwait(false); - return RpcNep17Balances.FromJson(result, protocolSettings); + return RpcNep17Balances.FromJson((JObject)result, protocolSettings); } #endregion Plugins diff --git a/src/RpcClient/StateAPI.cs b/src/RpcClient/StateAPI.cs index 52c45438c..ff61a7b52 100644 --- a/src/RpcClient/StateAPI.cs +++ b/src/RpcClient/StateAPI.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,14 +8,10 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. +using Neo.Json; +using Neo.Network.RPC.Models; using System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading; using System.Threading.Tasks; -using Neo.IO.Json; -using Neo.Network.RPC.Models; namespace Neo.Network.RPC { @@ -31,7 +27,7 @@ public StateAPI(RpcClient rpc) public async Task GetStateRootAsync(uint index) { var result = await rpcClient.RpcSendAsync(RpcClient.GetRpcName(), index).ConfigureAwait(false); - return RpcStateRoot.FromJson(result); + return RpcStateRoot.FromJson((JObject)result); } public async Task GetProofAsync(UInt256 rootHash, UInt160 scriptHash, byte[] key) @@ -57,11 +53,11 @@ public async Task VerifyProofAsync(UInt256 rootHash, byte[] proofBytes) return (localRootIndex, validatedRootIndex); } - static uint? ToNullableUint(JObject json) => (json == null) ? (uint?)null : (uint?)json.AsNumber(); + static uint? ToNullableUint(JToken json) => (json == null) ? (uint?)null : (uint?)json.AsNumber(); - public static JObject[] MakeFindStatesParams(UInt256 rootHash, UInt160 scriptHash, ReadOnlySpan prefix, ReadOnlySpan from = default, int? count = null) + public static JToken[] MakeFindStatesParams(UInt256 rootHash, UInt160 scriptHash, ReadOnlySpan prefix, ReadOnlySpan from = default, int? count = null) { - var @params = new JObject[count.HasValue ? 5 : 4]; + var @params = new JToken[count.HasValue ? 5 : 4]; @params[0] = rootHash.ToString(); @params[1] = scriptHash.ToString(); @params[2] = Convert.ToBase64String(prefix); @@ -78,7 +74,7 @@ public async Task FindStatesAsync(UInt256 rootHash, UInt160 scri var @params = MakeFindStatesParams(rootHash, scriptHash, prefix.Span, from.Span, count); var result = await rpcClient.RpcSendAsync(RpcClient.GetRpcName(), @params).ConfigureAwait(false); - return RpcFoundStates.FromJson(result); + return RpcFoundStates.FromJson((JObject)result); } public async Task GetStateAsync(UInt256 rootHash, UInt160 scriptHash, byte[] key) diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index 9d7881194..b0d481eb4 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -9,7 +9,7 @@ // modifications are permitted. using Neo.Cryptography.ECC; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.SmartContract; using Neo.SmartContract.Native; @@ -36,7 +36,7 @@ private static (BigInteger numerator, BigInteger denominator) Fraction(decimal d return (numerator, denominator); } - public static UInt160 ToScriptHash(this JObject value, ProtocolSettings protocolSettings) + public static UInt160 ToScriptHash(this JToken value, ProtocolSettings protocolSettings) { var addressOrScriptHash = value.AsString(); @@ -132,7 +132,7 @@ public static Block BlockFromJson(JObject json, ProtocolSettings protocolSetting return new Block() { Header = HeaderFromJson(json, protocolSettings), - Transactions = ((JArray)json["tx"]).Select(p => TransactionFromJson(p, protocolSettings)).ToArray() + Transactions = ((JArray)json["tx"]).Select(p => TransactionFromJson((JObject)p, protocolSettings)).ToArray() }; } @@ -155,7 +155,7 @@ public static Header HeaderFromJson(JObject json, ProtocolSettings protocolSetti Index = (uint)json["index"].AsNumber(), PrimaryIndex = (byte)json["primary"].AsNumber(), NextConsensus = json["nextconsensus"].ToScriptHash(protocolSettings), - Witness = ((JArray)json["witnesses"]).Select(p => WitnessFromJson(p)).FirstOrDefault() + Witness = ((JArray)json["witnesses"]).Select(p => WitnessFromJson((JObject)p)).FirstOrDefault() }; } @@ -165,13 +165,13 @@ public static Transaction TransactionFromJson(JObject json, ProtocolSettings pro { Version = byte.Parse(json["version"].AsString()), Nonce = uint.Parse(json["nonce"].AsString()), - Signers = ((JArray)json["signers"]).Select(p => SignerFromJson(p, protocolSettings)).ToArray(), + Signers = ((JArray)json["signers"]).Select(p => SignerFromJson((JObject)p, protocolSettings)).ToArray(), SystemFee = long.Parse(json["sysfee"].AsString()), NetworkFee = long.Parse(json["netfee"].AsString()), ValidUntilBlock = uint.Parse(json["validuntilblock"].AsString()), - Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttributeFromJson(p)).ToArray(), + Attributes = ((JArray)json["attributes"]).Select(p => TransactionAttributeFromJson((JObject)p)).ToArray(), Script = Convert.FromBase64String(json["script"].AsString()), - Witnesses = ((JArray)json["witnesses"]).Select(p => WitnessFromJson(p)).ToArray() + Witnesses = ((JArray)json["witnesses"]).Select(p => WitnessFromJson((JObject)p)).ToArray() }; } @@ -221,7 +221,7 @@ public static Witness WitnessFromJson(JObject json) public static StackItem StackItemFromJson(JObject json) { - StackItemType type = json["type"].TryGetEnum(); + StackItemType type = json["type"].GetEnum(); switch (type) { case StackItemType.Boolean: @@ -234,20 +234,20 @@ public static StackItem StackItemFromJson(JObject json) return BigInteger.Parse(json["value"].AsString()); case StackItemType.Array: Array array = new(); - foreach (var item in (JArray)json["value"]) + foreach (JObject item in (JArray)json["value"]) array.Add(StackItemFromJson(item)); return array; case StackItemType.Struct: Struct @struct = new(); - foreach (var item in (JArray)json["value"]) + foreach (JObject item in (JArray)json["value"]) @struct.Add(StackItemFromJson(item)); return @struct; case StackItemType.Map: Map map = new(); foreach (var item in (JArray)json["value"]) { - PrimitiveType key = (PrimitiveType)StackItemFromJson(item["key"]); - map[key] = StackItemFromJson(item["value"]); + PrimitiveType key = (PrimitiveType)StackItemFromJson((JObject)item["key"]); + map[key] = StackItemFromJson((JObject)item["value"]); } return map; case StackItemType.Pointer: diff --git a/src/RpcServer/Diagnostic.cs b/src/RpcServer/Diagnostic.cs index b70ac6448..d75c93cd5 100644 --- a/src/RpcServer/Diagnostic.cs +++ b/src/RpcServer/Diagnostic.cs @@ -41,11 +41,11 @@ public void ContextUnloaded(ExecutionContext context) currentNodeOfInvocationTree = currentNodeOfInvocationTree.Parent; } - public void PostExecuteInstruction() + public void PreExecuteInstruction(Instruction instruction) { } - public void PreExecuteInstruction() + public void PostExecuteInstruction(Instruction instruction) { } } diff --git a/src/RpcServer/RpcServer.Blockchain.cs b/src/RpcServer/RpcServer.Blockchain.cs index 822f282cf..700067572 100644 --- a/src/RpcServer/RpcServer.Blockchain.cs +++ b/src/RpcServer/RpcServer.Blockchain.cs @@ -9,7 +9,7 @@ // modifications are permitted. using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.SmartContract; using Neo.SmartContract.Native; @@ -24,15 +24,15 @@ namespace Neo.Plugins partial class RpcServer { [RpcMethod] - protected virtual JObject GetBestBlockHash(JArray _params) + protected virtual JToken GetBestBlockHash(JArray _params) { return NativeContract.Ledger.CurrentHash(system.StoreView).ToString(); } [RpcMethod] - protected virtual JObject GetBlock(JArray _params) + protected virtual JToken GetBlock(JArray _params) { - JObject key = _params[0]; + JToken key = _params[0]; bool verbose = _params.Count >= 2 && _params[1].AsBoolean(); using var snapshot = system.GetSnapshot(); Block block; @@ -61,19 +61,19 @@ protected virtual JObject GetBlock(JArray _params) } [RpcMethod] - protected virtual JObject GetBlockHeaderCount(JArray _params) + protected virtual JToken GetBlockHeaderCount(JArray _params) { return (system.HeaderCache.Last?.Index ?? NativeContract.Ledger.CurrentIndex(system.StoreView)) + 1; } [RpcMethod] - protected virtual JObject GetBlockCount(JArray _params) + protected virtual JToken GetBlockCount(JArray _params) { return NativeContract.Ledger.CurrentIndex(system.StoreView) + 1; } [RpcMethod] - protected virtual JObject GetBlockHash(JArray _params) + protected virtual JToken GetBlockHash(JArray _params) { uint height = uint.Parse(_params[0].AsString()); var snapshot = system.StoreView; @@ -85,9 +85,9 @@ protected virtual JObject GetBlockHash(JArray _params) } [RpcMethod] - protected virtual JObject GetBlockHeader(JArray _params) + protected virtual JToken GetBlockHeader(JArray _params) { - JObject key = _params[0]; + JToken key = _params[0]; bool verbose = _params.Count >= 2 && _params[1].AsBoolean(); var snapshot = system.StoreView; Header header; @@ -118,7 +118,7 @@ protected virtual JObject GetBlockHeader(JArray _params) } [RpcMethod] - protected virtual JObject GetContractState(JArray _params) + protected virtual JToken GetContractState(JArray _params) { UInt160 script_hash = ToScriptHash(_params[0].AsString()); ContractState contract = NativeContract.ContractManagement.GetContract(system.StoreView, script_hash); @@ -137,24 +137,24 @@ private static UInt160 ToScriptHash(string keyword) } [RpcMethod] - protected virtual JObject GetRawMemPool(JArray _params) + protected virtual JToken GetRawMemPool(JArray _params) { bool shouldGetUnverified = _params.Count >= 1 && _params[0].AsBoolean(); if (!shouldGetUnverified) - return new JArray(system.MemPool.GetVerifiedTransactions().Select(p => (JObject)p.Hash.ToString())); + return new JArray(system.MemPool.GetVerifiedTransactions().Select(p => (JToken)p.Hash.ToString())); JObject json = new(); json["height"] = NativeContract.Ledger.CurrentIndex(system.StoreView); system.MemPool.GetVerifiedAndUnverifiedTransactions( out IEnumerable verifiedTransactions, out IEnumerable unverifiedTransactions); - json["verified"] = new JArray(verifiedTransactions.Select(p => (JObject)p.Hash.ToString())); - json["unverified"] = new JArray(unverifiedTransactions.Select(p => (JObject)p.Hash.ToString())); + json["verified"] = new JArray(verifiedTransactions.Select(p => (JToken)p.Hash.ToString())); + json["unverified"] = new JArray(unverifiedTransactions.Select(p => (JToken)p.Hash.ToString())); return json; } [RpcMethod] - protected virtual JObject GetRawTransaction(JArray _params) + protected virtual JToken GetRawTransaction(JArray _params) { UInt256 hash = UInt256.Parse(_params[0].AsString()); bool verbose = _params.Count >= 2 && _params[1].AsBoolean(); @@ -177,7 +177,7 @@ protected virtual JObject GetRawTransaction(JArray _params) } [RpcMethod] - protected virtual JObject GetStorage(JArray _params) + protected virtual JToken GetStorage(JArray _params) { using var snapshot = system.GetSnapshot(); if (!int.TryParse(_params[0].AsString(), out int id)) @@ -198,7 +198,7 @@ protected virtual JObject GetStorage(JArray _params) } [RpcMethod] - protected virtual JObject GetTransactionHeight(JArray _params) + protected virtual JToken GetTransactionHeight(JArray _params) { UInt256 hash = UInt256.Parse(_params[0].AsString()); uint? height = NativeContract.Ledger.GetTransactionState(system.StoreView, hash)?.BlockIndex; @@ -207,7 +207,7 @@ protected virtual JObject GetTransactionHeight(JArray _params) } [RpcMethod] - protected virtual JObject GetNextBlockValidators(JArray _params) + protected virtual JToken GetNextBlockValidators(JArray _params) { using var snapshot = system.GetSnapshot(); var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount); @@ -221,7 +221,7 @@ protected virtual JObject GetNextBlockValidators(JArray _params) } [RpcMethod] - protected virtual JObject GetCandidates(JArray _params) + protected virtual JToken GetCandidates(JArray _params) { using var snapshot = system.GetSnapshot(); byte[] script; @@ -263,13 +263,13 @@ protected virtual JObject GetCandidates(JArray _params) } [RpcMethod] - protected virtual JObject GetCommittee(JArray _params) + protected virtual JToken GetCommittee(JArray _params) { - return new JArray(NativeContract.NEO.GetCommittee(system.StoreView).Select(p => (JObject)p.ToString())); + return new JArray(NativeContract.NEO.GetCommittee(system.StoreView).Select(p => (JToken)p.ToString())); } [RpcMethod] - protected virtual JObject GetNativeContracts(JArray _params) + protected virtual JToken GetNativeContracts(JArray _params) { return new JArray(NativeContract.Contracts.Select(p => p.NativeContractToJson(system.Settings))); } diff --git a/src/RpcServer/RpcServer.Node.cs b/src/RpcServer/RpcServer.Node.cs index 4b044d756..9f4547bfc 100644 --- a/src/RpcServer/RpcServer.Node.cs +++ b/src/RpcServer/RpcServer.Node.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -10,7 +10,7 @@ using Akka.Actor; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; @@ -23,13 +23,13 @@ namespace Neo.Plugins partial class RpcServer { [RpcMethod] - protected virtual JObject GetConnectionCount(JArray _params) + protected virtual JToken GetConnectionCount(JArray _params) { return localNode.ConnectedCount; } [RpcMethod] - protected virtual JObject GetPeers(JArray _params) + protected virtual JToken GetPeers(JArray _params) { JObject json = new(); json["unconnected"] = new JArray(localNode.GetUnconnectedPeers().Select(p => @@ -65,7 +65,7 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash) } [RpcMethod] - protected virtual JObject GetVersion(JArray _params) + protected virtual JToken GetVersion(JArray _params) { JObject json = new(); json["tcpport"] = localNode.ListenerTcpPort; @@ -86,7 +86,7 @@ protected virtual JObject GetVersion(JArray _params) } [RpcMethod] - protected virtual JObject SendRawTransaction(JArray _params) + protected virtual JToken SendRawTransaction(JArray _params) { Transaction tx = Convert.FromBase64String(_params[0].AsString()).AsSerializable(); RelayResult reason = system.Blockchain.Ask(tx).Result; @@ -94,7 +94,7 @@ protected virtual JObject SendRawTransaction(JArray _params) } [RpcMethod] - protected virtual JObject SubmitBlock(JArray _params) + protected virtual JToken SubmitBlock(JArray _params) { Block block = Convert.FromBase64String(_params[0].AsString()).AsSerializable(); RelayResult reason = system.Blockchain.Ask(block).Result; diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 6d3ae56f8..2a3c38ab7 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -10,7 +10,7 @@ using Neo.Cryptography.ECC; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract; @@ -135,7 +135,7 @@ private static JObject ToJson(TreeNode node) return json; } - private static JObject ToJson(IEnumerable changes) + private static JArray ToJson(IEnumerable changes) { JArray array = new(); foreach (var entry in changes) @@ -171,7 +171,7 @@ private static Signer[] SignersFromJson(JArray _params, ProtocolSettings setting Scopes = (WitnessScope)Enum.Parse(typeof(WitnessScope), u["scopes"]?.AsString()), AllowedContracts = ((JArray)u["allowedcontracts"])?.Select(p => UInt160.Parse(p.AsString())).ToArray(), AllowedGroups = ((JArray)u["allowedgroups"])?.Select(p => ECPoint.Parse(p.AsString(), ECCurve.Secp256r1)).ToArray(), - Rules = ((JArray)u["rules"])?.Select(WitnessRule.FromJson).ToArray(), + Rules = ((JArray)u["rules"])?.Select(r => WitnessRule.FromJson((JObject)r)).ToArray(), }).ToArray(); // Validate format @@ -195,11 +195,11 @@ private static Witness[] WitnessesFromJson(JArray _params) } [RpcMethod] - protected virtual JObject InvokeFunction(JArray _params) + protected virtual JToken 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() : System.Array.Empty(); + ContractParameter[] args = _params.Count >= 3 ? ((JArray)_params[2]).Select(p => ContractParameter.FromJson((JObject)p)).ToArray() : System.Array.Empty(); Signer[] signers = _params.Count >= 4 ? SignersFromJson((JArray)_params[3], system.Settings) : null; Witness[] witnesses = _params.Count >= 4 ? WitnessesFromJson((JArray)_params[3]) : null; bool useDiagnostic = _params.Count >= 5 && _params[4].GetBoolean(); @@ -213,7 +213,7 @@ protected virtual JObject InvokeFunction(JArray _params) } [RpcMethod] - protected virtual JObject InvokeScript(JArray _params) + protected virtual JToken InvokeScript(JArray _params) { byte[] script = Convert.FromBase64String(_params[0].AsString()); Signer[] signers = _params.Count >= 2 ? SignersFromJson((JArray)_params[1], system.Settings) : null; @@ -223,7 +223,7 @@ protected virtual JObject InvokeScript(JArray _params) } [RpcMethod] - protected virtual JObject TraverseIterator(JArray _params) + protected virtual JToken TraverseIterator(JArray _params) { Guid sid = Guid.Parse(_params[0].GetString()); Guid iid = Guid.Parse(_params[1].GetString()); @@ -244,7 +244,7 @@ protected virtual JObject TraverseIterator(JArray _params) } [RpcMethod] - protected virtual JObject TerminateSession(JArray _params) + protected virtual JToken TerminateSession(JArray _params) { Guid sid = Guid.Parse(_params[0].GetString()); Session session; @@ -256,7 +256,7 @@ protected virtual JObject TerminateSession(JArray _params) } [RpcMethod] - protected virtual JObject GetUnclaimedGas(JArray _params) + protected virtual JToken GetUnclaimedGas(JArray _params) { string address = _params[0].AsString(); JObject json = new(); diff --git a/src/RpcServer/RpcServer.Utilities.cs b/src/RpcServer/RpcServer.Utilities.cs index 134c4a5c0..735ee5c45 100644 --- a/src/RpcServer/RpcServer.Utilities.cs +++ b/src/RpcServer/RpcServer.Utilities.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Wallets; using System.Linq; @@ -17,7 +17,7 @@ namespace Neo.Plugins partial class RpcServer { [RpcMethod] - protected virtual JObject ListPlugins(JArray _params) + protected virtual JToken ListPlugins(JArray _params) { return new JArray(Plugin.Plugins .OrderBy(u => u.Name) @@ -28,12 +28,12 @@ protected virtual JObject ListPlugins(JArray _params) ["interfaces"] = new JArray(u.GetType().GetInterfaces() .Select(p => p.Name) .Where(p => p.EndsWith("Plugin")) - .Select(p => (JObject)p)) + .Select(p => (JToken)p)) })); } [RpcMethod] - protected virtual JObject ValidateAddress(JArray _params) + protected virtual JToken ValidateAddress(JArray _params) { string address = _params[0].AsString(); JObject json = new(); diff --git a/src/RpcServer/RpcServer.Wallet.cs b/src/RpcServer/RpcServer.Wallet.cs index 3ed17f03a..6548b6529 100644 --- a/src/RpcServer/RpcServer.Wallet.cs +++ b/src/RpcServer/RpcServer.Wallet.cs @@ -10,7 +10,7 @@ using Akka.Actor; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.SmartContract; @@ -56,14 +56,14 @@ private void CheckWallet() } [RpcMethod] - protected virtual JObject CloseWallet(JArray _params) + protected virtual JToken CloseWallet(JArray _params) { wallet = null; return true; } [RpcMethod] - protected virtual JObject DumpPrivKey(JArray _params) + protected virtual JToken DumpPrivKey(JArray _params) { CheckWallet(); UInt160 scriptHash = AddressToScriptHash(_params[0].AsString(), system.Settings.AddressVersion); @@ -72,7 +72,7 @@ protected virtual JObject DumpPrivKey(JArray _params) } [RpcMethod] - protected virtual JObject GetNewAddress(JArray _params) + protected virtual JToken GetNewAddress(JArray _params) { CheckWallet(); WalletAccount account = wallet.CreateAccount(); @@ -82,7 +82,7 @@ protected virtual JObject GetNewAddress(JArray _params) } [RpcMethod] - protected virtual JObject GetWalletBalance(JArray _params) + protected virtual JToken GetWalletBalance(JArray _params) { CheckWallet(); UInt160 asset_id = UInt160.Parse(_params[0].AsString()); @@ -92,7 +92,7 @@ protected virtual JObject GetWalletBalance(JArray _params) } [RpcMethod] - protected virtual JObject GetWalletUnclaimedGas(JArray _params) + protected virtual JToken GetWalletUnclaimedGas(JArray _params) { CheckWallet(); BigInteger gas = BigInteger.Zero; @@ -106,7 +106,7 @@ protected virtual JObject GetWalletUnclaimedGas(JArray _params) } [RpcMethod] - protected virtual JObject ImportPrivKey(JArray _params) + protected virtual JToken ImportPrivKey(JArray _params) { CheckWallet(); string privkey = _params[0].AsString(); @@ -123,7 +123,7 @@ protected virtual JObject ImportPrivKey(JArray _params) } [RpcMethod] - protected virtual JObject CalculateNetworkFee(JArray _params) + protected virtual JToken CalculateNetworkFee(JArray _params) { byte[] tx = Convert.FromBase64String(_params[0].AsString()); @@ -134,7 +134,7 @@ protected virtual JObject CalculateNetworkFee(JArray _params) } [RpcMethod] - protected virtual JObject ListAddress(JArray _params) + protected virtual JToken ListAddress(JArray _params) { CheckWallet(); return wallet.GetAccounts().Select(p => @@ -149,7 +149,7 @@ protected virtual JObject ListAddress(JArray _params) } [RpcMethod] - protected virtual JObject OpenWallet(JArray _params) + protected virtual JToken OpenWallet(JArray _params) { string path = _params[0].AsString(); string password = _params[1].AsString(); @@ -188,7 +188,7 @@ private void ProcessInvokeWithWallet(JObject result, Signer[] signers = null) } [RpcMethod] - protected virtual JObject SendFrom(JArray _params) + protected virtual JToken SendFrom(JArray _params) { CheckWallet(); UInt160 assetId = UInt160.Parse(_params[0].AsString()); @@ -230,7 +230,7 @@ protected virtual JObject SendFrom(JArray _params) } [RpcMethod] - protected virtual JObject SendMany(JArray _params) + protected virtual JToken SendMany(JArray _params) { CheckWallet(); int to_start = 0; @@ -281,7 +281,7 @@ protected virtual JObject SendMany(JArray _params) } [RpcMethod] - protected virtual JObject SendToAddress(JArray _params) + protected virtual JToken SendToAddress(JArray _params) { CheckWallet(); UInt160 assetId = UInt160.Parse(_params[0].AsString()); @@ -320,10 +320,10 @@ protected virtual JObject SendToAddress(JArray _params) } [RpcMethod] - protected virtual JObject InvokeContractVerify(JArray _params) + protected virtual JToken InvokeContractVerify(JArray _params) { UInt160 script_hash = UInt160.Parse(_params[0].AsString()); - ContractParameter[] args = _params.Count >= 2 ? ((JArray)_params[1]).Select(p => ContractParameter.FromJson(p)).ToArray() : Array.Empty(); + ContractParameter[] args = _params.Count >= 2 ? ((JArray)_params[1]).Select(p => ContractParameter.FromJson((JObject)p)).ToArray() : Array.Empty(); Signer[] signers = _params.Count >= 3 ? SignersFromJson((JArray)_params[2], system.Settings) : null; Witness[] witnesses = _params.Count >= 3 ? WitnessesFromJson((JArray)_params[2]) : null; return GetVerificationResult(script_hash, args, signers, witnesses); diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index 724c313b2..34a6f4d66 100644 --- a/src/RpcServer/RpcServer.cs +++ b/src/RpcServer/RpcServer.cs @@ -16,7 +16,7 @@ using Microsoft.AspNetCore.Server.Kestrel.Https; using Microsoft.Extensions.DependencyInjection; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P; using System; using System.Collections.Generic; @@ -73,7 +73,7 @@ private bool CheckAuth(HttpContext context) return authvalues[0] == settings.RpcUser && authvalues[1] == settings.RpcPass; } - private static JObject CreateErrorResponse(JObject id, int code, string message, JObject data = null) + private static JObject CreateErrorResponse(JToken id, int code, string message, JToken data = null) { JObject response = CreateResponse(id); response["error"] = new JObject(); @@ -84,7 +84,7 @@ private static JObject CreateErrorResponse(JObject id, int code, string message, return response; } - private static JObject CreateResponse(JObject id) + private static JObject CreateResponse(JToken id) { JObject response = new(); response["jsonrpc"] = "2.0"; @@ -164,7 +164,7 @@ public async Task ProcessAsync(HttpContext context) context.Response.Headers["Access-Control-Allow-Headers"] = "Content-Type"; context.Response.Headers["Access-Control-Max-Age"] = "31536000"; if (context.Request.Method != "GET" && context.Request.Method != "POST") return; - JObject request = null; + JToken request = null; if (context.Request.Method == "GET") { string jsonrpc = context.Request.Query["jsonrpc"]; @@ -183,7 +183,7 @@ public async Task ProcessAsync(HttpContext context) request["jsonrpc"] = jsonrpc; request["id"] = id; request["method"] = method; - request["params"] = JObject.Parse(_params); + request["params"] = JToken.Parse(_params); } } else if (context.Request.Method == "POST") @@ -191,11 +191,11 @@ public async Task ProcessAsync(HttpContext context) using StreamReader reader = new(context.Request.Body); try { - request = JObject.Parse(await reader.ReadToEndAsync()); + request = JToken.Parse(await reader.ReadToEndAsync()); } catch (FormatException) { } } - JObject response; + JToken response; if (request == null) { response = CreateErrorResponse(null, -32700, "Parse error"); @@ -208,14 +208,14 @@ public async Task ProcessAsync(HttpContext context) } else { - var tasks = array.Select(p => ProcessRequestAsync(context, p)); + var tasks = array.Select(p => ProcessRequestAsync(context, (JObject)p)); var results = await Task.WhenAll(tasks); response = results.Where(p => p != null).ToArray(); } } else { - response = await ProcessRequestAsync(context, request); + response = await ProcessRequestAsync(context, (JObject)request); } if (response == null || (response as JArray)?.Count == 0) return; context.Response.ContentType = "application/json"; @@ -239,8 +239,8 @@ private async Task ProcessRequestAsync(HttpContext context, JObject req throw new RpcException(-32601, "Method not found"); response["result"] = func((JArray)request["params"]) switch { - JObject result => result, - Task task => await task, + JToken result => result, + Task task => await task, _ => throw new NotSupportedException() }; return response; diff --git a/src/RpcServer/Utility.cs b/src/RpcServer/Utility.cs index 5d446ba17..87cf69871 100644 --- a/src/RpcServer/Utility.cs +++ b/src/RpcServer/Utility.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Network.RPC is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,7 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.SmartContract.Native; using System.Linq; @@ -40,7 +40,7 @@ public static JObject NativeContractToJson(this NativeContract contract, Protoco ["hash"] = contract.Hash.ToString(), ["nef"] = contract.Nef.ToJson(), ["manifest"] = contract.Manifest.ToJson(), - ["updatehistory"] = settings.NativeUpdateHistory[contract.Name].Select(p => (JObject)p).ToArray() + ["updatehistory"] = settings.NativeUpdateHistory[contract.Name].Select(p => (JToken)p).ToArray() }; } } diff --git a/src/StateService/Network/StateRoot.cs b/src/StateService/Network/StateRoot.cs index 843d39323..3adcfe10c 100644 --- a/src/StateService/Network/StateRoot.cs +++ b/src/StateService/Network/StateRoot.cs @@ -10,7 +10,7 @@ using Neo.Cryptography.ECC; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; using Neo.Persistence; diff --git a/src/StateService/StatePlugin.cs b/src/StateService/StatePlugin.cs index ef20d873e..2feb3f8ad 100644 --- a/src/StateService/StatePlugin.cs +++ b/src/StateService/StatePlugin.cs @@ -12,7 +12,7 @@ using Neo.ConsoleService; using Neo.Cryptography.MPTTrie; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -87,8 +87,8 @@ public override void Dispose() base.Dispose(); Blockchain.Committing -= OnCommitting; Blockchain.Committed -= OnCommitted; - if (Store is not null) System.EnsureStoped(Store); - if (Verifier is not null) System.EnsureStoped(Verifier); + if (Store is not null) System.EnsureStopped(Store); + if (Verifier is not null) System.EnsureStopped(Verifier); } private void OnCommitting(NeoSystem system, Block block, DataCache snapshot, IReadOnlyList applicationExecutedList) @@ -176,7 +176,7 @@ private void OnVerifyProof(UInt256 root_hash, string proof) } [RpcMethod] - public JObject GetStateRoot(JArray _params) + public JToken GetStateRoot(JArray _params) { uint index = uint.Parse(_params[0].AsString()); using var snapshot = StateStore.Singleton.GetSnapshot(); @@ -230,7 +230,7 @@ private string GetProof(UInt256 root_hash, UInt160 script_hash, byte[] key) } [RpcMethod] - public JObject GetProof(JArray _params) + public JToken GetProof(JArray _params) { UInt256 root_hash = UInt256.Parse(_params[0].AsString()); UInt160 script_hash = UInt160.Parse(_params[1].AsString()); @@ -258,7 +258,7 @@ private string VerifyProof(UInt256 root_hash, byte[] proof) } [RpcMethod] - public JObject VerifyProof(JArray _params) + public JToken VerifyProof(JArray _params) { UInt256 root_hash = UInt256.Parse(_params[0].AsString()); byte[] proof_bytes = Convert.FromBase64String(_params[1].AsString()); @@ -266,7 +266,7 @@ public JObject VerifyProof(JArray _params) } [RpcMethod] - public JObject GetStateHeight(JArray _params) + public JToken GetStateHeight(JArray _params) { var json = new JObject(); json["localrootindex"] = StateStore.Singleton.LocalRootIndex; @@ -291,7 +291,7 @@ private StorageKey ParseStorageKey(byte[] data) } [RpcMethod] - public JObject FindStates(JArray _params) + public JToken FindStates(JArray _params) { var root_hash = UInt256.Parse(_params[0].AsString()); if (!Settings.Default.FullState && StateStore.Singleton.CurrentLocalRootHash != root_hash) @@ -349,7 +349,7 @@ public JObject FindStates(JArray _params) } [RpcMethod] - public JObject GetState(JArray _params) + public JToken GetState(JArray _params) { var root_hash = UInt256.Parse(_params[0].AsString()); if (!Settings.Default.FullState && StateStore.Singleton.CurrentLocalRootHash != root_hash) diff --git a/src/StatesDumper/StatesDumper.cs b/src/StatesDumper/StatesDumper.cs index 3723cc756..f40a232c6 100644 --- a/src/StatesDumper/StatesDumper.cs +++ b/src/StatesDumper/StatesDumper.cs @@ -10,7 +10,7 @@ using Neo.ConsoleService; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; diff --git a/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs b/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs index bff6acbee..a285682f1 100644 --- a/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs +++ b/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Plugins.TokensTracker is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,11 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -21,6 +17,10 @@ using Neo.VM; using Neo.VM.Types; using Neo.Wallets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; using Array = Neo.VM.Types.Array; namespace Neo.Plugins.Trackers.NEP_11 @@ -192,7 +192,7 @@ private void RecordTransferHistoryNep11(UInt160 contractHash, UInt160 from, UInt [RpcMethod] - public JObject GetNep11Transfers(JArray _params) + public JToken GetNep11Transfers(JArray _params) { if (!_shouldTrackHistory) throw new RpcException(-32601, "Method not found"); UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); @@ -215,7 +215,7 @@ public JObject GetNep11Transfers(JArray _params) } [RpcMethod] - public JObject GetNep11Balances(JArray _params) + public JToken GetNep11Balances(JArray _params) { UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); @@ -275,7 +275,7 @@ public JObject GetNep11Balances(JArray _params) } [RpcMethod] - public JObject GetNep11Properties(JArray _params) + public JToken GetNep11Properties(JArray _params) { UInt160 nep11Hash = GetScriptHashFromParam(_params[0].AsString()); var tokenId = _params[1].AsString().HexToBytes(); diff --git a/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs b/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs index a4a780cf9..63119fcca 100644 --- a/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs +++ b/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Plugins.TokensTracker is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,11 +8,7 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using System; -using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; @@ -21,6 +17,10 @@ using Neo.VM; using Neo.VM.Types; using Neo.Wallets; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Numerics; using Array = Neo.VM.Types.Array; namespace Neo.Plugins.Trackers.NEP_17 @@ -141,7 +141,7 @@ private void SaveNep17Balance(BalanceChangeRecord balanceChanged, DataCache snap [RpcMethod] - public JObject GetNep17Transfers(JArray _params) + public JToken GetNep17Transfers(JArray _params) { if (!_shouldTrackHistory) throw new RpcException(-32601, "Method not found"); UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); @@ -164,7 +164,7 @@ public JObject GetNep17Transfers(JArray _params) } [RpcMethod] - public JObject GetNep17Balances(JArray _params) + public JToken GetNep17Balances(JArray _params) { UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); diff --git a/src/TokensTracker/Trackers/TrackerBase.cs b/src/TokensTracker/Trackers/TrackerBase.cs index 05dc4f823..829a7710c 100644 --- a/src/TokensTracker/Trackers/TrackerBase.cs +++ b/src/TokensTracker/Trackers/TrackerBase.cs @@ -1,4 +1,4 @@ -// Copyright (C) 2015-2021 The Neo Project. +// Copyright (C) 2015-2022 The Neo Project. // // The Neo.Plugins.TokensTracker is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the @@ -8,19 +8,19 @@ // Redistribution and use in source and binary forms with or without // modifications are permitted. -using System; -using System.Buffers.Binary; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Numerics; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.Persistence; using Neo.VM.Types; using Neo.Wallets; +using System; +using System.Buffers.Binary; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Numerics; using Array = Neo.VM.Types.Array; namespace Neo.Plugins.Trackers diff --git a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj index 94baf85bd..6ad613519 100644 --- a/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj +++ b/tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj @@ -6,7 +6,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/tests/Neo.Network.RPC.Tests/TestUtils.cs b/tests/Neo.Network.RPC.Tests/TestUtils.cs index 5f83992db..74380f613 100644 --- a/tests/Neo.Network.RPC.Tests/TestUtils.cs +++ b/tests/Neo.Network.RPC.Tests/TestUtils.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; using System.Collections.Generic; @@ -9,7 +9,7 @@ namespace Neo.Network.RPC.Tests { internal static class TestUtils { - public readonly static List RpcTestCases = ((JArray)JObject.Parse(File.ReadAllText("RpcTestCases.json"))).Select(p => RpcTestCase.FromJson(p)).ToList(); + public readonly static List RpcTestCases = ((JArray)JToken.Parse(File.ReadAllText("RpcTestCases.json"))).Select(p => RpcTestCase.FromJson((JObject)p)).ToList(); public static Block GetBlock(int txCount) { @@ -75,8 +75,8 @@ public static RpcTestCase FromJson(JObject json) return new RpcTestCase { Name = json["Name"].AsString(), - Request = RpcRequest.FromJson(json["Request"]), - Response = RpcResponse.FromJson(json["Response"]), + Request = RpcRequest.FromJson((JObject)json["Request"]), + Response = RpcResponse.FromJson((JObject)json["Response"]), }; } diff --git a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs index 835dfc2e0..566efc9e4 100644 --- a/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs +++ b/tests/Neo.Network.RPC.Tests/UT_Nep17API.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using Neo.IO.Json; +using Neo.Json; using Neo.SmartContract; using Neo.SmartContract.Native; using Neo.VM; @@ -97,7 +97,7 @@ public async Task TestGetTokenInfo() var haveNeoTokenUT = false; foreach (var test in tests) { - rpcClientMock.Setup(p => p.RpcSendAsync("getcontractstate", It.Is(u => true))) + rpcClientMock.Setup(p => p.RpcSendAsync("getcontractstate", It.Is(u => true))) .ReturnsAsync(test.Response.Result) .Verifiable(); if (test.Request.Params[0].AsString() == NativeContract.GAS.Hash.ToString() || test.Request.Params[0].AsString().Equals(NativeContract.GAS.Name, System.StringComparison.OrdinalIgnoreCase)) diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index a01c1796b..7e4e9d0e1 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -3,7 +3,7 @@ using Moq; using Moq.Protected; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; using Neo.SmartContract; @@ -170,7 +170,7 @@ public async Task TestGetCommittee() foreach (var test in tests) { var result = await rpc.GetCommitteeAsync(); - Assert.AreEqual(test.Response.Result.ToString(), ((JArray)result.Select(p => (JObject)p).ToArray()).ToString()); + Assert.AreEqual(test.Response.Result.ToString(), ((JArray)result.Select(p => (JToken)p).ToArray()).ToString()); } } @@ -201,7 +201,7 @@ public async Task TestGetRawMempool() { var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.GetRawMempoolAsync).ToLower()); var result = await rpc.GetRawMempoolAsync(); - Assert.AreEqual(test.Response.Result.ToString(), ((JArray)result.Select(p => (JObject)p).ToArray()).ToString()); + Assert.AreEqual(test.Response.Result.ToString(), ((JArray)result.Select(p => (JToken)p).ToArray()).ToString()); } [TestMethod] @@ -305,7 +305,7 @@ public async Task TestInvokeFunction() { var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.InvokeFunctionAsync).ToLower()); var result = await rpc.InvokeFunctionAsync(test.Request.Params[0].AsString(), test.Request.Params[1].AsString(), - ((JArray)test.Request.Params[2]).Select(p => RpcStack.FromJson(p)).ToArray()); + ((JArray)test.Request.Params[2]).Select(p => RpcStack.FromJson((JObject)p)).ToArray()); Assert.AreEqual(test.Response.Result.ToString(), result.ToJson().ToString()); // TODO test verify method @@ -429,7 +429,7 @@ public async Task TestSendFrom() public async Task TestSendMany() { var test = TestUtils.RpcTestCases.Find(p => p.Name == nameof(rpc.SendManyAsync).ToLower()); - var result = await rpc.SendManyAsync(test.Request.Params[0].AsString(), ((JArray)test.Request.Params[1]).Select(p => RpcTransferOut.FromJson(p, rpc.protocolSettings))); + var result = await rpc.SendManyAsync(test.Request.Params[0].AsString(), ((JArray)test.Request.Params[1]).Select(p => RpcTransferOut.FromJson((JObject)p, rpc.protocolSettings))); Assert.AreEqual(test.Response.Result.ToString(), result.ToString()); } diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs index 27c663511..b31a4e818 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs @@ -1,6 +1,6 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.RPC.Models; using System; using System.Linq; @@ -27,137 +27,137 @@ public void TestSetup() [TestMethod()] public void TestRpcAccount() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ImportPrivKeyAsync).ToLower()).Response.Result; - var item = RpcAccount.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ImportPrivKeyAsync).ToLower()).Response.Result; + var item = RpcAccount.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcApplicationLog() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetApplicationLogAsync).ToLower()).Response.Result; - var item = RpcApplicationLog.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetApplicationLogAsync).ToLower()).Response.Result; + var item = RpcApplicationLog.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcBlock() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockAsync).ToLower()).Response.Result; - var item = RpcBlock.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockAsync).ToLower()).Response.Result; + var item = RpcBlock.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } [TestMethod()] public void TestRpcBlockHeader() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockHeaderAsync).ToLower()).Response.Result; - var item = RpcBlockHeader.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockHeaderAsync).ToLower()).Response.Result; + var item = RpcBlockHeader.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } [TestMethod()] public void TestGetContractState() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; - var item = RpcContractState.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; + var item = RpcContractState.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); - var nef = RpcNefFile.FromJson(json["nef"]); + var nef = RpcNefFile.FromJson((JObject)json["nef"]); Assert.AreEqual(json["nef"].ToString(), nef.ToJson().ToString()); } [TestMethod()] public void TestRpcInvokeResult() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.InvokeFunctionAsync).ToLower()).Response.Result; - var item = RpcInvokeResult.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.InvokeFunctionAsync).ToLower()).Response.Result; + var item = RpcInvokeResult.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcMethodToken() { - RpcMethodToken.FromJson(JObject.Parse("{\"hash\": \"0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add\", \"method\":\"test\",\"paramcount\":\"1\",\"hasreturnvalue\":\"true\",\"callflags\":\"All\"}")); + RpcMethodToken.FromJson((JObject)JToken.Parse("{\"hash\": \"0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add\", \"method\":\"test\",\"paramcount\":\"1\",\"hasreturnvalue\":\"true\",\"callflags\":\"All\"}")); } [TestMethod()] public void TestRpcNep17Balances() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17BalancesAsync).ToLower()).Response.Result; - var item = RpcNep17Balances.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17BalancesAsync).ToLower()).Response.Result; + var item = RpcNep17Balances.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } [TestMethod()] public void TestRpcNep17Transfers() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17TransfersAsync).ToLower()).Response.Result; - var item = RpcNep17Transfers.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17TransfersAsync).ToLower()).Response.Result; + var item = RpcNep17Transfers.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } [TestMethod()] public void TestRpcPeers() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetPeersAsync).ToLower()).Response.Result; - var item = RpcPeers.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetPeersAsync).ToLower()).Response.Result; + var item = RpcPeers.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcPlugin() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ListPluginsAsync).ToLower()).Response.Result; - var item = ((JArray)json).Select(p => RpcPlugin.FromJson(p)); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ListPluginsAsync).ToLower()).Response.Result; + var item = ((JArray)json).Select(p => RpcPlugin.FromJson((JObject)p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } [TestMethod()] public void TestRpcRawMemPool() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawMempoolBothAsync).ToLower()).Response.Result; - var item = RpcRawMemPool.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawMempoolBothAsync).ToLower()).Response.Result; + var item = RpcRawMemPool.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcTransaction() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawTransactionAsync).ToLower()).Response.Result; - var item = RpcTransaction.FromJson(json, rpc.protocolSettings); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawTransactionAsync).ToLower()).Response.Result; + var item = RpcTransaction.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } [TestMethod()] public void TestRpcTransferOut() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.SendManyAsync).ToLower()).Request.Params[1]; - var item = ((JArray)json).Select(p => RpcTransferOut.FromJson(p, rpc.protocolSettings)); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.SendManyAsync).ToLower()).Request.Params[1]; + var item = ((JArray)json).Select(p => RpcTransferOut.FromJson((JObject)p, rpc.protocolSettings)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson(rpc.protocolSettings)).ToArray()).ToString()); } [TestMethod()] public void TestRpcValidateAddressResult() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ValidateAddressAsync).ToLower()).Response.Result; - var item = RpcValidateAddressResult.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ValidateAddressAsync).ToLower()).Response.Result; + var item = RpcValidateAddressResult.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcValidator() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNextBlockValidatorsAsync).ToLower()).Response.Result; - var item = ((JArray)json).Select(p => RpcValidator.FromJson(p)); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNextBlockValidatorsAsync).ToLower()).Response.Result; + var item = ((JArray)json).Select(p => RpcValidator.FromJson((JObject)p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } [TestMethod()] public void TestRpcVersion() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetVersionAsync).ToLower()).Response.Result; - var item = RpcVersion.FromJson(json); + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetVersionAsync).ToLower()).Response.Result; + var item = RpcVersion.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } } diff --git a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs index aebf5b11d..6d6120c25 100644 --- a/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs +++ b/tests/Neo.Network.RPC.Tests/UT_TransactionManager.cs @@ -3,7 +3,7 @@ using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; @@ -52,7 +52,7 @@ public static Mock MockRpcClient(UInt160 sender, byte[] script) // calculatenetworkfee var networkfee = new JObject(); networkfee["networkfee"] = 100000000; - mockRpc.Setup(p => p.RpcSendAsync("calculatenetworkfee", It.Is(u => true))) + mockRpc.Setup(p => p.RpcSendAsync("calculatenetworkfee", It.Is(u => true))) .ReturnsAsync(networkfee) .Verifiable(); @@ -85,7 +85,7 @@ public static Mock MockMultiSig(UInt160 multiHash, byte[] script) // calculatenetworkfee var networkfee = new JObject(); networkfee["networkfee"] = 100000000; - mockRpc.Setup(p => p.RpcSendAsync("calculatenetworkfee", It.Is(u => true))) + mockRpc.Setup(p => p.RpcSendAsync("calculatenetworkfee", It.Is(u => true))) .ReturnsAsync(networkfee) .Verifiable(); @@ -118,7 +118,7 @@ public static void MockInvokeScript(Mock mockClient, byte[] script, p State = VMState.HALT }; - mockClient.Setup(p => p.RpcSendAsync("invokescript", It.Is(j => + mockClient.Setup(p => p.RpcSendAsync("invokescript", It.Is(j => Convert.FromBase64String(j[0].AsString()).SequenceEqual(script)))) .ReturnsAsync(result.ToJson()) .Verifiable(); diff --git a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs index c6d6d1f6d..991c7f8b8 100644 --- a/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs +++ b/tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs @@ -1,7 +1,7 @@ using Microsoft.VisualStudio.TestTools.UnitTesting; using Moq; using Neo.Cryptography.ECC; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; using Neo.Network.RPC.Models; using Neo.SmartContract; @@ -87,7 +87,7 @@ public async Task TestClaimGas() var json = new JObject(); json["hash"] = UInt256.Zero.ToString(); - rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); + rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); var tranaction = await walletAPI.ClaimGasAsync(keyPair1.Export()); Assert.AreEqual(testScript.ToHexString(), tranaction.Script.Span.ToHexString()); @@ -104,7 +104,7 @@ public async Task TestTransfer() var json = new JObject(); json["hash"] = UInt256.Zero.ToString(); - rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); + rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); var tranaction = await walletAPI.TransferAsync(NativeContract.GAS.Hash.ToString(), keyPair1.Export(), UInt160.Zero.ToAddress(client.protocolSettings.AddressVersion), 100); Assert.AreEqual(testScript.ToHexString(), tranaction.Script.Span.ToHexString()); @@ -126,7 +126,7 @@ public async Task TestTransferfromMultiSigAccount() var json = new JObject(); json["hash"] = UInt256.Zero.ToString(); - rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); + rpcClientMock.Setup(p => p.RpcSendAsync("sendrawtransaction", It.IsAny())).ReturnsAsync(json); var tranaction = await walletAPI.TransferAsync(NativeContract.GAS.Hash, 1, new[] { keyPair1.PublicKey }, new[] { keyPair1 }, UInt160.Zero, NativeContract.GAS.Factor * 100); Assert.AreEqual(testScript.ToHexString(), tranaction.Script.Span.ToHexString()); @@ -152,7 +152,7 @@ public async Task TestTransferfromMultiSigAccount() public async Task TestWaitTransaction() { Transaction transaction = TestUtils.GetTransaction(); - rpcClientMock.Setup(p => p.RpcSendAsync("getrawtransaction", It.Is(j => j[0].AsString() == transaction.Hash.ToString()))) + rpcClientMock.Setup(p => p.RpcSendAsync("getrawtransaction", It.Is(j => j[0].AsString() == transaction.Hash.ToString()))) .ReturnsAsync(new RpcTransaction { Transaction = transaction, VMState = VMState.HALT, BlockHash = UInt256.Zero, BlockTime = 100, Confirmations = 1 }.ToJson(client.protocolSettings)); var tx = await walletAPI.WaitTransactionAsync(transaction); diff --git a/tests/Neo.Plugins.OracleService.Tests/Neo.Plugins.OracleService.Tests.csproj b/tests/Neo.Plugins.OracleService.Tests/Neo.Plugins.OracleService.Tests.csproj index 1c337c697..d79d2a75f 100644 --- a/tests/Neo.Plugins.OracleService.Tests/Neo.Plugins.OracleService.Tests.csproj +++ b/tests/Neo.Plugins.OracleService.Tests/Neo.Plugins.OracleService.Tests.csproj @@ -6,8 +6,8 @@ - - + +