From 74886898ed47d6f2f33bcb79e0f62ed513d90150 Mon Sep 17 00:00:00 2001 From: Shuai Date: Thu, 14 Jul 2022 17:32:25 +0800 Subject: [PATCH 01/48] update neo --- src/Directory.Build.props | 2 +- src/RpcServer/Diagnostic.cs | 4 ++-- src/StateService/StatePlugin.cs | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 43b09706d..aa38f9152 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -21,7 +21,7 @@ - + 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/StateService/StatePlugin.cs b/src/StateService/StatePlugin.cs index ef20d873e..11a9e9715 100644 --- a/src/StateService/StatePlugin.cs +++ b/src/StateService/StatePlugin.cs @@ -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) From 3cfa81633b5f6b062d478701db3c5712f209d5ce Mon Sep 17 00:00:00 2001 From: Shuai Date: Mon, 25 Jul 2022 11:37:31 +0800 Subject: [PATCH 02/48] CI-1380 --- src/ApplicationLogs/LogReader.cs | 22 ++++---- src/Directory.Build.props | 2 +- src/OracleService/OracleService.csproj | 3 +- src/RpcClient/Models/RpcAccount.cs | 6 +- src/RpcClient/Models/RpcApplicationLog.cs | 24 ++++---- src/RpcClient/Models/RpcBlock.cs | 8 +-- src/RpcClient/Models/RpcBlockHeader.cs | 8 +-- src/RpcClient/Models/RpcContractState.cs | 8 +-- src/RpcClient/Models/RpcFoundStates.cs | 6 +- src/RpcClient/Models/RpcInvokeResult.cs | 16 +++--- src/RpcClient/Models/RpcMethodToken.cs | 4 +- src/RpcClient/Models/RpcNativeContract.cs | 10 ++-- src/RpcClient/Models/RpcNefFile.cs | 4 +- src/RpcClient/Models/RpcNep17Balances.cs | 14 ++--- src/RpcClient/Models/RpcNep17Transfers.cs | 14 ++--- src/RpcClient/Models/RpcPeers.cs | 14 ++--- src/RpcClient/Models/RpcPlugin.cs | 10 ++-- src/RpcClient/Models/RpcRawMemPool.cs | 12 ++-- src/RpcClient/Models/RpcRequest.cs | 10 ++-- src/RpcClient/Models/RpcResponse.cs | 20 +++---- src/RpcClient/Models/RpcStateRoot.cs | 4 +- src/RpcClient/Models/RpcTransaction.cs | 10 ++-- src/RpcClient/Models/RpcTransferOut.cs | 6 +- src/RpcClient/Models/RpcUnclaimedGas.cs | 8 +-- .../Models/RpcValidateAddressResult.cs | 8 +-- src/RpcClient/Models/RpcValidator.cs | 8 +-- src/RpcClient/Models/RpcVersion.cs | 14 ++--- src/RpcClient/RpcClient.cs | 40 ++++++------- src/RpcClient/StateAPI.cs | 8 +-- src/RpcClient/Utility.cs | 35 ++++++------ src/RpcServer/RpcServer.Blockchain.cs | 56 +++++++++---------- src/RpcServer/RpcServer.Node.cs | 22 ++++---- src/RpcServer/RpcServer.SmartContract.cs | 32 +++++------ src/RpcServer/RpcServer.Utilities.cs | 10 ++-- src/RpcServer/RpcServer.Wallet.cs | 40 ++++++------- src/RpcServer/RpcServer.cs | 28 +++++----- src/RpcServer/Utility.cs | 14 ++--- src/StateService/Network/StateRoot.cs | 4 +- src/StateService/StatePlugin.cs | 14 ++--- src/StatesDumper/StatesDumper.cs | 6 +- .../Trackers/NEP-11/Nep11Tracker.cs | 12 ++-- .../Trackers/NEP-17/Nep17Tracker.cs | 10 ++-- src/TokensTracker/Trackers/TrackerBase.cs | 6 +- tests/Neo.Network.RPC.Tests/TestUtils.cs | 8 +-- tests/Neo.Network.RPC.Tests/UT_Nep17API.cs | 4 +- tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 6 +- tests/Neo.Network.RPC.Tests/UT_RpcModels.cs | 36 ++++++------ .../UT_TransactionManager.cs | 8 +-- tests/Neo.Network.RPC.Tests/UT_WalletAPI.cs | 10 ++-- 49 files changed, 342 insertions(+), 340 deletions(-) diff --git a/src/ApplicationLogs/LogReader.cs b/src/ApplicationLogs/LogReader.cs index 35b38f0b1..1c6912045 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)); + var raw = 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)) { @@ -80,13 +80,13 @@ public JObject GetApplicationLog(JArray _params) return raw; } - public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) + public static JToken TxLogToJson(Blockchain.ApplicationExecuted appExec) { global::System.Diagnostics.Debug.Assert(appExec.Transaction != null); var txJson = new JObject(); txJson["txid"] = appExec.Transaction.Hash.ToString(); - JObject trigger = new JObject(); + JToken trigger = new JObject(); trigger["trigger"] = appExec.Trigger; trigger["vmstate"] = appExec.VMState; trigger["exception"] = GetExceptionMessage(appExec.Exception); @@ -101,7 +101,7 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) } trigger["notifications"] = appExec.Notifications.Select(q => { - JObject notification = new JObject(); + JToken notification = new JObject(); notification["contract"] = q.ScriptHash.ToString(); notification["eventname"] = q.EventName; try @@ -115,11 +115,11 @@ public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) return notification; }).ToArray(); - txJson["executions"] = new List() { trigger }.ToArray(); + txJson["executions"] = new List() { trigger }.ToArray(); return txJson; } - public static JObject BlockLogToJson(Block block, IReadOnlyList applicationExecutedList) + public static JToken BlockLogToJson(Block block, IReadOnlyList applicationExecutedList) { var blocks = applicationExecutedList.Where(p => p.Transaction is null).ToArray(); if (blocks.Length > 0) @@ -127,10 +127,10 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList(); + var triggerList = new List(); foreach (var appExec in blocks) { - JObject trigger = new JObject(); + JToken trigger = new JObject(); trigger["trigger"] = appExec.Trigger; trigger["vmstate"] = appExec.VMState; trigger["gasconsumed"] = appExec.GasConsumed.ToString(); @@ -144,7 +144,7 @@ public static JObject BlockLogToJson(Block block, IReadOnlyList { - JObject notification = new JObject(); + JToken notification = new JObject(); notification["contract"] = q.ScriptHash.ToString(); notification["eventname"] = q.EventName; try diff --git a/src/Directory.Build.props b/src/Directory.Build.props index aa38f9152..15265cbe2 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -21,7 +21,7 @@ - + diff --git a/src/OracleService/OracleService.csproj b/src/OracleService/OracleService.csproj index fae818cc8..0ef207b61 100644 --- a/src/OracleService/OracleService.csproj +++ b/src/OracleService/OracleService.csproj @@ -1,4 +1,4 @@ - + Neo.Plugins.OracleService @@ -7,6 +7,7 @@ + diff --git a/src/RpcClient/Models/RpcAccount.cs b/src/RpcClient/Models/RpcAccount.cs index ab396279a..75ac7a209 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 { @@ -22,7 +22,7 @@ public class RpcAccount public bool WatchOnly { get; set; } - public JObject ToJson() + public JToken ToJson() { return new JObject { @@ -33,7 +33,7 @@ public JObject ToJson() }; } - public static RpcAccount FromJson(JObject json) + public static RpcAccount FromJson(JToken json) { return new RpcAccount { diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index 9f2041d10..f684c8a8b 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.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 Neo.SmartContract; using Neo.VM; using Neo.VM.Types; @@ -25,9 +25,9 @@ public class RpcApplicationLog public List Executions { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new JObject(); + JToken json = new JObject(); if (TxId != null) json["txid"] = TxId.ToString(); if (BlockHash != null) @@ -36,7 +36,7 @@ public JObject ToJson() return json; } - public static RpcApplicationLog FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcApplicationLog FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcApplicationLog { @@ -61,9 +61,9 @@ public class Execution public List Notifications { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["trigger"] = Trigger; json["vmstate"] = VMState; json["gasconsumed"] = GasConsumed.ToString(); @@ -73,12 +73,12 @@ public JObject ToJson() return json; } - public static Execution FromJson(JObject json, ProtocolSettings protocolSettings) + public static Execution FromJson(JToken json, ProtocolSettings protocolSettings) { return new Execution { - Trigger = json["trigger"].TryGetEnum(), - VMState = json["vmstate"].TryGetEnum(), + Trigger = json["trigger"].AsEnum(), + VMState = json["vmstate"].AsEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), ExceptionMessage = json["exception"]?.AsString(), Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).ToList(), @@ -95,16 +95,16 @@ public class RpcNotifyEventArgs public StackItem State { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["contract"] = Contract.ToString(); json["eventname"] = EventName; json["state"] = State.ToJson(); return json; } - public static RpcNotifyEventArgs FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcNotifyEventArgs FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcNotifyEventArgs { diff --git a/src/RpcClient/Models/RpcBlock.cs b/src/RpcClient/Models/RpcBlock.cs index bcc9fe904..15960fa75 100644 --- a/src/RpcClient/Models/RpcBlock.cs +++ b/src/RpcClient/Models/RpcBlock.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 Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models @@ -21,15 +21,15 @@ public class RpcBlock public UInt256 NextBlockHash { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = Utility.BlockToJson(Block, protocolSettings); + JToken json = Utility.BlockToJson(Block, protocolSettings); json["confirmations"] = Confirmations; json["nextblockhash"] = NextBlockHash?.ToString(); return json; } - public static RpcBlock FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcBlock FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcBlock { diff --git a/src/RpcClient/Models/RpcBlockHeader.cs b/src/RpcClient/Models/RpcBlockHeader.cs index 8ef1f4dd6..7be210528 100644 --- a/src/RpcClient/Models/RpcBlockHeader.cs +++ b/src/RpcClient/Models/RpcBlockHeader.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 Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models @@ -21,15 +21,15 @@ public class RpcBlockHeader public UInt256 NextBlockHash { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = Header.ToJson(protocolSettings); + JToken json = Header.ToJson(protocolSettings); json["confirmations"] = Confirmations; json["nextblockhash"] = NextBlockHash?.ToString(); return json; } - public static RpcBlockHeader FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcBlockHeader FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcBlockHeader { diff --git a/src/RpcClient/Models/RpcContractState.cs b/src/RpcClient/Models/RpcContractState.cs index def5fba55..dfae260d4 100644 --- a/src/RpcClient/Models/RpcContractState.cs +++ b/src/RpcClient/Models/RpcContractState.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 Neo.SmartContract; using Neo.SmartContract.Manifest; @@ -18,12 +18,12 @@ public class RpcContractState { public ContractState ContractState { get; set; } - public JObject ToJson() + public JToken ToJson() { return ContractState.ToJson(); } - public static RpcContractState FromJson(JObject json) + public static RpcContractState FromJson(JToken json) { return new RpcContractState { @@ -33,7 +33,7 @@ public static RpcContractState FromJson(JObject json) UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), Nef = RpcNefFile.FromJson(json["nef"]), - Manifest = ContractManifest.FromJson(json["manifest"]) + Manifest = ContractManifest.FromJson((JObject)json["manifest"]) } }; } diff --git a/src/RpcClient/Models/RpcFoundStates.cs b/src/RpcClient/Models/RpcFoundStates.cs index 755d771c8..4a57b13ff 100644 --- a/src/RpcClient/Models/RpcFoundStates.cs +++ b/src/RpcClient/Models/RpcFoundStates.cs @@ -10,7 +10,7 @@ using System; using System.Linq; -using Neo.IO.Json; +using Neo.Json; namespace Neo.Network.RPC.Models { @@ -21,7 +21,7 @@ public class RpcFoundStates public byte[] FirstProof; public byte[] LastProof; - public static RpcFoundStates FromJson(JObject json) + public static RpcFoundStates FromJson(JToken json) { return new RpcFoundStates { @@ -37,7 +37,7 @@ public static RpcFoundStates FromJson(JObject json) }; } - static byte[] ProofFromJson(JObject json) + static byte[] ProofFromJson(JToken json) => json == null ? null : Convert.FromBase64String(json.AsString()); } } diff --git a/src/RpcClient/Models/RpcInvokeResult.cs b/src/RpcClient/Models/RpcInvokeResult.cs index 4516b5923..d56954f44 100644 --- a/src/RpcClient/Models/RpcInvokeResult.cs +++ b/src/RpcClient/Models/RpcInvokeResult.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 Neo.VM; using Neo.VM.Types; using System; @@ -32,9 +32,9 @@ public class RpcInvokeResult public string Session { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["script"] = Script; json["state"] = State; json["gasconsumed"] = GasConsumed.ToString(); @@ -53,12 +53,12 @@ public JObject ToJson() return json; } - public static RpcInvokeResult FromJson(JObject json) + public static RpcInvokeResult FromJson(JToken json) { RpcInvokeResult invokeScriptResult = new() { Script = json["script"].AsString(), - State = json["state"].TryGetEnum(), + State = json["state"].AsEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), }; invokeScriptResult.Exception = json["exception"]?.AsString(); @@ -79,15 +79,15 @@ public class RpcStack public string Value { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["type"] = Type; json["value"] = Value; return json; } - public static RpcStack FromJson(JObject json) + public static RpcStack FromJson(JToken json) { return new RpcStack { diff --git a/src/RpcClient/Models/RpcMethodToken.cs b/src/RpcClient/Models/RpcMethodToken.cs index 7734678b0..464bce712 100644 --- a/src/RpcClient/Models/RpcMethodToken.cs +++ b/src/RpcClient/Models/RpcMethodToken.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 Neo.SmartContract; using System; @@ -16,7 +16,7 @@ namespace Neo.Network.RPC.Models { class RpcMethodToken { - public static MethodToken FromJson(JObject json) + public static MethodToken FromJson(JToken json) { return new MethodToken { diff --git a/src/RpcClient/Models/RpcNativeContract.cs b/src/RpcClient/Models/RpcNativeContract.cs index 996611635..0d498d93b 100644 --- a/src/RpcClient/Models/RpcNativeContract.cs +++ b/src/RpcClient/Models/RpcNativeContract.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 Neo.SmartContract; using Neo.SmartContract.Manifest; using System.Linq; @@ -23,19 +23,19 @@ public class RpcNativeContract public ContractManifest Manifest { get; set; } public uint[] UpdateHistory { get; set; } - public static RpcNativeContract FromJson(JObject json) + public static RpcNativeContract FromJson(JToken json) { return new RpcNativeContract { 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() + Manifest = ContractManifest.FromJson((JObject)json["manifest"]), + UpdateHistory = ((JArray)json["updatehistory"]).Select(u => (uint)u.GetInt32()).ToArray() }; } - public JObject ToJson() + public JToken ToJson() { return new JObject { diff --git a/src/RpcClient/Models/RpcNefFile.cs b/src/RpcClient/Models/RpcNefFile.cs index 34663fe13..72fc33edf 100644 --- a/src/RpcClient/Models/RpcNefFile.cs +++ b/src/RpcClient/Models/RpcNefFile.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 Neo.SmartContract; using System; using System.Linq; @@ -17,7 +17,7 @@ namespace Neo.Network.RPC.Models { class RpcNefFile { - public static NefFile FromJson(JObject json) + public static NefFile FromJson(JToken json) { return new NefFile { diff --git a/src/RpcClient/Models/RpcNep17Balances.cs b/src/RpcClient/Models/RpcNep17Balances.cs index af5b3c483..1e96effbf 100644 --- a/src/RpcClient/Models/RpcNep17Balances.cs +++ b/src/RpcClient/Models/RpcNep17Balances.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 Neo.Wallets; using System.Collections.Generic; using System.Linq; @@ -22,15 +22,15 @@ public class RpcNep17Balances public List Balances { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = new(); + var json = new JObject(); json["balance"] = Balances.Select(p => p.ToJson()).ToArray(); json["address"] = UserScriptHash.ToAddress(protocolSettings.AddressVersion); return json; } - public static RpcNep17Balances FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcNep17Balances FromJson(JToken json, ProtocolSettings protocolSettings) { RpcNep17Balances nep17Balance = new() { @@ -49,16 +49,16 @@ public class RpcNep17Balance public uint LastUpdatedBlock { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["assethash"] = AssetHash.ToString(); json["amount"] = Amount.ToString(); json["lastupdatedblock"] = LastUpdatedBlock; return json; } - public static RpcNep17Balance FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcNep17Balance FromJson(JToken json, ProtocolSettings protocolSettings) { RpcNep17Balance balance = new() { diff --git a/src/RpcClient/Models/RpcNep17Transfers.cs b/src/RpcClient/Models/RpcNep17Transfers.cs index 3e8da04ea..b1c74f618 100644 --- a/src/RpcClient/Models/RpcNep17Transfers.cs +++ b/src/RpcClient/Models/RpcNep17Transfers.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 Neo.Wallets; using System.Collections.Generic; using System.Linq; @@ -24,16 +24,16 @@ public class RpcNep17Transfers public List Received { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = new(); + var json = new JObject(); json["sent"] = Sent.Select(p => p.ToJson(protocolSettings)).ToArray(); json["received"] = Received.Select(p => p.ToJson(protocolSettings)).ToArray(); json["address"] = UserScriptHash.ToAddress(protocolSettings.AddressVersion); return json; } - public static RpcNep17Transfers FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcNep17Transfers FromJson(JToken json, ProtocolSettings protocolSettings) { RpcNep17Transfers transfers = new() { @@ -61,9 +61,9 @@ public class RpcNep17Transfer public UInt256 TxHash { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = new(); + var json = new JObject(); json["timestamp"] = TimestampMS; json["assethash"] = AssetHash.ToString(); json["transferaddress"] = UserScriptHash?.ToAddress(protocolSettings.AddressVersion); @@ -74,7 +74,7 @@ public JObject ToJson(ProtocolSettings protocolSettings) return json; } - public static RpcNep17Transfer FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcNep17Transfer FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcNep17Transfer { diff --git a/src/RpcClient/Models/RpcPeers.cs b/src/RpcClient/Models/RpcPeers.cs index 95a41e4d9..765f4ecd0 100644 --- a/src/RpcClient/Models/RpcPeers.cs +++ b/src/RpcClient/Models/RpcPeers.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.Linq; namespace Neo.Network.RPC.Models @@ -21,16 +21,16 @@ public class RpcPeers public RpcPeer[] Connected { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["unconnected"] = new JArray(Unconnected.Select(p => p.ToJson())); json["bad"] = new JArray(Bad.Select(p => p.ToJson())); json["connected"] = new JArray(Connected.Select(p => p.ToJson())); return json; } - public static RpcPeers FromJson(JObject json) + public static RpcPeers FromJson(JToken json) { return new RpcPeers { @@ -47,15 +47,15 @@ public class RpcPeer public int Port { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["address"] = Address; json["port"] = Port; return json; } - public static RpcPeer FromJson(JObject json) + public static RpcPeer FromJson(JToken json) { return new RpcPeer { diff --git a/src/RpcClient/Models/RpcPlugin.cs b/src/RpcClient/Models/RpcPlugin.cs index d75bd0481..8cbb958e3 100644 --- a/src/RpcClient/Models/RpcPlugin.cs +++ b/src/RpcClient/Models/RpcPlugin.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.Linq; namespace Neo.Network.RPC.Models @@ -21,16 +21,16 @@ public class RpcPlugin public string[] Interfaces { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); 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; } - public static RpcPlugin FromJson(JObject json) + public static RpcPlugin FromJson(JToken json) { return new RpcPlugin { diff --git a/src/RpcClient/Models/RpcRawMemPool.cs b/src/RpcClient/Models/RpcRawMemPool.cs index 6e2d9cdb6..ba54fa707 100644 --- a/src/RpcClient/Models/RpcRawMemPool.cs +++ b/src/RpcClient/Models/RpcRawMemPool.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.Collections.Generic; using System.Linq; @@ -22,16 +22,16 @@ public class RpcRawMemPool public List UnVerified { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); 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; } - public static RpcRawMemPool FromJson(JObject json) + public static RpcRawMemPool FromJson(JToken json) { return new RpcRawMemPool { diff --git a/src/RpcClient/Models/RpcRequest.cs b/src/RpcClient/Models/RpcRequest.cs index e46dde283..c1edc65bb 100644 --- a/src/RpcClient/Models/RpcRequest.cs +++ b/src/RpcClient/Models/RpcRequest.cs @@ -8,22 +8,22 @@ // 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) + public static RpcRequest FromJson(JToken json) { return new RpcRequest { @@ -34,7 +34,7 @@ public static RpcRequest FromJson(JObject json) }; } - public JObject ToJson() + public JToken ToJson() { var json = new JObject(); json["id"] = Id; diff --git a/src/RpcClient/Models/RpcResponse.cs b/src/RpcClient/Models/RpcResponse.cs index 898eb7f77..a72dd1535 100644 --- a/src/RpcClient/Models/RpcResponse.cs +++ b/src/RpcClient/Models/RpcResponse.cs @@ -8,23 +8,23 @@ // 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; } - public static RpcResponse FromJson(JObject json) + public static RpcResponse FromJson(JToken json) { RpcResponse response = new() { @@ -41,9 +41,9 @@ public static RpcResponse FromJson(JObject json) return response; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["id"] = Id; json["jsonrpc"] = JsonRpc; json["error"] = Error?.ToJson(); @@ -58,9 +58,9 @@ public class RpcResponseError public string Message { get; set; } - public JObject Data { get; set; } + public JToken Data { get; set; } - public static RpcResponseError FromJson(JObject json) + public static RpcResponseError FromJson(JToken json) { return new RpcResponseError { @@ -70,9 +70,9 @@ public static RpcResponseError FromJson(JObject json) }; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["code"] = Code; json["message"] = Message; json["data"] = Data; diff --git a/src/RpcClient/Models/RpcStateRoot.cs b/src/RpcClient/Models/RpcStateRoot.cs index 9991c5173..d4d8b1836 100644 --- a/src/RpcClient/Models/RpcStateRoot.cs +++ b/src/RpcClient/Models/RpcStateRoot.cs @@ -9,7 +9,7 @@ // modifications are permitted. using System.Linq; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models @@ -21,7 +21,7 @@ public class RpcStateRoot public UInt256 RootHash; public Witness Witness; - public static RpcStateRoot FromJson(JObject json) + public static RpcStateRoot FromJson(JToken json) { return new RpcStateRoot { diff --git a/src/RpcClient/Models/RpcTransaction.cs b/src/RpcClient/Models/RpcTransaction.cs index b0a0daf06..d1de3e33b 100644 --- a/src/RpcClient/Models/RpcTransaction.cs +++ b/src/RpcClient/Models/RpcTransaction.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 Neo.Network.P2P.Payloads; using Neo.VM; @@ -26,9 +26,9 @@ public class RpcTransaction public VMState? VMState { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { - JObject json = Utility.TransactionToJson(Transaction, protocolSettings); + JToken json = Utility.TransactionToJson(Transaction, protocolSettings); if (Confirmations != null) { json["blockhash"] = BlockHash.ToString(); @@ -42,7 +42,7 @@ public JObject ToJson(ProtocolSettings protocolSettings) return json; } - public static RpcTransaction FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcTransaction FromJson(JToken json, ProtocolSettings protocolSettings) { RpcTransaction transaction = new RpcTransaction { @@ -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"]?.AsEnum(); } return transaction; } diff --git a/src/RpcClient/Models/RpcTransferOut.cs b/src/RpcClient/Models/RpcTransferOut.cs index 742597068..0a3c96b5b 100644 --- a/src/RpcClient/Models/RpcTransferOut.cs +++ b/src/RpcClient/Models/RpcTransferOut.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 Neo.Wallets; namespace Neo.Network.RPC.Models @@ -21,7 +21,7 @@ public class RpcTransferOut public string Value { get; set; } - public JObject ToJson(ProtocolSettings protocolSettings) + public JToken ToJson(ProtocolSettings protocolSettings) { return new JObject { @@ -31,7 +31,7 @@ public JObject ToJson(ProtocolSettings protocolSettings) }; } - public static RpcTransferOut FromJson(JObject json, ProtocolSettings protocolSettings) + public static RpcTransferOut FromJson(JToken json, ProtocolSettings protocolSettings) { return new RpcTransferOut { diff --git a/src/RpcClient/Models/RpcUnclaimedGas.cs b/src/RpcClient/Models/RpcUnclaimedGas.cs index eb0c2d719..5667ab1dd 100644 --- a/src/RpcClient/Models/RpcUnclaimedGas.cs +++ b/src/RpcClient/Models/RpcUnclaimedGas.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 { @@ -18,15 +18,15 @@ public class RpcUnclaimedGas public string Address { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["unclaimed"] = Unclaimed.ToString(); json["address"] = Address; return json; } - public static RpcUnclaimedGas FromJson(JObject json) + public static RpcUnclaimedGas FromJson(JToken json) { return new RpcUnclaimedGas { diff --git a/src/RpcClient/Models/RpcValidateAddressResult.cs b/src/RpcClient/Models/RpcValidateAddressResult.cs index 2c671d289..0da5f6c7e 100644 --- a/src/RpcClient/Models/RpcValidateAddressResult.cs +++ b/src/RpcClient/Models/RpcValidateAddressResult.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 { @@ -18,15 +18,15 @@ public class RpcValidateAddressResult public bool IsValid { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["address"] = Address; json["isvalid"] = IsValid; return json; } - public static RpcValidateAddressResult FromJson(JObject json) + public static RpcValidateAddressResult FromJson(JToken json) { return new RpcValidateAddressResult { diff --git a/src/RpcClient/Models/RpcValidator.cs b/src/RpcClient/Models/RpcValidator.cs index 21b02a052..a4dd76ec8 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 @@ -19,15 +19,15 @@ public class RpcValidator public BigInteger Votes { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["publickey"] = PublicKey; json["votes"] = Votes.ToString(); return json; } - public static RpcValidator FromJson(JObject json) + public static RpcValidator FromJson(JToken json) { return new RpcValidator { diff --git a/src/RpcClient/Models/RpcVersion.cs b/src/RpcClient/Models/RpcVersion.cs index ef5327289..c27cb4dd7 100644 --- a/src/RpcClient/Models/RpcVersion.cs +++ b/src/RpcClient/Models/RpcVersion.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 { @@ -26,9 +26,9 @@ public class RpcProtocol public int MemoryPoolMaxTransactions { get; set; } public ulong InitialGasDistribution { get; set; } - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["network"] = Network; json["validatorscount"] = ValidatorsCount; json["msperblock"] = MillisecondsPerBlock; @@ -41,7 +41,7 @@ public JObject ToJson() return json; } - public static RpcProtocol FromJson(JObject json) + public static RpcProtocol FromJson(JToken json) { return new() { @@ -68,9 +68,9 @@ public static RpcProtocol FromJson(JObject json) public RpcProtocol Protocol { get; set; } = new(); - public JObject ToJson() + public JToken ToJson() { - JObject json = new(); + var json = new JObject(); json["network"] = Protocol.Network; // Obsolete json["tcpport"] = TcpPort; json["wsport"] = WsPort; @@ -80,7 +80,7 @@ public JObject ToJson() return json; } - public static RpcVersion FromJson(JObject json) + public static RpcVersion FromJson(JToken json) { return new() { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 3ee432f9d..982632e3f 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.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.Network.RPC.Models; using Neo.SmartContract; @@ -79,7 +79,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 +91,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(JToken.Parse(content)); response.RawResponse = content; if (response.Error != null) @@ -132,20 +132,20 @@ 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); return response.Result; } - + public static string GetRpcName([CallerMemberName] string methodName = null) { return new Regex("(.*?)(Hex|Both)?(Async)?").Replace(methodName, "$1").ToLowerInvariant(); @@ -245,7 +245,7 @@ public async Task GetContractStateAsync(string hash) return ContractStateFromJson(result); } - public static ContractState ContractStateFromJson(JObject json) + public static ContractState ContractStateFromJson(JToken json) { return new ContractState { @@ -253,7 +253,7 @@ public static ContractState ContractStateFromJson(JObject json) UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), Nef = RpcNefFile.FromJson(json["nef"]), - Manifest = ContractManifest.FromJson(json["manifest"]) + Manifest = ContractManifest.FromJson((JObject)json["manifest"]) }; } @@ -421,7 +421,7 @@ 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()); @@ -436,7 +436,7 @@ 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()); @@ -452,16 +452,16 @@ public async Task GetUnclaimedGasAsync(string address) } - public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id) + public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id) { const int count = 100; while (true) { var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); var array = (JArray)result; - foreach (var jObject in array) + foreach (var JToken in array) { - yield return jObject; + yield return JToken; } if (array.Count < count) break; } @@ -475,14 +475,14 @@ public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, s /// /// /// - public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id, int count) + public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id, int count) { var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); if (result is JArray { Count: > 0 } array) { - foreach (var jObject in array) + foreach (var JToken in array) { - yield return jObject; + yield return JToken; } } } @@ -604,7 +604,7 @@ public async Task OpenWalletAsync(string path, string password) /// Transfer from the specified address to the destination address. /// /// 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) + public async Task SendFromAsync(string assetId, string fromAddress, string toAddress, string amount) { return await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), fromAddress.AsScriptHash(), toAddress.AsScriptHash(), amount).ConfigureAwait(false); @@ -614,9 +614,9 @@ public async Task SendFromAsync(string assetId, string fromAddress, str /// Bulk transfer order, and you can specify a sender address. /// /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. - public async Task SendManyAsync(string fromAddress, IEnumerable outputs) + public async Task SendManyAsync(string fromAddress, IEnumerable outputs) { - var parameters = new List(); + var parameters = new List(); if (!string.IsNullOrEmpty(fromAddress)) { parameters.Add(fromAddress.AsScriptHash()); @@ -630,7 +630,7 @@ public async Task SendManyAsync(string fromAddress, IEnumerable /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. - public async Task SendToAddressAsync(string assetId, string address, string amount) + public async Task SendToAddressAsync(string assetId, string address, string amount) { return await RpcSendAsync(GetRpcName(), assetId.AsScriptHash(), address.AsScriptHash(), amount) .ConfigureAwait(false); diff --git a/src/RpcClient/StateAPI.cs b/src/RpcClient/StateAPI.cs index 52c45438c..13e758f76 100644 --- a/src/RpcClient/StateAPI.cs +++ b/src/RpcClient/StateAPI.cs @@ -14,7 +14,7 @@ using System.Runtime.CompilerServices; using System.Threading; using System.Threading.Tasks; -using Neo.IO.Json; +using Neo.Json; using Neo.Network.RPC.Models; namespace Neo.Network.RPC @@ -57,11 +57,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); diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index 9d7881194..e3eb9232d 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; @@ -18,6 +18,7 @@ using System; using System.Linq; using System.Numerics; +using Neo.Json; using Array = Neo.VM.Types.Array; using Buffer = Neo.VM.Types.Buffer; @@ -36,14 +37,14 @@ 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(); return addressOrScriptHash.Length < 40 ? addressOrScriptHash.ToScriptHash(protocolSettings.AddressVersion) : UInt160.Parse(addressOrScriptHash); } - + public static string AsScriptHash(this string addressOrScriptHash) { foreach (var native in NativeContract.Contracts) @@ -127,7 +128,7 @@ public static BigInteger ToBigInteger(this decimal amount, uint decimals) return res; } - public static Block BlockFromJson(JObject json, ProtocolSettings protocolSettings) + public static Block BlockFromJson(JToken json, ProtocolSettings protocolSettings) { return new Block() { @@ -136,14 +137,14 @@ public static Block BlockFromJson(JObject json, ProtocolSettings protocolSetting }; } - public static JObject BlockToJson(Block block, ProtocolSettings protocolSettings) + public static JToken BlockToJson(Block block, ProtocolSettings protocolSettings) { - JObject json = block.ToJson(protocolSettings); + JToken json = block.ToJson(protocolSettings); json["tx"] = block.Transactions.Select(p => TransactionToJson(p, protocolSettings)).ToArray(); return json; } - public static Header HeaderFromJson(JObject json, ProtocolSettings protocolSettings) + public static Header HeaderFromJson(JToken json, ProtocolSettings protocolSettings) { return new Header { @@ -159,7 +160,7 @@ public static Header HeaderFromJson(JObject json, ProtocolSettings protocolSetti }; } - public static Transaction TransactionFromJson(JObject json, ProtocolSettings protocolSettings) + public static Transaction TransactionFromJson(JToken json, ProtocolSettings protocolSettings) { return new Transaction { @@ -175,15 +176,15 @@ public static Transaction TransactionFromJson(JObject json, ProtocolSettings pro }; } - public static JObject TransactionToJson(Transaction tx, ProtocolSettings protocolSettings) + public static JToken TransactionToJson(Transaction tx, ProtocolSettings protocolSettings) { - JObject json = tx.ToJson(protocolSettings); + JToken json = tx.ToJson(protocolSettings); json["sysfee"] = tx.SystemFee.ToString(); json["netfee"] = tx.NetworkFee.ToString(); return json; } - public static Signer SignerFromJson(JObject json, ProtocolSettings protocolSettings) + public static Signer SignerFromJson(JToken json, ProtocolSettings protocolSettings) { return new Signer { @@ -194,7 +195,7 @@ public static Signer SignerFromJson(JObject json, ProtocolSettings protocolSetti }; } - public static TransactionAttribute TransactionAttributeFromJson(JObject json) + public static TransactionAttribute TransactionAttributeFromJson(JToken json) { TransactionAttributeType usage = Enum.Parse(json["type"].AsString()); return usage switch @@ -210,7 +211,7 @@ public static TransactionAttribute TransactionAttributeFromJson(JObject json) }; } - public static Witness WitnessFromJson(JObject json) + public static Witness WitnessFromJson(JToken json) { return new Witness { @@ -218,10 +219,10 @@ public static Witness WitnessFromJson(JObject json) VerificationScript = Convert.FromBase64String(json["verification"].AsString()) }; } - - public static StackItem StackItemFromJson(JObject json) + + public static StackItem StackItemFromJson(JToken json) { - StackItemType type = json["type"].TryGetEnum(); + StackItemType type = json["type"].AsEnum(); switch (type) { case StackItemType.Boolean: @@ -262,7 +263,7 @@ public static string GetIteratorId(this StackItem item) { if (item is InteropInterface iop) { - var json = iop.GetInterface(); + var json = iop.GetInterface(); return json["id"]?.GetString(); } return null; diff --git a/src/RpcServer/RpcServer.Blockchain.cs b/src/RpcServer/RpcServer.Blockchain.cs index 822f282cf..d9511bf18 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; @@ -50,7 +50,7 @@ protected virtual JObject GetBlock(JArray _params) throw new RpcException(-100, "Unknown block"); if (verbose) { - JObject json = Utility.BlockToJson(block, system.Settings); + JToken json = Utility.BlockToJson(block, system.Settings); json["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - block.Index + 1; UInt256 hash = NativeContract.Ledger.GetBlockHash(snapshot, block.Index + 1); if (hash != null) @@ -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; @@ -106,7 +106,7 @@ protected virtual JObject GetBlockHeader(JArray _params) if (verbose) { - JObject json = header.ToJson(system.Settings); + JToken json = header.ToJson(system.Settings); json["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - header.Index + 1; UInt256 hash = NativeContract.Ledger.GetBlockHash(snapshot, header.Index + 1); if (hash != null) @@ -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(); + var json = new JObject(); 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(); @@ -165,7 +165,7 @@ protected virtual JObject GetRawTransaction(JArray _params) tx ??= state?.Transaction; if (tx is null) throw new RpcException(-100, "Unknown transaction"); if (!verbose) return Convert.ToBase64String(tx.ToArray()); - JObject json = Utility.TransactionToJson(tx, system.Settings); + JToken json = Utility.TransactionToJson(tx, system.Settings); if (state is not null) { TrimmedBlock block = NativeContract.Ledger.GetTrimmedBlock(snapshot, NativeContract.Ledger.GetBlockHash(snapshot, state.BlockIndex)); @@ -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,13 +207,13 @@ 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); return validators.Select(p => { - JObject validator = new(); + var validator = new JObject(); validator["publickey"] = p.ToString(); validator["votes"] = (int)NativeContract.NEO.GetCandidateVote(snapshot, p); return validator; @@ -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; @@ -230,7 +230,7 @@ protected virtual JObject GetCandidates(JArray _params) script = sb.EmitDynamicCall(NativeContract.NEO.Hash, "getCandidates", null).ToArray(); } using ApplicationEngine engine = ApplicationEngine.Run(script, snapshot, settings: system.Settings, gas: settings.MaxGasInvoke); - JObject json = new(); + var json = new JObject(); try { var resultstack = engine.ResultStack.ToArray(); @@ -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..713b39292 100644 --- a/src/RpcServer/RpcServer.Node.cs +++ b/src/RpcServer/RpcServer.Node.cs @@ -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,18 +23,18 @@ 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(); + var json = new JObject(); json["unconnected"] = new JArray(localNode.GetUnconnectedPeers().Select(p => { - JObject peerJson = new(); + var peerJson = new JObject(); peerJson["address"] = p.Address.ToString(); peerJson["port"] = p.Port; return peerJson; @@ -42,7 +42,7 @@ protected virtual JObject GetPeers(JArray _params) json["bad"] = new JArray(); //badpeers has been removed json["connected"] = new JArray(localNode.GetRemoteNodes().Select(p => { - JObject peerJson = new(); + var peerJson = new JObject(); peerJson["address"] = p.Remote.Address.ToString(); peerJson["port"] = p.ListenerTcpPort; return peerJson; @@ -50,7 +50,7 @@ protected virtual JObject GetPeers(JArray _params) return json; } - private static JObject GetRelayResult(VerifyResult reason, UInt256 hash) + private static JToken GetRelayResult(VerifyResult reason, UInt256 hash) { if (reason == VerifyResult.Succeed) { @@ -65,9 +65,9 @@ private static JObject GetRelayResult(VerifyResult reason, UInt256 hash) } [RpcMethod] - protected virtual JObject GetVersion(JArray _params) + protected virtual JToken GetVersion(JArray _params) { - JObject json = new(); + var json = new JObject(); json["tcpport"] = localNode.ListenerTcpPort; json["wsport"] = localNode.ListenerWsPort; json["nonce"] = LocalNode.Nonce; @@ -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..41d643b16 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; @@ -65,9 +65,9 @@ private void OnTimer(object state) session.Dispose(); } - private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[] witnesses = null, bool useDiagnostic = false) + private JToken GetInvokeResult(byte[] script, Signer[] signers = null, Witness[] witnesses = null, bool useDiagnostic = false) { - JObject json = new(); + var json = new JObject(); Session session = new(system, script, signers, witnesses, settings.MaxGasInvoke, useDiagnostic ? new Diagnostic() : null); try { @@ -124,9 +124,9 @@ private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[ return json; } - private static JObject ToJson(TreeNode node) + private static JToken ToJson(TreeNode node) { - JObject json = new(); + var json = new JObject(); json["hash"] = node.Item.ToString(); if (node.Children.Any()) { @@ -135,7 +135,7 @@ private static JObject ToJson(TreeNode node) return json; } - private static JObject ToJson(IEnumerable changes) + private static JToken ToJson(IEnumerable changes) { JArray array = new(); foreach (var entry in changes) @@ -150,9 +150,9 @@ private static JObject ToJson(IEnumerable changes) return array; } - private static JObject ToJson(StackItem item, Session session) + private static JToken ToJson(StackItem item, Session session) { - JObject json = item.ToJson(); + JToken json = item.ToJson(); if (item is InteropInterface interopInterface && interopInterface.GetInterface() is IIterator iterator) { Guid id = Guid.NewGuid(); @@ -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,10 +256,10 @@ 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(); + var json = new JObject(); UInt160 script_hash; try { diff --git a/src/RpcServer/RpcServer.Utilities.cs b/src/RpcServer/RpcServer.Utilities.cs index 134c4a5c0..e995d8685 100644 --- a/src/RpcServer/RpcServer.Utilities.cs +++ b/src/RpcServer/RpcServer.Utilities.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 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,15 +28,15 @@ 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(); + var json = new JObject(); UInt160 scriptHash; try { diff --git a/src/RpcServer/RpcServer.Wallet.cs b/src/RpcServer/RpcServer.Wallet.cs index 3ed17f03a..438997d93 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,17 +82,17 @@ 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()); - JObject json = new(); + var json = new JObject(); json["balance"] = wallet.GetAvailable(system.StoreView, asset_id).Value.ToString(); return json; } [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(); @@ -159,7 +159,7 @@ protected virtual JObject OpenWallet(JArray _params) return true; } - private void ProcessInvokeWithWallet(JObject result, Signer[] signers = null) + private void ProcessInvokeWithWallet(JToken result, Signer[] signers = null) { if (wallet == null || signers == null || signers.Length == 0) return; @@ -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,16 +320,16 @@ 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); } - private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signer[] signers = null, Witness[] witnesses = null) + private JToken GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signer[] signers = null, Witness[] witnesses = null) { using var snapshot = system.GetSnapshot(); var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash); @@ -364,7 +364,7 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar tx.Witnesses ??= new Witness[] { new() { InvocationScript = invocationScript } }; engine.LoadScript(new Script(invocationScript), configureState: p => p.CallFlags = CallFlags.None); } - JObject json = new(); + var json = new JObject(); json["script"] = Convert.ToBase64String(invocationScript); json["state"] = engine.Execute(); json["gasconsumed"] = engine.GasConsumed.ToString(); @@ -380,7 +380,7 @@ private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] ar return json; } - private JObject SignAndRelay(DataCache snapshot, Transaction tx) + private JToken SignAndRelay(DataCache snapshot, Transaction tx) { ContractParametersContext context = new(snapshot, tx, settings.Network); wallet.Sign(context); diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index 724c313b2..d7cec7368 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,9 +73,9 @@ 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 JToken CreateErrorResponse(JToken id, int code, string message, JToken data = null) { - JObject response = CreateResponse(id); + JToken response = CreateResponse(id); response["error"] = new JObject(); response["error"]["code"] = code; response["error"]["message"] = message; @@ -84,7 +84,7 @@ private static JObject CreateErrorResponse(JObject id, int code, string message, return response; } - private static JObject CreateResponse(JObject id) + private static JToken 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,28 +208,28 @@ 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"; await context.Response.WriteAsync(response.ToString(), Encoding.UTF8); } - private async Task ProcessRequestAsync(HttpContext context, JObject request) + private async Task ProcessRequestAsync(HttpContext context, JObject request) { if (!request.ContainsProperty("id")) return null; if (!request.ContainsProperty("method") || !request.ContainsProperty("params") || !(request["params"] is JArray)) { return CreateErrorResponse(request["id"], -32600, "Invalid Request"); } - JObject response = CreateResponse(request["id"]); + JToken response = CreateResponse(request["id"]); try { string method = request["method"].AsString(); @@ -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..6f109142a 100644 --- a/src/RpcServer/Utility.cs +++ b/src/RpcServer/Utility.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 Neo.Network.P2P.Payloads; using Neo.SmartContract.Native; using System.Linq; @@ -17,22 +17,22 @@ namespace Neo.Plugins { static class Utility { - public static JObject BlockToJson(Block block, ProtocolSettings settings) + public static JToken BlockToJson(Block block, ProtocolSettings settings) { - JObject json = block.ToJson(settings); + JToken json = block.ToJson(settings); json["tx"] = block.Transactions.Select(p => TransactionToJson(p, settings)).ToArray(); return json; } - public static JObject TransactionToJson(Transaction tx, ProtocolSettings settings) + public static JToken TransactionToJson(Transaction tx, ProtocolSettings settings) { - JObject json = tx.ToJson(settings); + JToken json = tx.ToJson(settings); json["sysfee"] = tx.SystemFee.ToString(); json["netfee"] = tx.NetworkFee.ToString(); return json; } - public static JObject NativeContractToJson(this NativeContract contract, ProtocolSettings settings) + public static JToken NativeContractToJson(this NativeContract contract, ProtocolSettings settings) { return new JObject { @@ -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..81ccbfdd9 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; @@ -109,7 +109,7 @@ public UInt160[] GetScriptHashesForVerifying(DataCache snapshot) return new UInt160[] { Contract.GetBFTAddress(validators) }; } - public JObject ToJson() + public JToken ToJson() { var json = new JObject(); json["version"] = Version; diff --git a/src/StateService/StatePlugin.cs b/src/StateService/StatePlugin.cs index 11a9e9715..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; @@ -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..44908eccc 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; @@ -96,7 +96,7 @@ private void OnPersistStorage(uint network, DataCache snapshot) { if (Settings.Default.Exclude.Contains(trackable.Key.Id)) continue; - JObject state = new JObject(); + JToken state = new JObject(); switch (trackable.State) { case TrackState.Added: @@ -118,7 +118,7 @@ private void OnPersistStorage(uint network, DataCache snapshot) array.Add(state); } - JObject bs_item = new JObject(); + JToken bs_item = new JObject(); bs_item["block"] = blockIndex; bs_item["size"] = array.Count; bs_item["storage"] = array; diff --git a/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs b/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs index bff6acbee..16ada0047 100644 --- a/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs +++ b/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs @@ -12,7 +12,7 @@ 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; @@ -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()); @@ -203,7 +203,7 @@ public JObject GetNep11Transfers(JArray _params) if (endTime < startTime) throw new RpcException(-32602, "Invalid params"); - JObject json = new(); + var json = new JObject(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); JArray transfersSent = new(); json["sent"] = transfersSent; @@ -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(); @@ -312,7 +312,7 @@ private void AddNep11Transfers(byte dbPrefix, UInt160 userScriptHash, ulong star var transferPairs = QueryTransfers(dbPrefix, userScriptHash, startTime, endTime).Take((int)_maxResults).ToList(); foreach (var (key, value) in transferPairs.OrderByDescending(l => l.key.TimestampMS)) { - JObject transfer = ToJson(key, value); + JToken transfer = ToJson(key, value); transfer["tokenid"] = key.Token.GetSpan().ToHexString(); parentJArray.Add(transfer); } diff --git a/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs b/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs index a4a780cf9..050f7e6eb 100644 --- a/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs +++ b/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs @@ -12,7 +12,7 @@ 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; @@ -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()); @@ -152,7 +152,7 @@ public JObject GetNep17Transfers(JArray _params) if (endTime < startTime) throw new RpcException(-32602, "Invalid params"); - JObject json = new(); + var json = new JObject(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); JArray transfersSent = new(); json["sent"] = transfersSent; @@ -164,11 +164,11 @@ public JObject GetNep17Transfers(JArray _params) } [RpcMethod] - public JObject GetNep17Balances(JArray _params) + public JToken GetNep17Balances(JArray _params) { UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); - JObject json = new(); + var json = new JObject(); JArray balances = new(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); json["balance"] = balances; diff --git a/src/TokensTracker/Trackers/TrackerBase.cs b/src/TokensTracker/Trackers/TrackerBase.cs index 05dc4f823..cceea3c92 100644 --- a/src/TokensTracker/Trackers/TrackerBase.cs +++ b/src/TokensTracker/Trackers/TrackerBase.cs @@ -15,7 +15,7 @@ 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; @@ -134,9 +134,9 @@ protected TransferRecord GetTransferRecord(UInt160 asset, Array stateItems) }; } - protected JObject ToJson(TokenTransferKey key, TokenTransfer value) + protected JToken ToJson(TokenTransferKey key, TokenTransfer value) { - JObject transfer = new(); + var transfer = new JObject(); transfer["timestamp"] = key.TimestampMS; transfer["assethash"] = key.AssetScriptHash.ToString(); transfer["transferaddress"] = value.UserScriptHash == UInt160.Zero ? null : value.UserScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); diff --git a/tests/Neo.Network.RPC.Tests/TestUtils.cs b/tests/Neo.Network.RPC.Tests/TestUtils.cs index 5f83992db..b4a2bc689 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(p)).ToList(); public static Block GetBlock(int txCount) { @@ -60,7 +60,7 @@ internal class RpcTestCase public RpcRequest Request { get; set; } public RpcResponse Response { get; set; } - public JObject ToJson() + public JToken ToJson() { return new JObject { @@ -70,7 +70,7 @@ public JObject ToJson() }; } - public static RpcTestCase FromJson(JObject json) + public static RpcTestCase FromJson(JToken json) { return new RpcTestCase { 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..27487feb3 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] diff --git a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs index 27c663511..7c43cc3fc 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,7 +27,7 @@ public void TestSetup() [TestMethod()] public void TestRpcAccount() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ImportPrivKeyAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ImportPrivKeyAsync).ToLower()).Response.Result; var item = RpcAccount.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -35,7 +35,7 @@ public void TestRpcAccount() [TestMethod()] public void TestRpcApplicationLog() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetApplicationLogAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetApplicationLogAsync).ToLower()).Response.Result; var item = RpcApplicationLog.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -43,7 +43,7 @@ public void TestRpcApplicationLog() [TestMethod()] public void TestRpcBlock() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockAsync).ToLower()).Response.Result; var item = RpcBlock.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -51,7 +51,7 @@ public void TestRpcBlock() [TestMethod()] public void TestRpcBlockHeader() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockHeaderAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockHeaderAsync).ToLower()).Response.Result; var item = RpcBlockHeader.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -59,7 +59,7 @@ public void TestRpcBlockHeader() [TestMethod()] public void TestGetContractState() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; var item = RpcContractState.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); @@ -70,7 +70,7 @@ public void TestGetContractState() [TestMethod()] public void TestRpcInvokeResult() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.InvokeFunctionAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.InvokeFunctionAsync).ToLower()).Response.Result; var item = RpcInvokeResult.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -78,13 +78,13 @@ public void TestRpcInvokeResult() [TestMethod()] public void TestRpcMethodToken() { - RpcMethodToken.FromJson(JObject.Parse("{\"hash\": \"0x0e1b9bfaa44e60311f6f3c96cfcd6d12c2fc3add\", \"method\":\"test\",\"paramcount\":\"1\",\"hasreturnvalue\":\"true\",\"callflags\":\"All\"}")); + RpcMethodToken.FromJson(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; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17BalancesAsync).ToLower()).Response.Result; var item = RpcNep17Balances.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -92,7 +92,7 @@ public void TestRpcNep17Balances() [TestMethod()] public void TestRpcNep17Transfers() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17TransfersAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17TransfersAsync).ToLower()).Response.Result; var item = RpcNep17Transfers.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -100,7 +100,7 @@ public void TestRpcNep17Transfers() [TestMethod()] public void TestRpcPeers() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetPeersAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetPeersAsync).ToLower()).Response.Result; var item = RpcPeers.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -108,7 +108,7 @@ public void TestRpcPeers() [TestMethod()] public void TestRpcPlugin() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ListPluginsAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ListPluginsAsync).ToLower()).Response.Result; var item = ((JArray)json).Select(p => RpcPlugin.FromJson(p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } @@ -116,7 +116,7 @@ public void TestRpcPlugin() [TestMethod()] public void TestRpcRawMemPool() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawMempoolBothAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawMempoolBothAsync).ToLower()).Response.Result; var item = RpcRawMemPool.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -124,7 +124,7 @@ public void TestRpcRawMemPool() [TestMethod()] public void TestRpcTransaction() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawTransactionAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawTransactionAsync).ToLower()).Response.Result; var item = RpcTransaction.FromJson(json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -132,7 +132,7 @@ public void TestRpcTransaction() [TestMethod()] public void TestRpcTransferOut() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.SendManyAsync).ToLower()).Request.Params[1]; + JToken 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)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson(rpc.protocolSettings)).ToArray()).ToString()); } @@ -140,7 +140,7 @@ public void TestRpcTransferOut() [TestMethod()] public void TestRpcValidateAddressResult() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ValidateAddressAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ValidateAddressAsync).ToLower()).Response.Result; var item = RpcValidateAddressResult.FromJson(json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -148,7 +148,7 @@ public void TestRpcValidateAddressResult() [TestMethod()] public void TestRpcValidator() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNextBlockValidatorsAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNextBlockValidatorsAsync).ToLower()).Response.Result; var item = ((JArray)json).Select(p => RpcValidator.FromJson(p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } @@ -156,7 +156,7 @@ public void TestRpcValidator() [TestMethod()] public void TestRpcVersion() { - JObject json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetVersionAsync).ToLower()).Response.Result; + JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetVersionAsync).ToLower()).Response.Result; var item = RpcVersion.FromJson(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); From da33c006a893b394d6b0362dc88231458b7e09a5 Mon Sep 17 00:00:00 2001 From: Shine Li Date: Wed, 27 Jul 2022 14:14:21 +0800 Subject: [PATCH 03/48] Update src/RpcClient/Utility.cs Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> --- src/RpcClient/Utility.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index e3eb9232d..56bd3f9b0 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -18,7 +18,6 @@ using System; using System.Linq; using System.Numerics; -using Neo.Json; using Array = Neo.VM.Types.Array; using Buffer = Neo.VM.Types.Buffer; From 8503f81642d2dfa8d2139d466e7ed1a6ea9ea916 Mon Sep 17 00:00:00 2001 From: Shargon Date: Thu, 28 Jul 2022 18:31:36 +0100 Subject: [PATCH 04/48] Update src/OracleService/OracleService.csproj Co-authored-by: Owen Zhang <38493437+superboyiii@users.noreply.github.com> --- src/OracleService/OracleService.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OracleService/OracleService.csproj b/src/OracleService/OracleService.csproj index 0ef207b61..e4b54ff09 100644 --- a/src/OracleService/OracleService.csproj +++ b/src/OracleService/OracleService.csproj @@ -7,7 +7,7 @@ - + From 0871eb2cf3a988336a01aca5efe88c720003e8ff Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Fri, 5 Aug 2022 07:37:58 +0800 Subject: [PATCH 05/48] 3.4.0 --- src/Directory.Build.props | 4 ++-- src/OracleService/OracleService.cs | 4 ++-- src/OracleService/OracleService.csproj | 3 +-- src/RocksDBStore/RocksDBStore.csproj | 2 +- tests/Neo.Network.RPC.Tests/Neo.Network.RPC.Tests.csproj | 2 +- .../Neo.Plugins.OracleService.Tests.csproj | 4 ++-- 6 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 15265cbe2..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 e4b54ff09..fae818cc8 100644 --- a/src/OracleService/OracleService.csproj +++ b/src/OracleService/OracleService.csproj @@ -1,4 +1,4 @@ - + Neo.Plugins.OracleService @@ -7,7 +7,6 @@ - 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/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.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 @@ - - + + From 24075f7be2925408f329d72ad233489ad2143373 Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Tue, 9 Aug 2022 09:59:08 +0800 Subject: [PATCH 06/48] update neofs api --- src/OracleService/OracleService.csproj | 2 +- src/OracleService/Protocols/OracleNeoFSProtocol.cs | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) 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) From 4cc2fc003b9a1ffb37ab64f1ba8ed6e993af74ea Mon Sep 17 00:00:00 2001 From: ZhangTao1596 Date: Tue, 9 Aug 2022 10:01:32 +0800 Subject: [PATCH 07/48] format --- src/RpcClient/RpcClient.cs | 2 +- src/RpcClient/Utility.cs | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 982632e3f..6bdf240c4 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -145,7 +145,7 @@ public virtual async Task RpcSendAsync(string method, params JToken[] pa var response = await SendAsync(request).ConfigureAwait(false); return response.Result; } - + public static string GetRpcName([CallerMemberName] string methodName = null) { return new Regex("(.*?)(Hex|Both)?(Async)?").Replace(methodName, "$1").ToLowerInvariant(); diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index 56bd3f9b0..c4d6d2e2f 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -43,7 +43,7 @@ public static UInt160 ToScriptHash(this JToken value, ProtocolSettings protocolS return addressOrScriptHash.Length < 40 ? addressOrScriptHash.ToScriptHash(protocolSettings.AddressVersion) : UInt160.Parse(addressOrScriptHash); } - + public static string AsScriptHash(this string addressOrScriptHash) { foreach (var native in NativeContract.Contracts) @@ -218,7 +218,7 @@ public static Witness WitnessFromJson(JToken json) VerificationScript = Convert.FromBase64String(json["verification"].AsString()) }; } - + public static StackItem StackItemFromJson(JToken json) { StackItemType type = json["type"].AsEnum(); From 915e73d96de62ac9fc6a27ba863158049a957033 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:03:17 +0800 Subject: [PATCH 08/48] Update LogReader.cs --- src/ApplicationLogs/LogReader.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/ApplicationLogs/LogReader.cs b/src/ApplicationLogs/LogReader.cs index 1c6912045..4a79b1782 100644 --- a/src/ApplicationLogs/LogReader.cs +++ b/src/ApplicationLogs/LogReader.cs @@ -64,7 +64,7 @@ public JToken GetApplicationLog(JArray _params) if (value is null) throw new RpcException(-100, "Unknown transaction/blockhash"); - var raw = JToken.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)) { @@ -86,7 +86,7 @@ public static JToken TxLogToJson(Blockchain.ApplicationExecuted appExec) var txJson = new JObject(); txJson["txid"] = appExec.Transaction.Hash.ToString(); - JToken trigger = new JObject(); + JObject trigger = new JObject(); trigger["trigger"] = appExec.Trigger; trigger["vmstate"] = appExec.VMState; trigger["exception"] = GetExceptionMessage(appExec.Exception); @@ -101,7 +101,7 @@ public static JToken TxLogToJson(Blockchain.ApplicationExecuted appExec) } trigger["notifications"] = appExec.Notifications.Select(q => { - JToken notification = new JObject(); + JObject notification = new JObject(); notification["contract"] = q.ScriptHash.ToString(); notification["eventname"] = q.EventName; try @@ -115,11 +115,11 @@ public static JToken TxLogToJson(Blockchain.ApplicationExecuted appExec) return notification; }).ToArray(); - txJson["executions"] = new List() { trigger }.ToArray(); + txJson["executions"] = new[] { trigger }; return txJson; } - public static JToken BlockLogToJson(Block block, IReadOnlyList applicationExecutedList) + public static JObject BlockLogToJson(Block block, IReadOnlyList applicationExecutedList) { var blocks = applicationExecutedList.Where(p => p.Transaction is null).ToArray(); if (blocks.Length > 0) @@ -127,10 +127,10 @@ public static JToken BlockLogToJson(Block block, IReadOnlyList(); + var triggerList = new List(); foreach (var appExec in blocks) { - JToken trigger = new JObject(); + JObject trigger = new JObject(); trigger["trigger"] = appExec.Trigger; trigger["vmstate"] = appExec.VMState; trigger["gasconsumed"] = appExec.GasConsumed.ToString(); @@ -144,7 +144,7 @@ public static JToken BlockLogToJson(Block block, IReadOnlyList { - JToken notification = new JObject(); + JObject notification = new JObject(); notification["contract"] = q.ScriptHash.ToString(); notification["eventname"] = q.EventName; try From 05e65a0b35b7ab0cb7d39277e82099a6f38b1bcc Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:04:49 +0800 Subject: [PATCH 09/48] Update LogReader.cs --- src/ApplicationLogs/LogReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ApplicationLogs/LogReader.cs b/src/ApplicationLogs/LogReader.cs index 4a79b1782..a2b5c4668 100644 --- a/src/ApplicationLogs/LogReader.cs +++ b/src/ApplicationLogs/LogReader.cs @@ -80,7 +80,7 @@ public JToken GetApplicationLog(JArray _params) return raw; } - public static JToken TxLogToJson(Blockchain.ApplicationExecuted appExec) + public static JObject TxLogToJson(Blockchain.ApplicationExecuted appExec) { global::System.Diagnostics.Debug.Assert(appExec.Transaction != null); From 18066c7ad7993fe7dfa9aa5348653c8033aba0e1 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:12:17 +0800 Subject: [PATCH 10/48] Update RpcAccount.cs and RpcClient.cs --- src/RpcClient/Models/RpcAccount.cs | 4 ++-- src/RpcClient/RpcClient.cs | 7 +++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/RpcClient/Models/RpcAccount.cs b/src/RpcClient/Models/RpcAccount.cs index 75ac7a209..d38e446ea 100644 --- a/src/RpcClient/Models/RpcAccount.cs +++ b/src/RpcClient/Models/RpcAccount.cs @@ -22,7 +22,7 @@ public class RpcAccount public bool WatchOnly { get; set; } - public JToken ToJson() + public JObject ToJson() { return new JObject { @@ -33,7 +33,7 @@ public JToken ToJson() }; } - public static RpcAccount FromJson(JToken json) + public static RpcAccount FromJson(JObject json) { return new RpcAccount { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 6bdf240c4..4c0ee14c3 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 @@ -14,7 +14,6 @@ using Neo.Network.RPC.Models; using Neo.SmartContract; using Neo.SmartContract.Manifest; -using Neo.VM; using System; using System.Collections.Generic; using System.IO; @@ -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(); } /// From a4e22382969fbec29b5f786928c72f0e17e2b472 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:17:15 +0800 Subject: [PATCH 11/48] Update RpcApplicationLog.cs and RpcClient.cs --- src/RpcClient/Models/RpcApplicationLog.cs | 28 +++++++++++------------ src/RpcClient/RpcClient.cs | 4 ++-- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index f684c8a8b..ef82c8f83 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 @@ -25,9 +25,9 @@ public class RpcApplicationLog public List Executions { get; set; } - public JToken ToJson() + public JObject ToJson() { - JToken json = new JObject(); + JObject json = new JObject(); if (TxId != null) json["txid"] = TxId.ToString(); if (BlockHash != null) @@ -36,13 +36,13 @@ public JToken ToJson() return json; } - public static RpcApplicationLog FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcApplicationLog FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcApplicationLog { 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(), }; } } @@ -61,9 +61,9 @@ public class Execution public List Notifications { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["trigger"] = Trigger; json["vmstate"] = VMState; json["gasconsumed"] = GasConsumed.ToString(); @@ -73,16 +73,16 @@ public JToken ToJson() return json; } - public static Execution FromJson(JToken json, ProtocolSettings protocolSettings) + public static Execution FromJson(JObject json, ProtocolSettings protocolSettings) { return new Execution { - Trigger = json["trigger"].AsEnum(), - VMState = json["vmstate"].AsEnum(), + 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() + Notifications = ((JArray)json["notifications"]).Select(p => RpcNotifyEventArgs.FromJson((JObject)p, protocolSettings)).ToList() }; } } @@ -95,16 +95,16 @@ public class RpcNotifyEventArgs public StackItem State { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["contract"] = Contract.ToString(); json["eventname"] = EventName; json["state"] = State.ToJson(); return json; } - public static RpcNotifyEventArgs FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcNotifyEventArgs FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcNotifyEventArgs { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 4c0ee14c3..e590c487d 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -646,7 +646,7 @@ public async Task SendToAddressAsync(string assetId, string address, str 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); } /// @@ -656,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); } /// From 93d1c1445b61448cb43d871fafadf73596948a1a Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:20:29 +0800 Subject: [PATCH 12/48] Update RpcBlock.cs, RpcClient.cs and Utility.cs --- src/RpcClient/Models/RpcBlock.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- src/RpcClient/Utility.cs | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/RpcClient/Models/RpcBlock.cs b/src/RpcClient/Models/RpcBlock.cs index 15960fa75..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 @@ -21,15 +21,15 @@ public class RpcBlock public UInt256 NextBlockHash { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - JToken json = Utility.BlockToJson(Block, protocolSettings); + JObject json = Utility.BlockToJson(Block, protocolSettings); json["confirmations"] = Confirmations; json["nextblockhash"] = NextBlockHash?.ToString(); return json; } - public static RpcBlock FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcBlock FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcBlock { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index e590c487d..9c14b702e 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -182,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); } /// diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index c4d6d2e2f..9e0d691eb 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -136,9 +136,9 @@ public static Block BlockFromJson(JToken json, ProtocolSettings protocolSettings }; } - public static JToken BlockToJson(Block block, ProtocolSettings protocolSettings) + public static JObject BlockToJson(Block block, ProtocolSettings protocolSettings) { - JToken json = block.ToJson(protocolSettings); + JObject json = block.ToJson(protocolSettings); json["tx"] = block.Transactions.Select(p => TransactionToJson(p, protocolSettings)).ToArray(); return json; } From 5a336eaff5f2328f4aea2f3b33d4977d678183e3 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:22:41 +0800 Subject: [PATCH 13/48] Update RpcBlockHeader.cs and RpcClient.cs --- src/RpcClient/Models/RpcBlockHeader.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/Models/RpcBlockHeader.cs b/src/RpcClient/Models/RpcBlockHeader.cs index 7be210528..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 @@ -21,15 +21,15 @@ public class RpcBlockHeader public UInt256 NextBlockHash { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - JToken json = Header.ToJson(protocolSettings); + JObject json = Header.ToJson(protocolSettings); json["confirmations"] = Confirmations; json["nextblockhash"] = NextBlockHash?.ToString(); return json; } - public static RpcBlockHeader FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcBlockHeader FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcBlockHeader { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 9c14b702e..4fcb2b975 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -232,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); } /// From bfe0228305b82425d1bd7df07d29e40dbaba41c1 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:24:51 +0800 Subject: [PATCH 14/48] Update RpcContractState.cs --- src/RpcClient/Models/RpcContractState.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RpcClient/Models/RpcContractState.cs b/src/RpcClient/Models/RpcContractState.cs index dfae260d4..584b1962b 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 @@ -18,12 +18,12 @@ public class RpcContractState { public ContractState ContractState { get; set; } - public JToken ToJson() + public JObject ToJson() { return ContractState.ToJson(); } - public static RpcContractState FromJson(JToken json) + public static RpcContractState FromJson(JObject json) { return new RpcContractState { From cf469ef83956d293087a3f360f79ac7207d0b696 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:28:16 +0800 Subject: [PATCH 15/48] Update RpcFoundStates.cs and StateAPI.cs --- src/RpcClient/Models/RpcFoundStates.cs | 12 ++++++------ src/RpcClient/StateAPI.cs | 12 ++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/src/RpcClient/Models/RpcFoundStates.cs b/src/RpcClient/Models/RpcFoundStates.cs index 4a57b13ff..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.Json; namespace Neo.Network.RPC.Models { @@ -21,7 +21,7 @@ public class RpcFoundStates public byte[] FirstProof; public byte[] LastProof; - public static RpcFoundStates FromJson(JToken json) + public static RpcFoundStates FromJson(JObject json) { return new RpcFoundStates { @@ -32,12 +32,12 @@ public static RpcFoundStates FromJson(JToken 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(JToken json) + static byte[] ProofFromJson(JString json) => json == null ? null : Convert.FromBase64String(json.AsString()); } } diff --git a/src/RpcClient/StateAPI.cs b/src/RpcClient/StateAPI.cs index 13e758f76..fb310bff6 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 System; -using System.Collections.Generic; -using System.Linq; -using System.Runtime.CompilerServices; -using System.Threading; -using System.Threading.Tasks; using Neo.Json; using Neo.Network.RPC.Models; +using System; +using System.Threading.Tasks; namespace Neo.Network.RPC { @@ -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) From 20d727be6a98fd1fcefcad7152a395f228725e53 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:30:48 +0800 Subject: [PATCH 16/48] Update RpcInvokeResult.cs and RpcClient.cs --- src/RpcClient/Models/RpcInvokeResult.cs | 16 ++++++++-------- src/RpcClient/RpcClient.cs | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/RpcClient/Models/RpcInvokeResult.cs b/src/RpcClient/Models/RpcInvokeResult.cs index d56954f44..c28f5528c 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 @@ -32,9 +32,9 @@ public class RpcInvokeResult public string Session { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["script"] = Script; json["state"] = State; json["gasconsumed"] = GasConsumed.ToString(); @@ -53,12 +53,12 @@ public JToken ToJson() return json; } - public static RpcInvokeResult FromJson(JToken json) + public static RpcInvokeResult FromJson(JObject json) { RpcInvokeResult invokeScriptResult = new() { Script = json["script"].AsString(), - State = json["state"].AsEnum(), + State = json["state"].GetEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), }; invokeScriptResult.Exception = json["exception"]?.AsString(); @@ -79,15 +79,15 @@ public class RpcStack public string Value { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["type"] = Type; json["value"] = Value; return json; } - public static RpcStack FromJson(JToken json) + public static RpcStack FromJson(JObject json) { return new RpcStack { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 4fcb2b975..e2a41865b 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -426,7 +426,7 @@ public async Task InvokeFunctionAsync(string scriptHash, string 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); } /// @@ -441,7 +441,7 @@ public async Task InvokeScriptAsync(ReadOnlyMemory script 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) From 0afbbdf67b739ce892f04ad26d4a63b047a1049d Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:39:07 +0800 Subject: [PATCH 17/48] Update RpcMethodToken.cs and RpcNefFile.cs --- src/RpcClient/Models/RpcMethodToken.cs | 4 ++-- src/RpcClient/Models/RpcNefFile.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcMethodToken.cs b/src/RpcClient/Models/RpcMethodToken.cs index 464bce712..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 @@ -16,7 +16,7 @@ namespace Neo.Network.RPC.Models { class RpcMethodToken { - public static MethodToken FromJson(JToken json) + public static MethodToken FromJson(JObject json) { return new MethodToken { diff --git a/src/RpcClient/Models/RpcNefFile.cs b/src/RpcClient/Models/RpcNefFile.cs index 72fc33edf..49af6769b 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 @@ -23,7 +23,7 @@ public static NefFile FromJson(JToken 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() }; From 27f6bc40abc0997cf9f812f7007693e75816e43f Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:41:19 +0800 Subject: [PATCH 18/48] Update RpcNativeContract.cs and RpcClient.cs --- src/RpcClient/Models/RpcNativeContract.cs | 6 +++--- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcNativeContract.cs b/src/RpcClient/Models/RpcNativeContract.cs index 0d498d93b..0f869f658 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 @@ -23,7 +23,7 @@ public class RpcNativeContract public ContractManifest Manifest { get; set; } public uint[] UpdateHistory { get; set; } - public static RpcNativeContract FromJson(JToken json) + public static RpcNativeContract FromJson(JObject json) { return new RpcNativeContract { @@ -35,7 +35,7 @@ public static RpcNativeContract FromJson(JToken json) }; } - public JToken ToJson() + public JObject ToJson() { return new JObject { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index e2a41865b..410eba8b3 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -262,7 +262,7 @@ public static ContractState ContractStateFromJson(JToken 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(); } /// From a6301274849c7be2893e3c1ce1fe65c8a8c42a3d Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:43:57 +0800 Subject: [PATCH 19/48] Update RpcContractState.cs, RpcNativeContract.cs, RpcNefFile.cs and RpcClient.cs --- src/RpcClient/Models/RpcContractState.cs | 2 +- src/RpcClient/Models/RpcNativeContract.cs | 2 +- src/RpcClient/Models/RpcNefFile.cs | 2 +- src/RpcClient/RpcClient.cs | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcContractState.cs b/src/RpcClient/Models/RpcContractState.cs index 584b1962b..ce68831f3 100644 --- a/src/RpcClient/Models/RpcContractState.cs +++ b/src/RpcClient/Models/RpcContractState.cs @@ -32,7 +32,7 @@ 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"]), + Nef = RpcNefFile.FromJson((JObject)json["nef"]), Manifest = ContractManifest.FromJson((JObject)json["manifest"]) } }; diff --git a/src/RpcClient/Models/RpcNativeContract.cs b/src/RpcClient/Models/RpcNativeContract.cs index 0f869f658..3edc9a71a 100644 --- a/src/RpcClient/Models/RpcNativeContract.cs +++ b/src/RpcClient/Models/RpcNativeContract.cs @@ -29,7 +29,7 @@ public static RpcNativeContract FromJson(JObject json) { Id = (int)json["id"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Nef = RpcNefFile.FromJson(json["nef"]), + 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 49af6769b..7bf580aca 100644 --- a/src/RpcClient/Models/RpcNefFile.cs +++ b/src/RpcClient/Models/RpcNefFile.cs @@ -17,7 +17,7 @@ namespace Neo.Network.RPC.Models { class RpcNefFile { - public static NefFile FromJson(JToken json) + public static NefFile FromJson(JObject json) { return new NefFile { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 410eba8b3..58d96c3d2 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -251,7 +251,7 @@ public static ContractState ContractStateFromJson(JToken json) Id = (int)json["id"].AsNumber(), UpdateCounter = (ushort)json["updatecounter"].AsNumber(), Hash = UInt160.Parse(json["hash"].AsString()), - Nef = RpcNefFile.FromJson(json["nef"]), + Nef = RpcNefFile.FromJson((JObject)json["nef"]), Manifest = ContractManifest.FromJson((JObject)json["manifest"]) }; } From 14a42d97d1156477aef8da19aff5137267f7aa82 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:46:47 +0800 Subject: [PATCH 20/48] Update RpcNep17Balances.cs and RpcClient.cs --- src/RpcClient/Models/RpcNep17Balances.cs | 16 ++++++++-------- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/RpcClient/Models/RpcNep17Balances.cs b/src/RpcClient/Models/RpcNep17Balances.cs index 1e96effbf..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 @@ -22,19 +22,19 @@ public class RpcNep17Balances public List Balances { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - var json = new JObject(); + JObject json = new(); json["balance"] = Balances.Select(p => p.ToJson()).ToArray(); json["address"] = UserScriptHash.ToAddress(protocolSettings.AddressVersion); return json; } - public static RpcNep17Balances FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcNep17Balances FromJson(JObject json, ProtocolSettings protocolSettings) { 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; @@ -49,16 +49,16 @@ public class RpcNep17Balance public uint LastUpdatedBlock { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["assethash"] = AssetHash.ToString(); json["amount"] = Amount.ToString(); json["lastupdatedblock"] = LastUpdatedBlock; return json; } - public static RpcNep17Balance FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcNep17Balance FromJson(JObject json, ProtocolSettings protocolSettings) { RpcNep17Balance balance = new() { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 58d96c3d2..757abc801 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -683,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 From c87942d9b08c31d54ac47f86931a624f355fb3b8 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:49:15 +0800 Subject: [PATCH 21/48] Update RpcNep17Transfers.cs and RpcClient.cs --- src/RpcClient/Models/RpcNep17Transfers.cs | 18 +++++++++--------- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/RpcClient/Models/RpcNep17Transfers.cs b/src/RpcClient/Models/RpcNep17Transfers.cs index b1c74f618..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 @@ -24,21 +24,21 @@ public class RpcNep17Transfers public List Received { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - var json = new JObject(); + JObject json = new(); json["sent"] = Sent.Select(p => p.ToJson(protocolSettings)).ToArray(); json["received"] = Received.Select(p => p.ToJson(protocolSettings)).ToArray(); json["address"] = UserScriptHash.ToAddress(protocolSettings.AddressVersion); return json; } - public static RpcNep17Transfers FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcNep17Transfers FromJson(JObject json, ProtocolSettings protocolSettings) { 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; @@ -61,9 +61,9 @@ public class RpcNep17Transfer public UInt256 TxHash { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - var json = new JObject(); + JObject json = new(); json["timestamp"] = TimestampMS; json["assethash"] = AssetHash.ToString(); json["transferaddress"] = UserScriptHash?.ToAddress(protocolSettings.AddressVersion); @@ -74,7 +74,7 @@ public JToken ToJson(ProtocolSettings protocolSettings) return json; } - public static RpcNep17Transfer FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcNep17Transfer FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcNep17Transfer { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 757abc801..200d257d1 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -672,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); } /// From ded0ccae0dbd90177fa447904bc08679fe56eec2 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:51:33 +0800 Subject: [PATCH 22/48] Update RpcPeers.cs and RpcClient.cs --- src/RpcClient/Models/RpcPeers.cs | 20 ++++++++++---------- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/RpcClient/Models/RpcPeers.cs b/src/RpcClient/Models/RpcPeers.cs index 765f4ecd0..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 @@ -21,22 +21,22 @@ public class RpcPeers public RpcPeer[] Connected { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["unconnected"] = new JArray(Unconnected.Select(p => p.ToJson())); json["bad"] = new JArray(Bad.Select(p => p.ToJson())); json["connected"] = new JArray(Connected.Select(p => p.ToJson())); return json; } - public static RpcPeers FromJson(JToken json) + 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() }; } } @@ -47,15 +47,15 @@ public class RpcPeer public int Port { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["address"] = Address; json["port"] = Port; return json; } - public static RpcPeer FromJson(JToken json) + public static RpcPeer FromJson(JObject json) { return new RpcPeer { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 200d257d1..c472d4e0e 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -372,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); } /// From 338d66806ec2dad24def39806484895d5f19f792 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:53:41 +0800 Subject: [PATCH 23/48] Update RpcPlugin.cs and RpcClient.cs --- src/RpcClient/Models/RpcPlugin.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/Models/RpcPlugin.cs b/src/RpcClient/Models/RpcPlugin.cs index 8cbb958e3..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 @@ -21,16 +21,16 @@ public class RpcPlugin public string[] Interfaces { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["name"] = Name; json["version"] = Version; json["interfaces"] = new JArray(Interfaces.Select(p => (JToken)p)); return json; } - public static RpcPlugin FromJson(JToken json) + public static RpcPlugin FromJson(JObject json) { return new RpcPlugin { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index c472d4e0e..2ad6c6d97 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -506,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(); } /// From f1cdb9fa10256612fc0f9dd5356c1c1275b0e0d1 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:55:34 +0800 Subject: [PATCH 24/48] Update RpcRawMemPool.cs and RpcClient.cs --- src/RpcClient/Models/RpcRawMemPool.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/Models/RpcRawMemPool.cs b/src/RpcClient/Models/RpcRawMemPool.cs index ba54fa707..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 @@ -22,16 +22,16 @@ public class RpcRawMemPool public List UnVerified { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["height"] = Height; json["verified"] = new JArray(Verified.Select(p => (JToken)p.ToString())); json["unverified"] = new JArray(UnVerified.Select(p => (JToken)p.ToString())); return json; } - public static RpcRawMemPool FromJson(JToken json) + public static RpcRawMemPool FromJson(JObject json) { return new RpcRawMemPool { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 2ad6c6d97..caa24511c 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -281,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); } /// From 255de6e688ce1ab523c21b6299a4a17fb365b7ee Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 11:57:17 +0800 Subject: [PATCH 25/48] Update RpcRequest.cs --- src/RpcClient/Models/RpcRequest.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RpcClient/Models/RpcRequest.cs b/src/RpcClient/Models/RpcRequest.cs index c1edc65bb..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 @@ -23,7 +23,7 @@ public class RpcRequest public JToken[] Params { get; set; } - public static RpcRequest FromJson(JToken json) + public static RpcRequest FromJson(JObject json) { return new RpcRequest { @@ -34,7 +34,7 @@ public static RpcRequest FromJson(JToken json) }; } - public JToken ToJson() + public JObject ToJson() { var json = new JObject(); json["id"] = Id; From ac95c630ded0f9034ac830ec008491d9ce2566e8 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:00:09 +0800 Subject: [PATCH 26/48] Update RpcResponse.cs and RpcClient.cs --- src/RpcClient/Models/RpcResponse.cs | 16 ++++++++-------- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/RpcClient/Models/RpcResponse.cs b/src/RpcClient/Models/RpcResponse.cs index a72dd1535..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 @@ -24,7 +24,7 @@ public class RpcResponse public string RawResponse { get; set; } - public static RpcResponse FromJson(JToken json) + public static RpcResponse FromJson(JObject json) { RpcResponse response = new() { @@ -35,15 +35,15 @@ public static RpcResponse FromJson(JToken json) if (json["error"] != null) { - response.Error = RpcResponseError.FromJson(json["error"]); + response.Error = RpcResponseError.FromJson((JObject)json["error"]); } return response; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["id"] = Id; json["jsonrpc"] = JsonRpc; json["error"] = Error?.ToJson(); @@ -60,7 +60,7 @@ public class RpcResponseError public JToken Data { get; set; } - public static RpcResponseError FromJson(JToken json) + public static RpcResponseError FromJson(JObject json) { return new RpcResponseError { @@ -70,9 +70,9 @@ public static RpcResponseError FromJson(JToken json) }; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["code"] = Code; json["message"] = Message; json["data"] = Data; diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index caa24511c..a12cb8e81 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -90,7 +90,7 @@ static RpcRequest AsRpcRequest(string method, params JToken[] paraArgs) } static RpcResponse AsRpcResponse(string content) { - var response = RpcResponse.FromJson(JToken.Parse(content)); + var response = RpcResponse.FromJson((JObject)JToken.Parse(content)); response.RawResponse = content; if (response.Error != null) From f8794744a3bdfc6ad320258adb65e30e3f43b754 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:18:32 +0800 Subject: [PATCH 27/48] Update RpcStateRoot.cs and StateAPI.cs --- src/RpcClient/Models/RpcStateRoot.cs | 6 +++--- src/RpcClient/StateAPI.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcStateRoot.cs b/src/RpcClient/Models/RpcStateRoot.cs index d4d8b1836..fc9f880a8 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.Json; using Neo.Network.P2P.Payloads; +using System.Linq; namespace Neo.Network.RPC.Models { @@ -21,7 +21,7 @@ public class RpcStateRoot public UInt256 RootHash; public Witness Witness; - public static RpcStateRoot FromJson(JToken json) + public static RpcStateRoot FromJson(JObject json) { return new RpcStateRoot { diff --git a/src/RpcClient/StateAPI.cs b/src/RpcClient/StateAPI.cs index fb310bff6..ff61a7b52 100644 --- a/src/RpcClient/StateAPI.cs +++ b/src/RpcClient/StateAPI.cs @@ -27,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) From 4d2e49312b24ff0e21a379f91522d2198b35fee7 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:23:55 +0800 Subject: [PATCH 28/48] Update RpcTransaction.cs, RpcClient.cs and Utility.cs --- src/RpcClient/Models/RpcTransaction.cs | 10 +++++----- src/RpcClient/RpcClient.cs | 2 +- src/RpcClient/Utility.cs | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/RpcClient/Models/RpcTransaction.cs b/src/RpcClient/Models/RpcTransaction.cs index d1de3e33b..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 @@ -26,9 +26,9 @@ public class RpcTransaction public VMState? VMState { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { - JToken json = Utility.TransactionToJson(Transaction, protocolSettings); + JObject json = Utility.TransactionToJson(Transaction, protocolSettings); if (Confirmations != null) { json["blockhash"] = BlockHash.ToString(); @@ -42,7 +42,7 @@ public JToken ToJson(ProtocolSettings protocolSettings) return json; } - public static RpcTransaction FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcTransaction FromJson(JObject json, ProtocolSettings protocolSettings) { RpcTransaction transaction = new RpcTransaction { @@ -53,7 +53,7 @@ public static RpcTransaction FromJson(JToken json, ProtocolSettings protocolSett transaction.BlockHash = UInt256.Parse(json["blockhash"].AsString()); transaction.Confirmations = (uint)json["confirmations"].AsNumber(); transaction.BlockTime = (ulong)json["blocktime"].AsNumber(); - transaction.VMState = json["vmstate"]?.AsEnum(); + transaction.VMState = json["vmstate"]?.GetEnum(); } return transaction; } diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index a12cb8e81..7cfe9fb27 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -300,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); } /// diff --git a/src/RpcClient/Utility.cs b/src/RpcClient/Utility.cs index 9e0d691eb..524813290 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -175,9 +175,9 @@ public static Transaction TransactionFromJson(JToken json, ProtocolSettings prot }; } - public static JToken TransactionToJson(Transaction tx, ProtocolSettings protocolSettings) + public static JObject TransactionToJson(Transaction tx, ProtocolSettings protocolSettings) { - JToken json = tx.ToJson(protocolSettings); + JObject json = tx.ToJson(protocolSettings); json["sysfee"] = tx.SystemFee.ToString(); json["netfee"] = tx.NetworkFee.ToString(); return json; From ba41901a38da84014bbca8a10e8040ade00b18bf Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:25:38 +0800 Subject: [PATCH 29/48] Update RpcTransferOut.cs --- src/RpcClient/Models/RpcTransferOut.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/RpcClient/Models/RpcTransferOut.cs b/src/RpcClient/Models/RpcTransferOut.cs index 0a3c96b5b..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 @@ -21,7 +21,7 @@ public class RpcTransferOut public string Value { get; set; } - public JToken ToJson(ProtocolSettings protocolSettings) + public JObject ToJson(ProtocolSettings protocolSettings) { return new JObject { @@ -31,7 +31,7 @@ public JToken ToJson(ProtocolSettings protocolSettings) }; } - public static RpcTransferOut FromJson(JToken json, ProtocolSettings protocolSettings) + public static RpcTransferOut FromJson(JObject json, ProtocolSettings protocolSettings) { return new RpcTransferOut { From 40e375caba4016da5f8a666b65187352c2845f76 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:27:01 +0800 Subject: [PATCH 30/48] Update RpcUnclaimedGas.cs and RpcClient.cs --- src/RpcClient/Models/RpcUnclaimedGas.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/Models/RpcUnclaimedGas.cs b/src/RpcClient/Models/RpcUnclaimedGas.cs index 5667ab1dd..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 @@ -18,15 +18,15 @@ public class RpcUnclaimedGas public string Address { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["unclaimed"] = Unclaimed.ToString(); json["address"] = Address; return json; } - public static RpcUnclaimedGas FromJson(JToken json) + public static RpcUnclaimedGas FromJson(JObject json) { return new RpcUnclaimedGas { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 7cfe9fb27..c20a898d5 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -447,7 +447,7 @@ public async Task InvokeScriptAsync(ReadOnlyMemory script public async Task GetUnclaimedGasAsync(string address) { var result = await RpcSendAsync(GetRpcName(), address.AsScriptHash()).ConfigureAwait(false); - return RpcUnclaimedGas.FromJson(result); + return RpcUnclaimedGas.FromJson((JObject)result); } From 410e0ec6f6587f9c4d4fecf3cb2c0ef518f4cb4a Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:28:29 +0800 Subject: [PATCH 31/48] Update RpcValidateAddressResult.cs and RpcClient.cs --- src/RpcClient/Models/RpcValidateAddressResult.cs | 8 ++++---- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcClient/Models/RpcValidateAddressResult.cs b/src/RpcClient/Models/RpcValidateAddressResult.cs index 0da5f6c7e..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 @@ -18,15 +18,15 @@ public class RpcValidateAddressResult public bool IsValid { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["address"] = Address; json["isvalid"] = IsValid; return json; } - public static RpcValidateAddressResult FromJson(JToken json) + public static RpcValidateAddressResult FromJson(JObject json) { return new RpcValidateAddressResult { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index c20a898d5..c5d92b400 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -515,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 From 26c60d94bc940ba9450954bdc7f3c6853c18bb89 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:30:22 +0800 Subject: [PATCH 32/48] Update RpcValidator.cs and RpcClient.cs --- src/RpcClient/Models/RpcValidator.cs | 6 +++--- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/RpcClient/Models/RpcValidator.cs b/src/RpcClient/Models/RpcValidator.cs index a4dd76ec8..39e692337 100644 --- a/src/RpcClient/Models/RpcValidator.cs +++ b/src/RpcClient/Models/RpcValidator.cs @@ -19,15 +19,15 @@ public class RpcValidator public BigInteger Votes { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["publickey"] = PublicKey; json["votes"] = Votes.ToString(); return json; } - public static RpcValidator FromJson(JToken json) + public static RpcValidator FromJson(JObject json) { return new RpcValidator { diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index c5d92b400..6fca31cf2 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -341,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(); } /// From 2afb5b3759015b9a94b211ff02f40a45f38f5e6e Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:32:31 +0800 Subject: [PATCH 33/48] Update RpcVersion.cs and RpcClient.cs --- src/RpcClient/Models/RpcVersion.cs | 16 ++++++++-------- src/RpcClient/RpcClient.cs | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/RpcClient/Models/RpcVersion.cs b/src/RpcClient/Models/RpcVersion.cs index c27cb4dd7..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 @@ -26,9 +26,9 @@ public class RpcProtocol public int MemoryPoolMaxTransactions { get; set; } public ulong InitialGasDistribution { get; set; } - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["network"] = Network; json["validatorscount"] = ValidatorsCount; json["msperblock"] = MillisecondsPerBlock; @@ -41,7 +41,7 @@ public JToken ToJson() return json; } - public static RpcProtocol FromJson(JToken json) + public static RpcProtocol FromJson(JObject json) { return new() { @@ -68,9 +68,9 @@ public static RpcProtocol FromJson(JToken json) public RpcProtocol Protocol { get; set; } = new(); - public JToken ToJson() + public JObject ToJson() { - var json = new JObject(); + JObject json = new(); json["network"] = Protocol.Network; // Obsolete json["tcpport"] = TcpPort; json["wsport"] = WsPort; @@ -80,7 +80,7 @@ public JToken ToJson() return json; } - public static RpcVersion FromJson(JToken json) + public static RpcVersion FromJson(JObject json) { return new() { @@ -88,7 +88,7 @@ public static RpcVersion FromJson(JToken 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 6fca31cf2..637a8ad07 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -381,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); } /// From 2c17246f3929b4e516e07fb7a1c2b12ae99e875b Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 12:46:36 +0800 Subject: [PATCH 34/48] Update RpcClient.cs --- src/RpcClient/RpcClient.cs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/RpcClient/RpcClient.cs b/src/RpcClient/RpcClient.cs index 637a8ad07..b21a17a36 100644 --- a/src/RpcClient/RpcClient.cs +++ b/src/RpcClient/RpcClient.cs @@ -241,10 +241,10 @@ 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(JToken json) + public static ContractState ContractStateFromJson(JObject json) { return new ContractState { @@ -451,16 +451,16 @@ public async Task GetUnclaimedGasAsync(string address) } - public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id) + public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id) { const int count = 100; while (true) { var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); var array = (JArray)result; - foreach (var JToken in array) + foreach (JObject jObject in array) { - yield return JToken; + yield return jObject; } if (array.Count < count) break; } @@ -474,14 +474,14 @@ public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, st /// /// /// - public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id, int count) + public async IAsyncEnumerable TraverseIteratorAsync(string sessionId, string id, int count) { var result = await RpcSendAsync(GetRpcName(), sessionId, id, count).ConfigureAwait(false); if (result is JArray { Count: > 0 } array) { - foreach (var JToken in array) + foreach (JObject jObject in array) { - yield return JToken; + yield return jObject; } } } @@ -603,9 +603,9 @@ public async Task OpenWalletAsync(string path, string password) /// Transfer from the specified address to the destination address. /// /// 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) + 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); } @@ -613,7 +613,7 @@ public async Task SendFromAsync(string assetId, string fromAddress, stri /// Bulk transfer order, and you can specify a sender address. /// /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. - public async Task SendManyAsync(string fromAddress, IEnumerable outputs) + public async Task SendManyAsync(string fromAddress, IEnumerable outputs) { var parameters = new List(); if (!string.IsNullOrEmpty(fromAddress)) @@ -622,16 +622,16 @@ public async Task SendManyAsync(string fromAddress, IEnumerable p.ToJson(protocolSettings)).ToArray()); - return await RpcSendAsync(GetRpcName(), paraArgs: parameters.ToArray()).ConfigureAwait(false); + return (JObject)await RpcSendAsync(GetRpcName(), paraArgs: parameters.ToArray()).ConfigureAwait(false); } /// /// Transfer asset from the wallet to the destination address. /// /// This function returns Signed Transaction JSON if successful, ContractParametersContext JSON if signing failed. - public async Task SendToAddressAsync(string assetId, string address, string amount) + 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); } From 16d8c34db6a911e1e93d8ac5d991229789333994 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:11:23 +0800 Subject: [PATCH 35/48] Update RpcApplicationLog.cs, RpcInvokeResult.cs, RpcStateRoot.cs and Utility.cs --- src/RpcClient/Models/RpcApplicationLog.cs | 4 +-- src/RpcClient/Models/RpcInvokeResult.cs | 2 +- src/RpcClient/Models/RpcStateRoot.cs | 2 +- src/RpcClient/Utility.cs | 36 +++++++++++------------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/RpcClient/Models/RpcApplicationLog.cs b/src/RpcClient/Models/RpcApplicationLog.cs index ef82c8f83..29e22c8e6 100644 --- a/src/RpcClient/Models/RpcApplicationLog.cs +++ b/src/RpcClient/Models/RpcApplicationLog.cs @@ -81,7 +81,7 @@ public static Execution FromJson(JObject json, ProtocolSettings protocolSettings VMState = json["vmstate"].GetEnum(), GasConsumed = long.Parse(json["gasconsumed"].AsString()), ExceptionMessage = json["exception"]?.AsString(), - Stack = ((JArray)json["stack"]).Select(p => Utility.StackItemFromJson(p)).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/RpcInvokeResult.cs b/src/RpcClient/Models/RpcInvokeResult.cs index c28f5528c..faf436e8f 100644 --- a/src/RpcClient/Models/RpcInvokeResult.cs +++ b/src/RpcClient/Models/RpcInvokeResult.cs @@ -65,7 +65,7 @@ public static RpcInvokeResult FromJson(JObject json) 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/RpcStateRoot.cs b/src/RpcClient/Models/RpcStateRoot.cs index fc9f880a8..3a8bad275 100644 --- a/src/RpcClient/Models/RpcStateRoot.cs +++ b/src/RpcClient/Models/RpcStateRoot.cs @@ -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/Utility.cs b/src/RpcClient/Utility.cs index 524813290..b0d481eb4 100644 --- a/src/RpcClient/Utility.cs +++ b/src/RpcClient/Utility.cs @@ -127,12 +127,12 @@ public static BigInteger ToBigInteger(this decimal amount, uint decimals) return res; } - public static Block BlockFromJson(JToken json, ProtocolSettings protocolSettings) + public static Block BlockFromJson(JObject json, ProtocolSettings protocolSettings) { 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() }; } @@ -143,7 +143,7 @@ public static JObject BlockToJson(Block block, ProtocolSettings protocolSettings return json; } - public static Header HeaderFromJson(JToken json, ProtocolSettings protocolSettings) + public static Header HeaderFromJson(JObject json, ProtocolSettings protocolSettings) { return new Header { @@ -155,23 +155,23 @@ public static Header HeaderFromJson(JToken json, ProtocolSettings protocolSettin 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() }; } - public static Transaction TransactionFromJson(JToken json, ProtocolSettings protocolSettings) + public static Transaction TransactionFromJson(JObject json, ProtocolSettings protocolSettings) { return new Transaction { 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() }; } @@ -183,7 +183,7 @@ public static JObject TransactionToJson(Transaction tx, ProtocolSettings protoco return json; } - public static Signer SignerFromJson(JToken json, ProtocolSettings protocolSettings) + public static Signer SignerFromJson(JObject json, ProtocolSettings protocolSettings) { return new Signer { @@ -194,7 +194,7 @@ public static Signer SignerFromJson(JToken json, ProtocolSettings protocolSettin }; } - public static TransactionAttribute TransactionAttributeFromJson(JToken json) + public static TransactionAttribute TransactionAttributeFromJson(JObject json) { TransactionAttributeType usage = Enum.Parse(json["type"].AsString()); return usage switch @@ -210,7 +210,7 @@ public static TransactionAttribute TransactionAttributeFromJson(JToken json) }; } - public static Witness WitnessFromJson(JToken json) + public static Witness WitnessFromJson(JObject json) { return new Witness { @@ -219,9 +219,9 @@ public static Witness WitnessFromJson(JToken json) }; } - public static StackItem StackItemFromJson(JToken json) + public static StackItem StackItemFromJson(JObject json) { - StackItemType type = json["type"].AsEnum(); + StackItemType type = json["type"].GetEnum(); switch (type) { case StackItemType.Boolean: @@ -234,20 +234,20 @@ public static StackItem StackItemFromJson(JToken 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: @@ -262,7 +262,7 @@ public static string GetIteratorId(this StackItem item) { if (item is InteropInterface iop) { - var json = iop.GetInterface(); + var json = iop.GetInterface(); return json["id"]?.GetString(); } return null; From 42b40ec5cb1555b76e0eba7fa747a9b0aea790d8 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:18:03 +0800 Subject: [PATCH 36/48] Update RpcServer.Blockchain.cs and Utility.cs --- src/RpcServer/RpcServer.Blockchain.cs | 12 ++++++------ src/RpcServer/Utility.cs | 10 +++++----- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/RpcServer/RpcServer.Blockchain.cs b/src/RpcServer/RpcServer.Blockchain.cs index d9511bf18..700067572 100644 --- a/src/RpcServer/RpcServer.Blockchain.cs +++ b/src/RpcServer/RpcServer.Blockchain.cs @@ -50,7 +50,7 @@ protected virtual JToken GetBlock(JArray _params) throw new RpcException(-100, "Unknown block"); if (verbose) { - JToken json = Utility.BlockToJson(block, system.Settings); + JObject json = Utility.BlockToJson(block, system.Settings); json["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - block.Index + 1; UInt256 hash = NativeContract.Ledger.GetBlockHash(snapshot, block.Index + 1); if (hash != null) @@ -106,7 +106,7 @@ protected virtual JToken GetBlockHeader(JArray _params) if (verbose) { - JToken json = header.ToJson(system.Settings); + JObject json = header.ToJson(system.Settings); json["confirmations"] = NativeContract.Ledger.CurrentIndex(snapshot) - header.Index + 1; UInt256 hash = NativeContract.Ledger.GetBlockHash(snapshot, header.Index + 1); if (hash != null) @@ -143,7 +143,7 @@ protected virtual JToken GetRawMemPool(JArray _params) if (!shouldGetUnverified) return new JArray(system.MemPool.GetVerifiedTransactions().Select(p => (JToken)p.Hash.ToString())); - var json = new JObject(); + JObject json = new(); json["height"] = NativeContract.Ledger.CurrentIndex(system.StoreView); system.MemPool.GetVerifiedAndUnverifiedTransactions( out IEnumerable verifiedTransactions, @@ -165,7 +165,7 @@ protected virtual JToken GetRawTransaction(JArray _params) tx ??= state?.Transaction; if (tx is null) throw new RpcException(-100, "Unknown transaction"); if (!verbose) return Convert.ToBase64String(tx.ToArray()); - JToken json = Utility.TransactionToJson(tx, system.Settings); + JObject json = Utility.TransactionToJson(tx, system.Settings); if (state is not null) { TrimmedBlock block = NativeContract.Ledger.GetTrimmedBlock(snapshot, NativeContract.Ledger.GetBlockHash(snapshot, state.BlockIndex)); @@ -213,7 +213,7 @@ protected virtual JToken GetNextBlockValidators(JArray _params) var validators = NativeContract.NEO.GetNextBlockValidators(snapshot, system.Settings.ValidatorsCount); return validators.Select(p => { - var validator = new JObject(); + JObject validator = new(); validator["publickey"] = p.ToString(); validator["votes"] = (int)NativeContract.NEO.GetCandidateVote(snapshot, p); return validator; @@ -230,7 +230,7 @@ protected virtual JToken GetCandidates(JArray _params) script = sb.EmitDynamicCall(NativeContract.NEO.Hash, "getCandidates", null).ToArray(); } using ApplicationEngine engine = ApplicationEngine.Run(script, snapshot, settings: system.Settings, gas: settings.MaxGasInvoke); - var json = new JObject(); + JObject json = new(); try { var resultstack = engine.ResultStack.ToArray(); diff --git a/src/RpcServer/Utility.cs b/src/RpcServer/Utility.cs index 6f109142a..f90151de1 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 @@ -17,16 +17,16 @@ namespace Neo.Plugins { static class Utility { - public static JToken BlockToJson(Block block, ProtocolSettings settings) + public static JObject BlockToJson(Block block, ProtocolSettings settings) { - JToken json = block.ToJson(settings); + JObject json = block.ToJson(settings); json["tx"] = block.Transactions.Select(p => TransactionToJson(p, settings)).ToArray(); return json; } - public static JToken TransactionToJson(Transaction tx, ProtocolSettings settings) + public static JObject TransactionToJson(Transaction tx, ProtocolSettings settings) { - JToken json = tx.ToJson(settings); + JObject json = tx.ToJson(settings); json["sysfee"] = tx.SystemFee.ToString(); json["netfee"] = tx.NetworkFee.ToString(); return json; From 7a1fb6fb1f7d6c6667fe706883fa26b9e4e8f20c Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:20:49 +0800 Subject: [PATCH 37/48] Update RpcServer.Node.cs --- src/RpcServer/RpcServer.Node.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/RpcServer/RpcServer.Node.cs b/src/RpcServer/RpcServer.Node.cs index 713b39292..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 @@ -31,10 +31,10 @@ protected virtual JToken GetConnectionCount(JArray _params) [RpcMethod] protected virtual JToken GetPeers(JArray _params) { - var json = new JObject(); + JObject json = new(); json["unconnected"] = new JArray(localNode.GetUnconnectedPeers().Select(p => { - var peerJson = new JObject(); + JObject peerJson = new(); peerJson["address"] = p.Address.ToString(); peerJson["port"] = p.Port; return peerJson; @@ -42,7 +42,7 @@ protected virtual JToken GetPeers(JArray _params) json["bad"] = new JArray(); //badpeers has been removed json["connected"] = new JArray(localNode.GetRemoteNodes().Select(p => { - var peerJson = new JObject(); + JObject peerJson = new(); peerJson["address"] = p.Remote.Address.ToString(); peerJson["port"] = p.ListenerTcpPort; return peerJson; @@ -50,7 +50,7 @@ protected virtual JToken GetPeers(JArray _params) return json; } - private static JToken GetRelayResult(VerifyResult reason, UInt256 hash) + private static JObject GetRelayResult(VerifyResult reason, UInt256 hash) { if (reason == VerifyResult.Succeed) { @@ -67,7 +67,7 @@ private static JToken GetRelayResult(VerifyResult reason, UInt256 hash) [RpcMethod] protected virtual JToken GetVersion(JArray _params) { - var json = new JObject(); + JObject json = new(); json["tcpport"] = localNode.ListenerTcpPort; json["wsport"] = localNode.ListenerWsPort; json["nonce"] = LocalNode.Nonce; From f3378e31d43080dc9fb2c574a180d709ad1a1a97 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:25:32 +0800 Subject: [PATCH 38/48] Update RpcServer.SmartContract.cs --- src/RpcServer/RpcServer.SmartContract.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/RpcServer/RpcServer.SmartContract.cs b/src/RpcServer/RpcServer.SmartContract.cs index 41d643b16..2a3c38ab7 100644 --- a/src/RpcServer/RpcServer.SmartContract.cs +++ b/src/RpcServer/RpcServer.SmartContract.cs @@ -65,9 +65,9 @@ private void OnTimer(object state) session.Dispose(); } - private JToken GetInvokeResult(byte[] script, Signer[] signers = null, Witness[] witnesses = null, bool useDiagnostic = false) + private JObject GetInvokeResult(byte[] script, Signer[] signers = null, Witness[] witnesses = null, bool useDiagnostic = false) { - var json = new JObject(); + JObject json = new(); Session session = new(system, script, signers, witnesses, settings.MaxGasInvoke, useDiagnostic ? new Diagnostic() : null); try { @@ -124,9 +124,9 @@ private JToken GetInvokeResult(byte[] script, Signer[] signers = null, Witness[] return json; } - private static JToken ToJson(TreeNode node) + private static JObject ToJson(TreeNode node) { - var json = new JObject(); + JObject json = new(); json["hash"] = node.Item.ToString(); if (node.Children.Any()) { @@ -135,7 +135,7 @@ private static JToken ToJson(TreeNode node) return json; } - private static JToken ToJson(IEnumerable changes) + private static JArray ToJson(IEnumerable changes) { JArray array = new(); foreach (var entry in changes) @@ -150,9 +150,9 @@ private static JToken ToJson(IEnumerable changes) return array; } - private static JToken ToJson(StackItem item, Session session) + private static JObject ToJson(StackItem item, Session session) { - JToken json = item.ToJson(); + JObject json = item.ToJson(); if (item is InteropInterface interopInterface && interopInterface.GetInterface() is IIterator iterator) { Guid id = Guid.NewGuid(); @@ -259,7 +259,7 @@ protected virtual JToken TerminateSession(JArray _params) protected virtual JToken GetUnclaimedGas(JArray _params) { string address = _params[0].AsString(); - var json = new JObject(); + JObject json = new(); UInt160 script_hash; try { From 48c510f447804621378f52dcf7abc3f7690cb703 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:34:13 +0800 Subject: [PATCH 39/48] Update RpcServer.Utilities.cs --- src/RpcServer/RpcServer.Utilities.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/RpcServer/RpcServer.Utilities.cs b/src/RpcServer/RpcServer.Utilities.cs index e995d8685..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 @@ -36,7 +36,7 @@ protected virtual JToken ListPlugins(JArray _params) protected virtual JToken ValidateAddress(JArray _params) { string address = _params[0].AsString(); - var json = new JObject(); + JObject json = new(); UInt160 scriptHash; try { From bc770a5f455a8fd36dd80c4fb91f56f82f64ac2a Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:37:04 +0800 Subject: [PATCH 40/48] Update RpcServer.Wallet.cs --- src/RpcServer/RpcServer.Wallet.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcServer/RpcServer.Wallet.cs b/src/RpcServer/RpcServer.Wallet.cs index 438997d93..6548b6529 100644 --- a/src/RpcServer/RpcServer.Wallet.cs +++ b/src/RpcServer/RpcServer.Wallet.cs @@ -86,7 +86,7 @@ protected virtual JToken GetWalletBalance(JArray _params) { CheckWallet(); UInt160 asset_id = UInt160.Parse(_params[0].AsString()); - var json = new JObject(); + JObject json = new(); json["balance"] = wallet.GetAvailable(system.StoreView, asset_id).Value.ToString(); return json; } @@ -159,7 +159,7 @@ protected virtual JToken OpenWallet(JArray _params) return true; } - private void ProcessInvokeWithWallet(JToken result, Signer[] signers = null) + private void ProcessInvokeWithWallet(JObject result, Signer[] signers = null) { if (wallet == null || signers == null || signers.Length == 0) return; @@ -329,7 +329,7 @@ protected virtual JToken InvokeContractVerify(JArray _params) return GetVerificationResult(script_hash, args, signers, witnesses); } - private JToken GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signer[] signers = null, Witness[] witnesses = null) + private JObject GetVerificationResult(UInt160 scriptHash, ContractParameter[] args, Signer[] signers = null, Witness[] witnesses = null) { using var snapshot = system.GetSnapshot(); var contract = NativeContract.ContractManagement.GetContract(snapshot, scriptHash); @@ -364,7 +364,7 @@ private JToken GetVerificationResult(UInt160 scriptHash, ContractParameter[] arg tx.Witnesses ??= new Witness[] { new() { InvocationScript = invocationScript } }; engine.LoadScript(new Script(invocationScript), configureState: p => p.CallFlags = CallFlags.None); } - var json = new JObject(); + JObject json = new(); json["script"] = Convert.ToBase64String(invocationScript); json["state"] = engine.Execute(); json["gasconsumed"] = engine.GasConsumed.ToString(); @@ -380,7 +380,7 @@ private JToken GetVerificationResult(UInt160 scriptHash, ContractParameter[] arg return json; } - private JToken SignAndRelay(DataCache snapshot, Transaction tx) + private JObject SignAndRelay(DataCache snapshot, Transaction tx) { ContractParametersContext context = new(snapshot, tx, settings.Network); wallet.Sign(context); From 009a0bd8b990c93b5c37b13f121b53480160f2a7 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:44:11 +0800 Subject: [PATCH 41/48] Update RpcServer.cs --- src/RpcServer/RpcServer.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/RpcServer/RpcServer.cs b/src/RpcServer/RpcServer.cs index d7cec7368..34a6f4d66 100644 --- a/src/RpcServer/RpcServer.cs +++ b/src/RpcServer/RpcServer.cs @@ -73,9 +73,9 @@ private bool CheckAuth(HttpContext context) return authvalues[0] == settings.RpcUser && authvalues[1] == settings.RpcPass; } - private static JToken CreateErrorResponse(JToken id, int code, string message, JToken data = null) + private static JObject CreateErrorResponse(JToken id, int code, string message, JToken data = null) { - JToken response = CreateResponse(id); + JObject response = CreateResponse(id); response["error"] = new JObject(); response["error"]["code"] = code; response["error"]["message"] = message; @@ -84,7 +84,7 @@ private static JToken CreateErrorResponse(JToken id, int code, string message, J return response; } - private static JToken CreateResponse(JToken id) + private static JObject CreateResponse(JToken id) { JObject response = new(); response["jsonrpc"] = "2.0"; @@ -222,14 +222,14 @@ public async Task ProcessAsync(HttpContext context) await context.Response.WriteAsync(response.ToString(), Encoding.UTF8); } - private async Task ProcessRequestAsync(HttpContext context, JObject request) + private async Task ProcessRequestAsync(HttpContext context, JObject request) { if (!request.ContainsProperty("id")) return null; if (!request.ContainsProperty("method") || !request.ContainsProperty("params") || !(request["params"] is JArray)) { return CreateErrorResponse(request["id"], -32600, "Invalid Request"); } - JToken response = CreateResponse(request["id"]); + JObject response = CreateResponse(request["id"]); try { string method = request["method"].AsString(); From 93785780d5cb9f758e68039c5fb96bfc6d8301bc Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:46:22 +0800 Subject: [PATCH 42/48] Update Utility.cs --- src/RpcServer/Utility.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/RpcServer/Utility.cs b/src/RpcServer/Utility.cs index f90151de1..87cf69871 100644 --- a/src/RpcServer/Utility.cs +++ b/src/RpcServer/Utility.cs @@ -32,7 +32,7 @@ public static JObject TransactionToJson(Transaction tx, ProtocolSettings setting return json; } - public static JToken NativeContractToJson(this NativeContract contract, ProtocolSettings settings) + public static JObject NativeContractToJson(this NativeContract contract, ProtocolSettings settings) { return new JObject { From 838bcf3c2cb4a78af21cb2af3360440f804e1448 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:47:43 +0800 Subject: [PATCH 43/48] Update StateRoot.cs --- src/StateService/Network/StateRoot.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/StateService/Network/StateRoot.cs b/src/StateService/Network/StateRoot.cs index 81ccbfdd9..3adcfe10c 100644 --- a/src/StateService/Network/StateRoot.cs +++ b/src/StateService/Network/StateRoot.cs @@ -109,7 +109,7 @@ public UInt160[] GetScriptHashesForVerifying(DataCache snapshot) return new UInt160[] { Contract.GetBFTAddress(validators) }; } - public JToken ToJson() + public JObject ToJson() { var json = new JObject(); json["version"] = Version; From 14fe7fe3a844ae233b2c82d7facde67d42b7ab86 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:49:25 +0800 Subject: [PATCH 44/48] Update StatesDumper.cs --- src/StatesDumper/StatesDumper.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StatesDumper/StatesDumper.cs b/src/StatesDumper/StatesDumper.cs index 44908eccc..f40a232c6 100644 --- a/src/StatesDumper/StatesDumper.cs +++ b/src/StatesDumper/StatesDumper.cs @@ -96,7 +96,7 @@ private void OnPersistStorage(uint network, DataCache snapshot) { if (Settings.Default.Exclude.Contains(trackable.Key.Id)) continue; - JToken state = new JObject(); + JObject state = new JObject(); switch (trackable.State) { case TrackState.Added: @@ -118,7 +118,7 @@ private void OnPersistStorage(uint network, DataCache snapshot) array.Add(state); } - JToken bs_item = new JObject(); + JObject bs_item = new JObject(); bs_item["block"] = blockIndex; bs_item["size"] = array.Count; bs_item["storage"] = array; From 200d81f4d7c43ce1f8ed6ca8bc1bbb634f252b8f Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:51:39 +0800 Subject: [PATCH 45/48] Update Nep11Tracker.cs and TrackerBase.cs --- .../Trackers/NEP-11/Nep11Tracker.cs | 14 +++++++------- src/TokensTracker/Trackers/TrackerBase.cs | 16 ++++++++-------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs b/src/TokensTracker/Trackers/NEP-11/Nep11Tracker.cs index 16ada0047..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,10 +8,6 @@ // 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.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; @@ -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 @@ -203,7 +203,7 @@ public JToken GetNep11Transfers(JArray _params) if (endTime < startTime) throw new RpcException(-32602, "Invalid params"); - var json = new JObject(); + JObject json = new(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); JArray transfersSent = new(); json["sent"] = transfersSent; @@ -312,7 +312,7 @@ private void AddNep11Transfers(byte dbPrefix, UInt160 userScriptHash, ulong star var transferPairs = QueryTransfers(dbPrefix, userScriptHash, startTime, endTime).Take((int)_maxResults).ToList(); foreach (var (key, value) in transferPairs.OrderByDescending(l => l.key.TimestampMS)) { - JToken transfer = ToJson(key, value); + JObject transfer = ToJson(key, value); transfer["tokenid"] = key.Token.GetSpan().ToHexString(); parentJArray.Add(transfer); } diff --git a/src/TokensTracker/Trackers/TrackerBase.cs b/src/TokensTracker/Trackers/TrackerBase.cs index cceea3c92..88aef3d24 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,12 +8,6 @@ // 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.Json; using Neo.Ledger; @@ -21,6 +15,12 @@ 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 @@ -134,7 +134,7 @@ protected TransferRecord GetTransferRecord(UInt160 asset, Array stateItems) }; } - protected JToken ToJson(TokenTransferKey key, TokenTransfer value) + protected JObject ToJson(TokenTransferKey key, TokenTransfer value) { var transfer = new JObject(); transfer["timestamp"] = key.TimestampMS; From 08d3f1844754d0d040f2149d43b56ed29877fa60 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:52:59 +0800 Subject: [PATCH 46/48] Update Nep17Tracker.cs --- src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs b/src/TokensTracker/Trackers/NEP-17/Nep17Tracker.cs index 050f7e6eb..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,10 +8,6 @@ // 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.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; @@ -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 @@ -152,7 +152,7 @@ public JToken GetNep17Transfers(JArray _params) if (endTime < startTime) throw new RpcException(-32602, "Invalid params"); - var json = new JObject(); + JObject json = new(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); JArray transfersSent = new(); json["sent"] = transfersSent; @@ -168,7 +168,7 @@ public JToken GetNep17Balances(JArray _params) { UInt160 userScriptHash = GetScriptHashFromParam(_params[0].AsString()); - var json = new JObject(); + JObject json = new(); JArray balances = new(); json["address"] = userScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); json["balance"] = balances; From c7d124b8ca7fa296a1611431d6d4d8db16f24bbe Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 13:54:04 +0800 Subject: [PATCH 47/48] Update TrackerBase.cs --- src/TokensTracker/Trackers/TrackerBase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TokensTracker/Trackers/TrackerBase.cs b/src/TokensTracker/Trackers/TrackerBase.cs index 88aef3d24..829a7710c 100644 --- a/src/TokensTracker/Trackers/TrackerBase.cs +++ b/src/TokensTracker/Trackers/TrackerBase.cs @@ -136,7 +136,7 @@ protected TransferRecord GetTransferRecord(UInt160 asset, Array stateItems) protected JObject ToJson(TokenTransferKey key, TokenTransfer value) { - var transfer = new JObject(); + JObject transfer = new(); transfer["timestamp"] = key.TimestampMS; transfer["assethash"] = key.AssetScriptHash.ToString(); transfer["transferaddress"] = value.UserScriptHash == UInt160.Zero ? null : value.UserScriptHash.ToAddress(_neoSystem.Settings.AddressVersion); From 54fac8f571d5b6036e29ba3503d656f5514ff248 Mon Sep 17 00:00:00 2001 From: Erik Zhang Date: Wed, 10 Aug 2022 14:00:12 +0800 Subject: [PATCH 48/48] Fix compilation --- tests/Neo.Network.RPC.Tests/TestUtils.cs | 10 +++--- tests/Neo.Network.RPC.Tests/UT_RpcClient.cs | 4 +-- tests/Neo.Network.RPC.Tests/UT_RpcModels.cs | 36 ++++++++++----------- 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/tests/Neo.Network.RPC.Tests/TestUtils.cs b/tests/Neo.Network.RPC.Tests/TestUtils.cs index b4a2bc689..74380f613 100644 --- a/tests/Neo.Network.RPC.Tests/TestUtils.cs +++ b/tests/Neo.Network.RPC.Tests/TestUtils.cs @@ -9,7 +9,7 @@ namespace Neo.Network.RPC.Tests { internal static class TestUtils { - public readonly static List RpcTestCases = ((JArray)JToken.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) { @@ -60,7 +60,7 @@ internal class RpcTestCase public RpcRequest Request { get; set; } public RpcResponse Response { get; set; } - public JToken ToJson() + public JObject ToJson() { return new JObject { @@ -70,13 +70,13 @@ public JToken ToJson() }; } - public static RpcTestCase FromJson(JToken json) + 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_RpcClient.cs b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs index 27487feb3..7e4e9d0e1 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcClient.cs @@ -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 7c43cc3fc..b31a4e818 100644 --- a/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs +++ b/tests/Neo.Network.RPC.Tests/UT_RpcModels.cs @@ -28,7 +28,7 @@ public void TestSetup() public void TestRpcAccount() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ImportPrivKeyAsync).ToLower()).Response.Result; - var item = RpcAccount.FromJson(json); + var item = RpcAccount.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -36,7 +36,7 @@ public void TestRpcAccount() public void TestRpcApplicationLog() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetApplicationLogAsync).ToLower()).Response.Result; - var item = RpcApplicationLog.FromJson(json, rpc.protocolSettings); + var item = RpcApplicationLog.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -44,7 +44,7 @@ public void TestRpcApplicationLog() public void TestRpcBlock() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockAsync).ToLower()).Response.Result; - var item = RpcBlock.FromJson(json, rpc.protocolSettings); + var item = RpcBlock.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -52,7 +52,7 @@ public void TestRpcBlock() public void TestRpcBlockHeader() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetBlockHeaderAsync).ToLower()).Response.Result; - var item = RpcBlockHeader.FromJson(json, rpc.protocolSettings); + var item = RpcBlockHeader.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -60,10 +60,10 @@ public void TestRpcBlockHeader() public void TestGetContractState() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetContractStateAsync).ToLower()).Response.Result; - var item = RpcContractState.FromJson(json); + 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()); } @@ -71,21 +71,21 @@ public void TestGetContractState() public void TestRpcInvokeResult() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.InvokeFunctionAsync).ToLower()).Response.Result; - var item = RpcInvokeResult.FromJson(json); + var item = RpcInvokeResult.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } [TestMethod()] public void TestRpcMethodToken() { - RpcMethodToken.FromJson(JToken.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() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17BalancesAsync).ToLower()).Response.Result; - var item = RpcNep17Balances.FromJson(json, rpc.protocolSettings); + var item = RpcNep17Balances.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -93,7 +93,7 @@ public void TestRpcNep17Balances() public void TestRpcNep17Transfers() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNep17TransfersAsync).ToLower()).Response.Result; - var item = RpcNep17Transfers.FromJson(json, rpc.protocolSettings); + var item = RpcNep17Transfers.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -101,7 +101,7 @@ public void TestRpcNep17Transfers() public void TestRpcPeers() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetPeersAsync).ToLower()).Response.Result; - var item = RpcPeers.FromJson(json); + var item = RpcPeers.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -109,7 +109,7 @@ public void TestRpcPeers() public void TestRpcPlugin() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ListPluginsAsync).ToLower()).Response.Result; - var item = ((JArray)json).Select(p => RpcPlugin.FromJson(p)); + var item = ((JArray)json).Select(p => RpcPlugin.FromJson((JObject)p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } @@ -117,7 +117,7 @@ public void TestRpcPlugin() public void TestRpcRawMemPool() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawMempoolBothAsync).ToLower()).Response.Result; - var item = RpcRawMemPool.FromJson(json); + var item = RpcRawMemPool.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -125,7 +125,7 @@ public void TestRpcRawMemPool() public void TestRpcTransaction() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetRawTransactionAsync).ToLower()).Response.Result; - var item = RpcTransaction.FromJson(json, rpc.protocolSettings); + var item = RpcTransaction.FromJson((JObject)json, rpc.protocolSettings); Assert.AreEqual(json.ToString(), item.ToJson(rpc.protocolSettings).ToString()); } @@ -133,7 +133,7 @@ public void TestRpcTransaction() public void TestRpcTransferOut() { JToken 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)); + 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()); } @@ -141,7 +141,7 @@ public void TestRpcTransferOut() public void TestRpcValidateAddressResult() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.ValidateAddressAsync).ToLower()).Response.Result; - var item = RpcValidateAddressResult.FromJson(json); + var item = RpcValidateAddressResult.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } @@ -149,7 +149,7 @@ public void TestRpcValidateAddressResult() public void TestRpcValidator() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetNextBlockValidatorsAsync).ToLower()).Response.Result; - var item = ((JArray)json).Select(p => RpcValidator.FromJson(p)); + var item = ((JArray)json).Select(p => RpcValidator.FromJson((JObject)p)); Assert.AreEqual(json.ToString(), ((JArray)item.Select(p => p.ToJson()).ToArray()).ToString()); } @@ -157,7 +157,7 @@ public void TestRpcValidator() public void TestRpcVersion() { JToken json = TestUtils.RpcTestCases.Find(p => p.Name == nameof(RpcClient.GetVersionAsync).ToLower()).Response.Result; - var item = RpcVersion.FromJson(json); + var item = RpcVersion.FromJson((JObject)json); Assert.AreEqual(json.ToString(), item.ToJson().ToString()); } }