From 8f5339304180829727607081c69b27097ff8acc5 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sun, 3 Jul 2022 16:11:38 -0400 Subject: [PATCH 1/8] correct typos, comments --- src/neo/BigDecimal.cs | 11 ++-- src/neo/Cryptography/Base58.cs | 17 +++--- src/neo/Cryptography/BloomFilter.cs | 10 ++-- src/neo/Cryptography/ECC/ECFieldElement.cs | 12 ++-- src/neo/Cryptography/ECC/ECPoint.cs | 23 ++++---- src/neo/Helper.cs | 18 +++--- src/neo/IO/Actors/PriorityMailbox.cs | 12 ++-- src/neo/IO/ByteArrayEqualityComparer.cs | 14 ++--- src/neo/IO/Caching/HashSetCache.cs | 21 +++---- src/neo/IO/Caching/IndexedQueue.cs | 14 ++--- src/neo/IO/Caching/OrderedDictionary.cs | 21 ++----- src/neo/IO/Helper.cs | 13 ++--- src/neo/IO/Json/JArray.cs | 34 +++-------- src/neo/IO/Json/JObject.cs | 20 ++----- src/neo/Ledger/Blockchain.cs | 12 ++-- src/neo/Ledger/MemoryPool.cs | 14 ++--- src/neo/Ledger/PoolItem.cs | 11 ++-- src/neo/NeoSystem.cs | 18 +++--- src/neo/Network/P2P/LocalNode.cs | 22 +++++--- src/neo/Network/P2P/Message.cs | 11 ++-- .../P2P/Payloads/GetBlockByIndexPayload.cs | 10 ++-- src/neo/Network/P2P/Payloads/Header.cs | 37 ++++++------ src/neo/Network/P2P/Payloads/PingPayload.cs | 11 ++-- src/neo/Network/P2P/Payloads/Signer.cs | 19 ++++--- src/neo/Network/P2P/Payloads/Transaction.cs | 11 ++-- src/neo/Network/P2P/Payloads/Witness.cs | 17 +++--- .../Network/P2P/RemoteNode.ProtocolHandler.cs | 18 +++--- src/neo/Network/P2P/RemoteNode.cs | 12 ++-- src/neo/Network/P2P/TaskManager.cs | 48 ++++++++-------- src/neo/Persistence/ClonedCache.cs | 12 ++-- src/neo/Persistence/DataCache.cs | 20 ++++--- src/neo/Plugins/Plugin.cs | 16 +++--- .../ApplicationEngine.Iterator.cs | 12 ++-- .../ApplicationEngine.Storage.cs | 10 ++-- src/neo/SmartContract/ContractParameter.cs | 38 ++++++------- .../ContractParametersContext.cs | 10 ++-- src/neo/SmartContract/Helper.cs | 12 ++-- src/neo/SmartContract/KeyBuilder.cs | 12 ++-- src/neo/SmartContract/Manifest/ContractAbi.cs | 24 ++++---- .../Manifest/ContractEventDescriptor.cs | 17 +++--- .../SmartContract/Manifest/ContractGroup.cs | 17 +++--- .../Manifest/ContractManifest.cs | 14 ++--- .../Manifest/ContractParameterDefinition.cs | 17 +++--- .../Manifest/ContractPermission.cs | 21 ++++--- .../Manifest/ContractPermissionDescriptor.cs | 10 ++-- .../Manifest/WildCardContainer.cs | 12 ++-- src/neo/Wallets/NEP6/NEP6Account.cs | 14 ++--- src/neo/Wallets/NEP6/NEP6Contract.cs | 29 +++++----- src/neo/Wallets/NEP6/NEP6Wallet.cs | 56 +++++++++---------- src/neo/Wallets/NEP6/ScryptParameters.cs | 19 ++++--- src/neo/Wallets/SQLite/UserWallet.cs | 15 ++--- .../Wallets/SQLite/VerificationContract.cs | 11 ++-- src/neo/Wallets/Wallet.cs | 25 ++++----- 53 files changed, 456 insertions(+), 498 deletions(-) diff --git a/src/neo/BigDecimal.cs b/src/neo/BigDecimal.cs index f9c6e0ffb1..2e807e4672 100644 --- a/src/neo/BigDecimal.cs +++ b/src/neo/BigDecimal.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -193,8 +193,7 @@ public int CompareTo(BigDecimal other) public override bool Equals(object obj) { - if (obj is not BigDecimal @decimal) return false; - return Equals(@decimal); + return obj is BigDecimal @decimal && Equals(@decimal); } public bool Equals(BigDecimal other) diff --git a/src/neo/Cryptography/Base58.cs b/src/neo/Cryptography/Base58.cs index 92ec97291e..f906f3403e 100644 --- a/src/neo/Cryptography/Base58.cs +++ b/src/neo/Cryptography/Base58.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -45,10 +45,13 @@ public static byte[] Base58CheckDecode(this string input) } /// - /// Converts a byte array to its equivalent representation that is encoded with base-58 digits. The encoded contains the checksum of the binary data. + /// Converts a byte array to its equivalent + /// representation that is encoded with base-58 digits. + /// The encoded contains the checksum of the binary data. /// /// The byte array to convert. - /// The representation, in base-58, of the contents of . + /// The representation, + /// in base-58, of the contents of . public static string Base58CheckEncode(this ReadOnlySpan data) { byte[] checksum = data.Sha256().Sha256(); @@ -67,7 +70,7 @@ public static string Base58CheckEncode(this ReadOnlySpan data) /// A byte array that is equivalent to . public static byte[] Decode(string input) { - // Decode Base58 string to BigInteger + // Decode Base58 string to BigInteger var bi = BigInteger.Zero; for (int i = 0; i < input.Length; i++) { diff --git a/src/neo/Cryptography/BloomFilter.cs b/src/neo/Cryptography/BloomFilter.cs index 49e7aee983..1b1517c672 100644 --- a/src/neo/Cryptography/BloomFilter.cs +++ b/src/neo/Cryptography/BloomFilter.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -85,7 +85,7 @@ public void Add(ReadOnlyMemory element) /// if is found in the ; otherwise, . public bool Check(byte[] element) { - foreach (uint i in seeds.AsParallel().Select(s => element.Murmur32(s))) + foreach (uint i in seeds.AsParallel().Select(element.Murmur32)) if (!bits.Get((int)(i % (uint)bits.Length))) return false; return true; diff --git a/src/neo/Cryptography/ECC/ECFieldElement.cs b/src/neo/Cryptography/ECC/ECFieldElement.cs index d138666b3f..907aaff276 100644 --- a/src/neo/Cryptography/ECC/ECFieldElement.cs +++ b/src/neo/Cryptography/ECC/ECFieldElement.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,10 +40,8 @@ public override bool Equals(object obj) if (obj == this) return true; - if (obj is not ECFieldElement other) - return false; + return obj is ECFieldElement other && Equals(other); - return Equals(other); } public bool Equals(ECFieldElement other) diff --git a/src/neo/Cryptography/ECC/ECPoint.cs b/src/neo/Cryptography/ECC/ECPoint.cs index 8474864052..9919d514c1 100644 --- a/src/neo/Cryptography/ECC/ECPoint.cs +++ b/src/neo/Cryptography/ECC/ECPoint.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -29,10 +29,7 @@ public class ECPoint : IComparable, IEquatable, ISerializable /// /// Indicates whether it is a point at infinity. /// - public bool IsInfinity - { - get { return X == null && Y == null; } - } + public bool IsInfinity => X == null && Y == null; public int Size => IsInfinity ? 1 : 33; @@ -241,10 +238,10 @@ internal static ECPoint Multiply(ECPoint p, BigInteger k) // width of the Window NAF sbyte width; - // Required length of precomputation array + // Required length of precomputing array int reqPreCompLen; - // Determine optimal width and corresponding length of precomputation + // Determine optimal width and corresponding length of precomputing array // array based on literature values if (m < 13) { @@ -282,7 +279,7 @@ internal static ECPoint Multiply(ECPoint p, BigInteger k) reqPreCompLen = 127; } - // The length of the precomputation array + // The length of the precomputing array int preCompLen = 1; ECPoint[] preComp = new ECPoint[] { p }; @@ -290,7 +287,7 @@ internal static ECPoint Multiply(ECPoint p, BigInteger k) if (preCompLen < reqPreCompLen) { - // Precomputation array must be made bigger, copy existing preComp + // Precomputing array must be made bigger, copy existing preComp // array into the larger new preComp array ECPoint[] oldPreComp = preComp; preComp = new ECPoint[reqPreCompLen]; @@ -298,7 +295,7 @@ internal static ECPoint Multiply(ECPoint p, BigInteger k) for (int i = preCompLen; i < reqPreCompLen; i++) { - // Compute the new ECPoints for the precomputation array. + // Compute the new ECPoints for the precomputing array. // The values 1, 3, 5, ..., 2^(width-1)-1 times p are // computed preComp[i] = twiceP + preComp[i - 1]; diff --git a/src/neo/Helper.cs b/src/neo/Helper.cs index fa47cb6669..a3497f8c2e 100644 --- a/src/neo/Helper.cs +++ b/src/neo/Helper.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -54,9 +54,7 @@ private static int BitLen(int w) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] Concat(params byte[][] buffers) { - int length = 0; - for (int i = 0; i < buffers.Length; i++) - length += buffers[i].Length; + int length = buffers.Sum(t => t.Length); byte[] dst = new byte[length]; int p = 0; foreach (byte[] src in buffers) @@ -146,7 +144,7 @@ internal static string GetVersion(this Assembly assembly) /// The converted byte array. public static byte[] HexToBytes(this string value) { - if (value == null || value.Length == 0) + if (string.IsNullOrEmpty(value)) return Array.Empty(); if (value.Length % 2 == 1) throw new FormatException(); @@ -288,7 +286,7 @@ public static ulong ToTimestampMS(this DateTime time) } /// - /// Checks if address is IPv4 Maped to IPv6 format, if so, Map to IPv4. + /// Checks if address is IPv4 Mapped to IPv6 format, if so, Map to IPv4. /// Otherwise, return current address. /// internal static IPAddress Unmap(this IPAddress address) @@ -299,7 +297,7 @@ internal static IPAddress Unmap(this IPAddress address) } /// - /// Checks if IPEndPoint is IPv4 Maped to IPv6 format, if so, unmap to IPv4. + /// Checks if IPEndPoint is IPv4 Mapped to IPv6 format, if so, unmap to IPv4. /// Otherwise, return current endpoint. /// internal static IPEndPoint Unmap(this IPEndPoint endPoint) diff --git a/src/neo/IO/Actors/PriorityMailbox.cs b/src/neo/IO/Actors/PriorityMailbox.cs index 6dc8f0b429..1a6d3a6ec5 100644 --- a/src/neo/IO/Actors/PriorityMailbox.cs +++ b/src/neo/IO/Actors/PriorityMailbox.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -28,7 +28,7 @@ public override IMessageQueue Create(IActorRef owner, ActorSystem system) return new PriorityMessageQueue(ShallDrop, IsHighPriority); } - internal protected virtual bool IsHighPriority(object message) => false; - internal protected virtual bool ShallDrop(object message, IEnumerable queue) => false; + protected internal virtual bool IsHighPriority(object message) => false; + protected internal virtual bool ShallDrop(object message, IEnumerable queue) => false; } } diff --git a/src/neo/IO/ByteArrayEqualityComparer.cs b/src/neo/IO/ByteArrayEqualityComparer.cs index b069d87228..b31f5c82ab 100644 --- a/src/neo/IO/ByteArrayEqualityComparer.cs +++ b/src/neo/IO/ByteArrayEqualityComparer.cs @@ -1,14 +1,15 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. using System.Collections.Generic; +using System.Linq; namespace Neo.IO { @@ -47,10 +48,7 @@ public int GetHashCode(byte[] obj) { unchecked { - int hash = 17; - foreach (byte element in obj) - hash = hash * 31 + element; - return hash; + return obj.Aggregate(17, (current, element) => current * 31 + element); } } } diff --git a/src/neo/IO/Caching/HashSetCache.cs b/src/neo/IO/Caching/HashSetCache.cs index 3e6eea90f7..55083a9ce2 100644 --- a/src/neo/IO/Caching/HashSetCache.cs +++ b/src/neo/IO/Caching/HashSetCache.cs @@ -1,16 +1,17 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. using System; using System.Collections; using System.Collections.Generic; +using System.Linq; namespace Neo.IO.Caching { @@ -18,12 +19,12 @@ class HashSetCache : IReadOnlyCollection where T : IEquatable { /// /// Sets where the Hashes are stored - /// + /// private readonly LinkedList> sets = new(); /// /// Maximum capacity of each bucket inside each HashSet of . - /// + /// private readonly int bucketCapacity; /// @@ -102,13 +103,7 @@ public void ExceptWith(IEnumerable items) public IEnumerator GetEnumerator() { - foreach (var set in sets) - { - foreach (var item in set) - { - yield return item; - } - } + return sets.SelectMany(set => set).GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/src/neo/IO/Caching/IndexedQueue.cs b/src/neo/IO/Caching/IndexedQueue.cs index 0cdca447a5..2cb043574e 100644 --- a/src/neo/IO/Caching/IndexedQueue.cs +++ b/src/neo/IO/Caching/IndexedQueue.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -107,9 +107,9 @@ public void Enqueue(T item) } /// - /// Provides access to the item at the front of the queue without dequeueing it + /// Provides access to the item at the front of the queue without dequeuing it /// - /// The frontmost item + /// The front most item public T Peek() { if (_count == 0) @@ -201,7 +201,7 @@ public void TrimExcess() } /// - /// Copys the queue's items to a destination array + /// Copy the queue's items to a destination array /// /// The destination array /// The index in the destination to start copying at diff --git a/src/neo/IO/Caching/OrderedDictionary.cs b/src/neo/IO/Caching/OrderedDictionary.cs index 7f384d1380..53c7d43d4e 100644 --- a/src/neo/IO/Caching/OrderedDictionary.cs +++ b/src/neo/IO/Caching/OrderedDictionary.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,10 +40,7 @@ protected override TKey GetKeyForItem(TItem item) public TValue this[TKey key] { - get - { - return collection[key].Value; - } + get => collection[key].Value; set { if (collection.TryGetValue(key, out var entry)) @@ -53,13 +50,7 @@ public TValue this[TKey key] } } - public TValue this[int index] - { - get - { - return collection[index].Value; - } - } + public TValue this[int index] => collection[index].Value; public void Add(TKey key, TValue value) { diff --git a/src/neo/IO/Helper.cs b/src/neo/IO/Helper.cs index adaf127081..8f52d768c2 100644 --- a/src/neo/IO/Helper.cs +++ b/src/neo/IO/Helper.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -132,10 +132,9 @@ public static int GetVarSize(int value) { if (value < 0xFD) return sizeof(byte); - else if (value <= 0xFFFF) + if (value <= 0xFFFF) return sizeof(byte) + sizeof(ushort); - else - return sizeof(byte) + sizeof(uint); + return sizeof(byte) + sizeof(uint); } /// diff --git a/src/neo/IO/Json/JArray.cs b/src/neo/IO/Json/JArray.cs index eee381eda4..238c2c282c 100644 --- a/src/neo/IO/Json/JArray.cs +++ b/src/neo/IO/Json/JArray.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -41,31 +41,13 @@ public JArray(IEnumerable items) public override JObject this[int index] { - get - { - return items[index]; - } - set - { - items[index] = value; - } + get => items[index]; + set => items[index] = value; } - public int Count - { - get - { - return items.Count; - } - } + public int Count => items.Count; - public bool IsReadOnly - { - get - { - return false; - } - } + public bool IsReadOnly => false; public void Add(JObject item) { diff --git a/src/neo/IO/Json/JObject.cs b/src/neo/IO/Json/JObject.cs index 678c1d85db..30895cf2c8 100644 --- a/src/neo/IO/Json/JObject.cs +++ b/src/neo/IO/Json/JObject.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,16 +40,8 @@ public class JObject /// The property with the specified name. public JObject this[string name] { - get - { - if (Properties.TryGetValue(name, out JObject value)) - return value; - return null; - } - set - { - Properties[name] = value; - } + get => Properties.TryGetValue(name, out JObject value) ? value : null; + set => Properties[name] = value; } /// diff --git a/src/neo/Ledger/Blockchain.cs b/src/neo/Ledger/Blockchain.cs index 52b3c37ce5..45aba850a9 100644 --- a/src/neo/Ledger/Blockchain.cs +++ b/src/neo/Ledger/Blockchain.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -119,7 +119,7 @@ internal class Initialize { } public static event CommittingHandler Committing; public static event CommittedHandler Committed; - private readonly static Script onPersistScript, postPersistScript; + private static readonly Script onPersistScript, postPersistScript; private const int MaxTxToReverifyPerIdle = 10; private readonly NeoSystem system; private readonly Dictionary block_cache = new(); @@ -496,7 +496,7 @@ public BlockchainMailbox(Settings settings, Config config) { } - internal protected override bool IsHighPriority(object message) + protected internal override bool IsHighPriority(object message) { return message switch { diff --git a/src/neo/Ledger/MemoryPool.cs b/src/neo/Ledger/MemoryPool.cs index 839af3e7b1..2f64b90786 100644 --- a/src/neo/Ledger/MemoryPool.cs +++ b/src/neo/Ledger/MemoryPool.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -29,13 +29,13 @@ public class MemoryPool : IReadOnlyCollection public event EventHandler TransactionAdded; public event EventHandler TransactionRemoved; - // Allow a reverified transaction to be rebroadcasted if it has been this many block times since last broadcast. + // Allow a reverified transaction to be rebroadcast if it has been this many block times since last broadcast. private const int BlocksTillRebroadcast = 10; private int RebroadcastMultiplierThreshold => Capacity / 10; private readonly double MaxMillisecondsToReverifyTx; - // These two are not expected to be hit, they are just safegaurds. + // These two are not expected to be hit, they are just safeguards. private readonly double MaxMillisecondsToReverifyTxPerIdle; private readonly NeoSystem _system; @@ -55,7 +55,7 @@ public class MemoryPool : IReadOnlyCollection /// private readonly Dictionary _unsortedTransactions = new(); /// - /// Stores the verified sorted transactins currently in the pool. + /// Stores the verified sorted transactions currently in the pool. /// private readonly SortedSet _sortedTransactions = new(); diff --git a/src/neo/Ledger/PoolItem.cs b/src/neo/Ledger/PoolItem.cs index 37dfb906c5..fde291014c 100644 --- a/src/neo/Ledger/PoolItem.cs +++ b/src/neo/Ledger/PoolItem.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -59,8 +59,7 @@ public int CompareTo(Transaction otherTx) public int CompareTo(PoolItem otherItem) { - if (otherItem == null) return 1; - return CompareTo(otherItem.Tx); + return otherItem == null ? 1 : CompareTo(otherItem.Tx); } } } diff --git a/src/neo/NeoSystem.cs b/src/neo/NeoSystem.cs index c72d81fd3a..334da2f4db 100644 --- a/src/neo/NeoSystem.cs +++ b/src/neo/NeoSystem.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -165,7 +165,7 @@ public void Dispose() { foreach (var p in Plugin.Plugins) p.Dispose(); - EnsureStoped(LocalNode); + EnsureStopped(LocalNode); // Dispose will call ActorSystem.Terminate() ActorSystem.Dispose(); ActorSystem.WhenTerminated.Wait(); @@ -194,15 +194,14 @@ public T GetService(Func filter = null) IEnumerable result = services.OfType(); if (filter is null) return result.FirstOrDefault(); - else - return result.FirstOrDefault(filter); + return result.FirstOrDefault(filter); } /// /// Blocks the current thread until the specified actor has stopped. /// /// The actor to wait. - public void EnsureStoped(IActorRef actor) + public void EnsureStopped(IActorRef actor) { using Inbox inbox = Inbox.Create(ActorSystem); inbox.Watch(actor); @@ -275,8 +274,7 @@ public SnapshotCache GetSnapshot() /// if the transaction exists; otherwise, . public bool ContainsTransaction(UInt256 hash) { - if (MemPool.ContainsKey(hash)) return true; - return NativeContract.Ledger.ContainsTransaction(StoreView, hash); + return MemPool.ContainsKey(hash) || NativeContract.Ledger.ContainsTransaction(StoreView, hash); } } } diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index 0929b59140..d023de61dd 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -112,7 +112,7 @@ private void BroadcastMessage(MessageCommand command, ISerializable payload = nu /// /// Broadcast a message to all connected nodes. /// - /// The message to be broadcasted. + /// The message to be broadcast. private void BroadcastMessage(Message message) => SendToRemoteNodes(message); /// @@ -160,7 +160,8 @@ internal static IPEndPoint GetIpEndPoint(string hostAndPort) /// /// Checks the new connection. - /// If it is equal to the nonce of local or any remote node, it'll return false, else we'll return true and update the Listener address of the connected remote node. + /// If it is equal to the nonce of local or any remote node, it'll return false, + /// else we'll return true and update the Listener address of the connected remote node. /// /// Remote node actor. /// Remote node object. @@ -200,8 +201,10 @@ public IEnumerable GetUnconnectedPeers() } /// - /// Performs a broadcast with the command , which, eventually, tells all known connections. - /// If there are no connected peers it will try with the default, respecting limit. + /// Performs a broadcast with the command , + /// which, eventually, tells all known connections. + /// If there are no connected peers it will try with the default, + /// respecting limit. /// /// Number of peers that are being requested. protected override void NeedMorePeers(int count) @@ -244,7 +247,8 @@ protected override void OnReceive(object message) private void OnRelayDirectly(IInventory inventory) { var message = new RemoteNode.Relay { Inventory = inventory }; - // When relaying a block, if the block's index is greater than 'LastBlockIndex' of the RemoteNode, relay the block; + // When relaying a block, if the block's index is greater than + // 'LastBlockIndex' of the RemoteNode, relay the block; // otherwise, don't relay. if (inventory is Block block) { diff --git a/src/neo/Network/P2P/Message.cs b/src/neo/Network/P2P/Message.cs index 00242c5fec..fa3f1b17ea 100644 --- a/src/neo/Network/P2P/Message.cs +++ b/src/neo/Network/P2P/Message.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -53,7 +53,8 @@ public class Message : ISerializable /// Creates a new instance of the class. /// /// The command of the message. - /// The payload of the message. For the messages that don't require a payload, it should be . + /// The payload of the message. + /// For the messages that don't require a payload, it should be . /// public static Message Create(MessageCommand command, ISerializable payload = null) { diff --git a/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs b/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs index 115bc14c3d..e332e55abf 100644 --- a/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs +++ b/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -50,7 +50,7 @@ void ISerializable.Deserialize(ref MemoryReader reader) { IndexStart = reader.ReadUInt32(); Count = reader.ReadInt16(); - if (Count < -1 || Count == 0 || Count > HeadersPayload.MaxHeadersCount) + if (Count is < -1 or 0 or > HeadersPayload.MaxHeadersCount) throw new FormatException(); } diff --git a/src/neo/Network/P2P/Payloads/Header.cs b/src/neo/Network/P2P/Payloads/Header.cs index f5473d48f9..a5888f6838 100644 --- a/src/neo/Network/P2P/Payloads/Header.cs +++ b/src/neo/Network/P2P/Payloads/Header.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -133,7 +133,7 @@ public UInt256 Hash sizeof(uint) + // Index sizeof(byte) + // PrimaryIndex UInt160.Length + // NextConsensus - 1 + Witness.Size; // Witness + 1 + Witness.Size; // Witness Witness[] IVerifiable.Witnesses { @@ -220,19 +220,20 @@ void IVerifiable.SerializeUnsigned(BinaryWriter writer) /// The header represented by a JSON object. public JObject ToJson(ProtocolSettings settings) { - JObject json = new(); - json["hash"] = Hash.ToString(); - json["size"] = Size; - json["version"] = version; - json["previousblockhash"] = prevHash.ToString(); - json["merkleroot"] = merkleRoot.ToString(); - json["time"] = timestamp; - json["nonce"] = nonce.ToString("X16"); - json["index"] = index; - json["primary"] = primaryIndex; - json["nextconsensus"] = nextConsensus.ToAddress(settings.AddressVersion); - json["witnesses"] = new JArray(Witness.ToJson()); - return json; + return new JObject + { + ["hash"] = Hash.ToString(), + ["size"] = Size, + ["version"] = version, + ["previousblockhash"] = prevHash.ToString(), + ["merkleroot"] = merkleRoot.ToString(), + ["time"] = timestamp, + ["nonce"] = nonce.ToString("X16"), + ["index"] = index, + ["primary"] = primaryIndex, + ["nextconsensus"] = nextConsensus.ToAddress(settings.AddressVersion), + ["witnesses"] = new JArray(Witness.ToJson()) + }; } internal bool Verify(ProtocolSettings settings, DataCache snapshot) diff --git a/src/neo/Network/P2P/Payloads/PingPayload.cs b/src/neo/Network/P2P/Payloads/PingPayload.cs index 048c8b7157..3234895288 100644 --- a/src/neo/Network/P2P/Payloads/PingPayload.cs +++ b/src/neo/Network/P2P/Payloads/PingPayload.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -30,7 +30,8 @@ public class PingPayload : ISerializable public uint Timestamp; /// - /// A random number. This number must be the same in and messages. + /// A random number. This number must be the same in + /// and messages. /// public uint Nonce; diff --git a/src/neo/Network/P2P/Payloads/Signer.cs b/src/neo/Network/P2P/Payloads/Signer.cs index b91d1d45f5..ab5de4187e 100644 --- a/src/neo/Network/P2P/Payloads/Signer.cs +++ b/src/neo/Network/P2P/Payloads/Signer.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,17 +40,20 @@ public class Signer : IInteroperable, ISerializable public WitnessScope Scopes; /// - /// The contracts that allowed by the witness. Only available when the flag is set. + /// The contracts that allowed by the witness. + /// Only available when the flag is set. /// public UInt160[] AllowedContracts; /// - /// The groups that allowed by the witness. Only available when the flag is set. + /// The groups that allowed by the witness. + /// Only available when the flag is set. /// public ECPoint[] AllowedGroups; /// - /// The rules that the witness must meet. Only available when the flag is set. + /// The rules that the witness must meet. + /// Only available when the flag is set. /// public WitnessRule[] Rules; @@ -81,7 +84,7 @@ public void Deserialize(ref MemoryReader reader) } /// - /// Converts all rules contianed in the object to . + /// Converts all rules contained in the object to . /// /// The array used to represent the current signer. public IEnumerable GetAllRules() diff --git a/src/neo/Network/P2P/Payloads/Transaction.cs b/src/neo/Network/P2P/Payloads/Transaction.cs index 82900545c1..efe60a0fc5 100644 --- a/src/neo/Network/P2P/Payloads/Transaction.cs +++ b/src/neo/Network/P2P/Payloads/Transaction.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -244,8 +244,7 @@ public void DeserializeUnsigned(ref MemoryReader reader) public bool Equals(Transaction other) { if (other is null) return false; - if (ReferenceEquals(this, other)) return true; - return Hash.Equals(other.Hash); + return ReferenceEquals(this, other) || Hash.Equals(other.Hash); } public override bool Equals(object obj) diff --git a/src/neo/Network/P2P/Payloads/Witness.cs b/src/neo/Network/P2P/Payloads/Witness.cs index 113487cd6c..f3f7b12b02 100644 --- a/src/neo/Network/P2P/Payloads/Witness.cs +++ b/src/neo/Network/P2P/Payloads/Witness.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -74,10 +74,11 @@ void ISerializable.Serialize(BinaryWriter writer) /// The witness represented by a JSON object. public JObject ToJson() { - JObject json = new(); - json["invocation"] = Convert.ToBase64String(InvocationScript.Span); - json["verification"] = Convert.ToBase64String(VerificationScript.Span); - return json; + return new JObject + { + ["invocation"] = Convert.ToBase64String(InvocationScript.Span), + ["verification"] = Convert.ToBase64String(VerificationScript.Span) + }; } } } diff --git a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs index 85b1b4f628..d0999d8d3d 100644 --- a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs +++ b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -56,9 +56,10 @@ public static event MessageReceivedHandler MessageReceived private void OnMessage(Message msg) { - foreach (MessageReceivedHandler handler in handlers) - if (!handler(system, msg)) - return; + if (handlers.Any(handler => !handler(system, msg))) + { + return; + } if (Version == null) { if (msg.Command != MessageCommand.Version) @@ -233,7 +234,8 @@ private void OnGetBlockByIndexMessageReceived(GetBlockByIndexPayload payload) /// /// Will be triggered when a MessageCommand.GetData message is received. /// The payload includes an array of hash values. - /// For different payload.Type (Tx, Block, Consensus), get the corresponding (Txs, Blocks, Consensus) and tell them to RemoteNode actor. + /// For different payload.Type (Tx, Block, Consensus), + /// get the corresponding (Txs, Blocks, Consensus) and tell them to RemoteNode actor. /// /// The payload containing the requested information. private void OnGetDataMessageReceived(InvPayload payload) diff --git a/src/neo/Network/P2P/RemoteNode.cs b/src/neo/Network/P2P/RemoteNode.cs index e7444433c9..2a066fe09c 100644 --- a/src/neo/Network/P2P/RemoteNode.cs +++ b/src/neo/Network/P2P/RemoteNode.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -246,7 +246,7 @@ internal class RemoteNodeMailbox : PriorityMailbox { public RemoteNodeMailbox(Settings settings, Config config) : base(settings, config) { } - internal protected override bool IsHighPriority(object message) + protected internal override bool IsHighPriority(object message) { return message switch { @@ -260,7 +260,7 @@ internal protected override bool IsHighPriority(object message) }; } - internal protected override bool ShallDrop(object message, IEnumerable queue) + protected internal override bool ShallDrop(object message, IEnumerable queue) { if (message is not Message msg) return false; return msg.Command switch diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index 6825639171..bf5eaed719 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -51,7 +51,7 @@ private class Timer { } private static readonly TimeSpan TaskTimeout = TimeSpan.FromMinutes(1); private static readonly UInt256 HeaderTaskHash = UInt256.Zero; - private const int MaxConncurrentTasks = 3; + private const int MaxConcurrentTasks = 3; private readonly NeoSystem system; /// @@ -231,7 +231,6 @@ private void OnTaskCompleted(IInventory inventory) if (block.Hash != block_old.Hash) { Sender.Tell(Tcp.Abort.Instance); - return; } } else @@ -249,25 +248,21 @@ private void OnTaskCompleted(IInventory inventory) [MethodImpl(MethodImplOptions.AggressiveInlining)] private void DecrementGlobalTask(UInt256 hash) { - if (globalInvTasks.TryGetValue(hash, out var value)) - { - if (value == 1) - globalInvTasks.Remove(hash); - else - globalInvTasks[hash] = value - 1; - } + if (!globalInvTasks.TryGetValue(hash, out var value)) return; + if (value == 1) + globalInvTasks.Remove(hash); + else + globalInvTasks[hash] = value - 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void DecrementGlobalTask(uint index) { - if (globalIndexTasks.TryGetValue(index, out var value)) - { - if (value == 1) - globalIndexTasks.Remove(index); - else - globalIndexTasks[index] = value - 1; - } + if (!globalIndexTasks.TryGetValue(index, out var value)) return; + if (value == 1) + globalIndexTasks.Remove(index); + else + globalIndexTasks[index] = value - 1; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -278,7 +273,7 @@ private bool IncrementGlobalTask(UInt256 hash) globalInvTasks[hash] = 1; return true; } - if (value >= MaxConncurrentTasks) + if (value >= MaxConcurrentTasks) return false; globalInvTasks[hash] = value + 1; @@ -293,7 +288,7 @@ private bool IncrementGlobalTask(uint index) globalIndexTasks[index] = 1; return true; } - if (value >= MaxConncurrentTasks) + if (value >= MaxConcurrentTasks) return false; globalIndexTasks[index] = value + 1; @@ -379,9 +374,10 @@ private void RequestTasks(IActorRef remoteNode, TaskSession session) uint currentHeight = Math.Max(NativeContract.Ledger.CurrentIndex(snapshot), lastSeenPersistedIndex); uint headerHeight = system.HeaderCache.Last?.Index ?? currentHeight; - // When the number of AvailableTasks is no more than 0, no pending tasks of InventoryType.Block, it should process pending the tasks of headers + // When the number of AvailableTasks is no more than 0, + // no pending tasks of InventoryType.Block, it should process pending the tasks of headers // If not HeaderTask pending to be processed it should ask for more Blocks - if ((!HasHeaderTask || globalInvTasks[HeaderTaskHash] < MaxConncurrentTasks) && headerHeight < session.LastBlockIndex && !system.HeaderCache.Full) + if ((!HasHeaderTask || globalInvTasks[HeaderTaskHash] < MaxConcurrentTasks) && headerHeight < session.LastBlockIndex && !system.HeaderCache.Full) { session.InvTasks[HeaderTaskHash] = DateTime.UtcNow; IncrementGlobalTask(HeaderTaskHash); @@ -417,7 +413,7 @@ public TaskManagerMailbox(Akka.Actor.Settings settings, Config config) { } - internal protected override bool IsHighPriority(object message) + protected internal override bool IsHighPriority(object message) { switch (message) { @@ -434,7 +430,7 @@ internal protected override bool IsHighPriority(object message) } } - internal protected override bool ShallDrop(object message, IEnumerable queue) + protected internal override bool ShallDrop(object message, IEnumerable queue) { if (message is not TaskManager.NewTasks tasks) return false; // Remove duplicate tasks diff --git a/src/neo/Persistence/ClonedCache.cs b/src/neo/Persistence/ClonedCache.cs index ed25a957e4..72a308e55a 100644 --- a/src/neo/Persistence/ClonedCache.cs +++ b/src/neo/Persistence/ClonedCache.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -42,9 +42,9 @@ protected override StorageItem GetInternal(StorageKey key) return innerCache[key].Clone(); } - protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction) + protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPrefix, SeekDirection direction) { - foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction)) + foreach (var (key, value) in innerCache.Seek(keyOrPrefix, direction)) yield return (key, value.Clone()); } diff --git a/src/neo/Persistence/DataCache.cs b/src/neo/Persistence/DataCache.cs index b387b2cde3..04a4f261dc 100644 --- a/src/neo/Persistence/DataCache.cs +++ b/src/neo/Persistence/DataCache.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -125,6 +125,7 @@ public virtual void Commit() { LinkedList deletedItem = new(); foreach (Trackable trackable in GetChangeSet()) + { switch (trackable.State) { case TrackState.Added: @@ -140,11 +141,16 @@ public virtual void Commit() deletedItem.AddFirst(trackable.Key); break; } - foreach (StorageKey key in deletedItem) + } + lock (dictionary) { - dictionary.Remove(key); + foreach (StorageKey key in deletedItem) + { + dictionary.Remove(key); + } + changeSet.Clear(); } - changeSet.Clear(); + } /// diff --git a/src/neo/Plugins/Plugin.cs b/src/neo/Plugins/Plugin.cs index c5f348fb71..2aee3cb0b8 100644 --- a/src/neo/Plugins/Plugin.cs +++ b/src/neo/Plugins/Plugin.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -19,7 +19,8 @@ namespace Neo.Plugins { /// - /// Represents the base class of all plugins. Any plugin should inherit this class. The plugins are automatically loaded when the process starts. + /// Represents the base class of all plugins. Any plugin should inherit this class. + /// The plugins are automatically loaded when the process starts. /// public abstract class Plugin : IDisposable { @@ -89,7 +90,8 @@ protected Plugin() } /// - /// Called when the plugin is loaded and need to load the configure file, or the configuration file has been modified and needs to be reconfigured. + /// Called when the plugin is loaded and need to load the configure file, + /// or the configuration file has been modified and needs to be reconfigured. /// protected virtual void Configure() { @@ -211,7 +213,7 @@ protected void Log(object message, LogLevel level = LogLevel.Info) } /// - /// Called when a message to the plugins is received. The messnage is sent by calling . + /// Called when a message to the plugins is received. The message is sent by calling . /// /// The received message. /// if the has been handled; otherwise, . diff --git a/src/neo/SmartContract/ApplicationEngine.Iterator.cs b/src/neo/SmartContract/ApplicationEngine.Iterator.cs index 2280f2dced..66ca698e1f 100644 --- a/src/neo/SmartContract/ApplicationEngine.Iterator.cs +++ b/src/neo/SmartContract/ApplicationEngine.Iterator.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -33,7 +33,7 @@ partial class ApplicationEngine /// /// The iterator to be advanced. /// if the iterator was successfully advanced to the next element; if the iterator has passed the end of the collection. - internal protected static bool IteratorNext(IIterator iterator) + protected internal static bool IteratorNext(IIterator iterator) { return iterator.Next(); } @@ -44,7 +44,7 @@ internal protected static bool IteratorNext(IIterator iterator) /// /// The iterator to be used. /// The element in the collection at the current position of the iterator. - internal protected StackItem IteratorValue(IIterator iterator) + protected internal StackItem IteratorValue(IIterator iterator) { return iterator.Value(ReferenceCounter); } diff --git a/src/neo/SmartContract/ApplicationEngine.Storage.cs b/src/neo/SmartContract/ApplicationEngine.Storage.cs index 1ae615ce54..d597a3e97f 100644 --- a/src/neo/SmartContract/ApplicationEngine.Storage.cs +++ b/src/neo/SmartContract/ApplicationEngine.Storage.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -104,7 +104,7 @@ protected internal StorageContext GetReadOnlyContext() /// /// The storage context to convert. /// The readonly storage context. - internal protected static StorageContext AsReadOnly(StorageContext context) + protected internal static StorageContext AsReadOnly(StorageContext context) { if (!context.IsReadOnly) context = new StorageContext diff --git a/src/neo/SmartContract/ContractParameter.cs b/src/neo/SmartContract/ContractParameter.cs index 0c4a79f518..66bcade4f7 100644 --- a/src/neo/SmartContract/ContractParameter.cs +++ b/src/neo/SmartContract/ContractParameter.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -192,6 +192,7 @@ public override string ToString() private static string ToString(ContractParameter parameter, HashSet context) { + StringBuilder sb; switch (parameter.Value) { case null: @@ -199,26 +200,25 @@ private static string ToString(ContractParameter parameter, HashSet data: - if (context is null) context = new HashSet(); + context ??= new HashSet(); if (context.Contains(parameter)) { return "(array)"; } - else + + context.Add(parameter); + sb = new StringBuilder(); + sb.Append('['); + foreach (ContractParameter item in data) { - context.Add(parameter); - StringBuilder sb = new(); - sb.Append('['); - foreach (ContractParameter item in data) - { - sb.Append(ToString(item, context)); - sb.Append(", "); - } - if (data.Count > 0) - sb.Length -= 2; - sb.Append(']'); - return sb.ToString(); + sb.Append(ToString(item, context)); + sb.Append(", "); } + if (data.Count > 0) + sb.Length -= 2; + sb.Append(']'); + return sb.ToString(); + case IList> data: if (context is null) context = new HashSet(); if (context.Contains(parameter)) @@ -228,7 +228,7 @@ private static string ToString(ContractParameter parameter, HashSet script, out int m, out m = BinaryPrimitives.ReadUInt16LittleEndian(script[++i..]); i += 2; break; - case byte b when b >= (byte)OpCode.PUSH1 && b <= (byte)OpCode.PUSH16: + case byte b and >= (byte)OpCode.PUSH1 and <= (byte)OpCode.PUSH16: m = b - (byte)OpCode.PUSH0; ++i; break; @@ -198,7 +198,7 @@ private static bool IsMultiSigContract(ReadOnlySpan script, out int m, out if (script.Length < i + 3 || n != BinaryPrimitives.ReadUInt16LittleEndian(script[++i..])) return false; i += 2; break; - case byte b when b >= (byte)OpCode.PUSH1 && b <= (byte)OpCode.PUSH16: + case byte b and >= (byte)OpCode.PUSH1 and <= (byte)OpCode.PUSH16: if (n != b - (byte)OpCode.PUSH0) return false; ++i; break; diff --git a/src/neo/SmartContract/KeyBuilder.cs b/src/neo/SmartContract/KeyBuilder.cs index 3a723c48a3..378e0b71af 100644 --- a/src/neo/SmartContract/KeyBuilder.cs +++ b/src/neo/SmartContract/KeyBuilder.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -64,7 +64,7 @@ public KeyBuilder Add(ISerializable key) /// The type of the parameter. /// Part of the key. /// A reference to this instance after the add operation has completed. - unsafe public KeyBuilder Add(T key) where T : unmanaged + public unsafe KeyBuilder Add(T key) where T : unmanaged { return Add(new ReadOnlySpan(&key, sizeof(T))); } @@ -75,7 +75,7 @@ unsafe public KeyBuilder Add(T key) where T : unmanaged /// The type of the parameter. /// Part of the key. /// A reference to this instance after the add operation has completed. - unsafe public KeyBuilder AddBigEndian(T key) where T : unmanaged + public unsafe KeyBuilder AddBigEndian(T key) where T : unmanaged { ReadOnlySpan buffer = new(&key, sizeof(T)); for (int i = buffer.Length - 1; i >= 0; i--) diff --git a/src/neo/SmartContract/Manifest/ContractAbi.cs b/src/neo/SmartContract/Manifest/ContractAbi.cs index 278ac28cda..8eadbee946 100644 --- a/src/neo/SmartContract/Manifest/ContractAbi.cs +++ b/src/neo/SmartContract/Manifest/ContractAbi.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -76,17 +76,14 @@ public static ContractAbi FromJson(JObject json) /// The method that matches the specified name and number of parameters. If is set to -1, the first method with the specified name will be returned. public ContractMethodDescriptor GetMethod(string name, int pcount) { - if (pcount < -1 || pcount > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(pcount)); + if (pcount is < -1 or > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(pcount)); if (pcount >= 0) { methodDictionary ??= Methods.ToDictionary(p => (p.Name, p.Parameters.Length)); methodDictionary.TryGetValue((name, pcount), out var method); return method; } - else - { - return Methods.FirstOrDefault(p => p.Name == name); - } + return Methods.FirstOrDefault(p => p.Name == name); } /// @@ -95,10 +92,11 @@ public ContractMethodDescriptor GetMethod(string name, int pcount) /// The ABI represented by a JSON object. public JObject ToJson() { - var json = new JObject(); - json["methods"] = new JArray(Methods.Select(u => u.ToJson()).ToArray()); - json["events"] = new JArray(Events.Select(u => u.ToJson()).ToArray()); - return json; + return new JObject + { + ["methods"] = new JArray(Methods.Select(u => u.ToJson()).ToArray()), + ["events"] = new JArray(Events.Select(u => u.ToJson()).ToArray()) + }; } } } diff --git a/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs b/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs index eaf8123a70..3243bf3e94 100644 --- a/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs +++ b/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -71,10 +71,11 @@ public static ContractEventDescriptor FromJson(JObject json) /// The event represented by a JSON object. public virtual JObject ToJson() { - var json = new JObject(); - json["name"] = Name; - json["parameters"] = new JArray(Parameters.Select(u => u.ToJson()).ToArray()); - return json; + return new JObject + { + ["name"] = Name, + ["parameters"] = new JArray(Parameters.Select(u => u.ToJson()).ToArray()) + }; } } } diff --git a/src/neo/SmartContract/Manifest/ContractGroup.cs b/src/neo/SmartContract/Manifest/ContractGroup.cs index 22ab762d88..af01685e67 100644 --- a/src/neo/SmartContract/Manifest/ContractGroup.cs +++ b/src/neo/SmartContract/Manifest/ContractGroup.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -79,10 +79,11 @@ public bool IsValid(UInt160 hash) /// The group represented by a JSON object. public JObject ToJson() { - var json = new JObject(); - json["pubkey"] = PubKey.ToString(); - json["signature"] = Convert.ToBase64String(Signature); - return json; + return new JObject + { + ["pubkey"] = PubKey.ToString(), + ["signature"] = Convert.ToBase64String(Signature) + }; } } } diff --git a/src/neo/SmartContract/Manifest/ContractManifest.cs b/src/neo/SmartContract/Manifest/ContractManifest.cs index b440813330..de0df87650 100644 --- a/src/neo/SmartContract/Manifest/ContractManifest.cs +++ b/src/neo/SmartContract/Manifest/ContractManifest.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -111,10 +111,10 @@ public static ContractManifest FromJson(JObject json) ContractManifest manifest = new() { Name = json["name"].GetString(), - Groups = ((JArray)json["groups"]).Select(u => ContractGroup.FromJson(u)).ToArray(), + Groups = ((JArray)json["groups"]).Select(ContractGroup.FromJson).ToArray(), SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.GetString()).ToArray(), Abi = ContractAbi.FromJson(json["abi"]), - Permissions = ((JArray)json["permissions"]).Select(u => ContractPermission.FromJson(u)).ToArray(), + Permissions = ((JArray)json["permissions"]).Select(ContractPermission.FromJson).ToArray(), Trusts = WildcardContainer.FromJson(json["trusts"], u => ContractPermissionDescriptor.FromJson(u)), Extra = json["extra"] }; @@ -123,7 +123,7 @@ public static ContractManifest FromJson(JObject json) _ = manifest.Groups.ToDictionary(p => p.PubKey); if (json["features"].Properties.Count != 0) throw new FormatException(); - if (manifest.SupportedStandards.Any(p => string.IsNullOrEmpty(p))) + if (manifest.SupportedStandards.Any(string.IsNullOrEmpty)) throw new FormatException(); _ = manifest.SupportedStandards.ToDictionary(p => p); _ = manifest.Permissions.ToDictionary(p => p.Contract); diff --git a/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs b/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs index 15cda61b11..8a12e9e943 100644 --- a/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs +++ b/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -67,10 +67,11 @@ public static ContractParameterDefinition FromJson(JObject json) /// The parameter represented by a JSON object. public JObject ToJson() { - var json = new JObject(); - json["name"] = Name; - json["type"] = Type.ToString(); - return json; + return new JObject + { + ["name"] = Name, + ["type"] = Type.ToString() + }; } } } diff --git a/src/neo/SmartContract/Manifest/ContractPermission.cs b/src/neo/SmartContract/Manifest/ContractPermission.cs index 035e15beb3..f9d3ff8b9d 100644 --- a/src/neo/SmartContract/Manifest/ContractPermission.cs +++ b/src/neo/SmartContract/Manifest/ContractPermission.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -19,21 +19,26 @@ namespace Neo.SmartContract.Manifest { /// - /// Represents a permission of a contract. It describes which contracts may be invoked and which methods are called. - /// If a contract invokes a contract or method that is not declared in the manifest at runtime, the invocation will fail. + /// Represents a permission of a contract. It describes which contracts may be + /// invoked and which methods are called. + /// If a contract invokes a contract or method that is not declared in the manifest + /// at runtime, the invocation will fail. /// public class ContractPermission : IInteroperable { /// /// Indicates which contract to be invoked. /// It can be a hash of a contract, a public key of a group, or a wildcard *. - /// If it specifies a hash of a contract, then the contract will be invoked; If it specifies a public key of a group, then any contract in this group may be invoked; If it specifies a wildcard *, then any contract may be invoked. + /// If it specifies a hash of a contract, then the contract will be invoked; + /// If it specifies a public key of a group, then any contract in this group + /// may be invoked; If it specifies a wildcard *, then any contract may be invoked. /// public ContractPermissionDescriptor Contract { get; set; } /// /// Indicates which methods to be called. - /// It can also be assigned with a wildcard *. If it is a wildcard *, then it means that any method can be called. + /// It can also be assigned with a wildcard *. If it is a wildcard *, + /// then it means that any method can be called. /// public WildcardContainer Methods { get; set; } diff --git a/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs b/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs index 6a7e3b299e..af0ef517c9 100644 --- a/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs +++ b/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -107,7 +107,7 @@ public bool Equals(ContractPermissionDescriptor other) if (this == other) return true; if (IsWildcard == other.IsWildcard) return true; if (IsHash) return Hash.Equals(other.Hash); - else return Group.Equals(other.Group); + return Group.Equals(other.Group); } public override int GetHashCode() diff --git a/src/neo/SmartContract/Manifest/WildCardContainer.cs b/src/neo/SmartContract/Manifest/WildCardContainer.cs index 135afb5408..8517ffe1a8 100644 --- a/src/neo/SmartContract/Manifest/WildCardContainer.cs +++ b/src/neo/SmartContract/Manifest/WildCardContainer.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -65,7 +65,7 @@ public static WildcardContainer FromJson(JObject json, Func eleme if (str.Value != "*") throw new FormatException(); return CreateWildcard(); case JArray array: - return Create(array.Select(p => elementSelector(p)).ToArray()); + return Create(array.Select(elementSelector).ToArray()); default: throw new FormatException(); } @@ -87,7 +87,7 @@ public IEnumerator GetEnumerator() public JObject ToJson(Func elementSelector) { if (IsWildcard) return "*"; - return _data.Select(p => elementSelector(p)).ToArray(); + return _data.Select(elementSelector).ToArray(); } } } diff --git a/src/neo/Wallets/NEP6/NEP6Account.cs b/src/neo/Wallets/NEP6/NEP6Account.cs index 754d502764..7c0575a27d 100644 --- a/src/neo/Wallets/NEP6/NEP6Account.cs +++ b/src/neo/Wallets/NEP6/NEP6Account.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -53,11 +53,7 @@ public static NEP6Account FromJson(JObject json, NEP6Wallet wallet) public override KeyPair GetKey() { if (nep2key == null) return null; - if (key == null) - { - key = wallet.DecryptKey(nep2key); - } - return key; + return key ??= wallet.DecryptKey(nep2key); } public KeyPair GetKey(string password) diff --git a/src/neo/Wallets/NEP6/NEP6Contract.cs b/src/neo/Wallets/NEP6/NEP6Contract.cs index 8ef4470eaa..4803650b0f 100644 --- a/src/neo/Wallets/NEP6/NEP6Contract.cs +++ b/src/neo/Wallets/NEP6/NEP6Contract.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -34,17 +34,18 @@ public static NEP6Contract FromJson(JObject json) public JObject ToJson() { - JObject contract = new(); - contract["script"] = Convert.ToBase64String(Script); - contract["parameters"] = new JArray(ParameterList.Zip(ParameterNames, (type, name) => + return new JObject { - JObject parameter = new(); - parameter["name"] = name; - parameter["type"] = type; - return parameter; - })); - contract["deployed"] = Deployed; - return contract; + ["script"] = Convert.ToBase64String(Script), + ["parameters"] = new JArray(ParameterList.Zip(ParameterNames, (type, name) => + { + JObject parameter = new(); + parameter["name"] = name; + parameter["type"] = type; + return parameter; + })), + ["deployed"] = Deployed + }; } } } diff --git a/src/neo/Wallets/NEP6/NEP6Wallet.cs b/src/neo/Wallets/NEP6/NEP6Wallet.cs index e6d4c92fb4..487575251a 100644 --- a/src/neo/Wallets/NEP6/NEP6Wallet.cs +++ b/src/neo/Wallets/NEP6/NEP6Wallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -285,7 +285,7 @@ public override WalletAccount Import(string nep2, string passphrase, int N = 163 /// public JObject ToJson() { - return new() + return new JObject { ["name"] = name, ["version"] = version.ToString(), @@ -309,27 +309,20 @@ private bool VerifyPasswordInternal(string password) { lock (accounts) { - NEP6Account account = accounts.Values.FirstOrDefault(p => !p.Decrypted); - if (account == null) - { - account = accounts.Values.FirstOrDefault(p => p.HasKey); - } + NEP6Account account = accounts.Values.FirstOrDefault(p => !p.Decrypted) ?? accounts.Values.FirstOrDefault(p => p.HasKey); if (account == null) return true; if (account.Decrypted) { return account.VerifyPassword(password); } - else + try { - try - { - account.GetKey(password); - return true; - } - catch (FormatException) - { - return false; - } + account.GetKey(password); + return true; + } + catch (FormatException) + { + return false; } } } @@ -347,17 +340,18 @@ public override bool ChangePassword(string oldPassword, string newPassword) succeed = false; } }); - } - if (succeed) - { - foreach (NEP6Account account in accounts.Values) - account.ChangePasswordCommit(); - password = newPassword; - } - else - { - foreach (NEP6Account account in accounts.Values) - account.ChangePasswordRoolback(); + + if (succeed) + { + foreach (NEP6Account account in accounts.Values) + account.ChangePasswordCommit(); + password = newPassword; + } + else + { + foreach (NEP6Account account in accounts.Values) + account.ChangePasswordRoolback(); + } } return succeed; } diff --git a/src/neo/Wallets/NEP6/ScryptParameters.cs b/src/neo/Wallets/NEP6/ScryptParameters.cs index 15b6f08fc2..22d86b3f59 100644 --- a/src/neo/Wallets/NEP6/ScryptParameters.cs +++ b/src/neo/Wallets/NEP6/ScryptParameters.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -66,11 +66,12 @@ public static ScryptParameters FromJson(JObject json) /// The parameters represented by a JSON object. public JObject ToJson() { - JObject json = new(); - json["n"] = N; - json["r"] = R; - json["p"] = P; - return json; + return new JObject + { + ["n"] = N, + ["r"] = R, + ["p"] = P + }; } } } diff --git a/src/neo/Wallets/SQLite/UserWallet.cs b/src/neo/Wallets/SQLite/UserWallet.cs index 4da956a573..357e4e8cc6 100644 --- a/src/neo/Wallets/SQLite/UserWallet.cs +++ b/src/neo/Wallets/SQLite/UserWallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -104,10 +104,7 @@ private void AddAccount(UserWalletAccount account) { if (accounts.TryGetValue(account.ScriptHash, out UserWalletAccount account_old)) { - if (account.Contract == null) - { - account.Contract = account_old.Contract; - } + account.Contract ??= account_old.Contract; } accounts[account.ScriptHash] = account; } @@ -335,7 +332,7 @@ private byte[] LoadStoredData(string name) /// The password of the wallet. /// The to be used by the wallet. /// The opened wallet. - public static new UserWallet Open(string path, string password, ProtocolSettings settings) + public new static UserWallet Open(string path, string password, ProtocolSettings settings) { return new UserWallet(path, password.ToAesKey(), settings); } diff --git a/src/neo/Wallets/SQLite/VerificationContract.cs b/src/neo/Wallets/SQLite/VerificationContract.cs index d4d600440a..b816404429 100644 --- a/src/neo/Wallets/SQLite/VerificationContract.cs +++ b/src/neo/Wallets/SQLite/VerificationContract.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -36,8 +36,7 @@ public void Deserialize(ref MemoryReader reader) public bool Equals(VerificationContract other) { if (ReferenceEquals(this, other)) return true; - if (other is null) return false; - return ScriptHash.Equals(other.ScriptHash); + return other is not null && ScriptHash.Equals(other.ScriptHash); } public override bool Equals(object obj) diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index ff6babd738..edad02c949 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -249,7 +249,7 @@ public virtual WalletAccount GetDefaultAccount() foreach (WalletAccount account in GetAccounts()) { if (account.IsDefault) return account; - if (first == null) first = account; + first ??= account; } return first; } @@ -455,9 +455,9 @@ public virtual WalletAccount Import(string nep2, string passphrase, int N = 1638 /// The snapshot used to read data. /// The array of that contain the asset, amount, and targets of the transfer. /// The account to transfer from. - /// The cosigners to be added to the transction. + /// The cosigners to be added to the transaction. /// The block environment to execute the transaction. If null, will be used. - /// The created transction. + /// The created transaction. public Transaction MakeTransaction(DataCache snapshot, TransferOutput[] outputs, UInt160 from = null, Signer[] cosigners = null, Block persistingBlock = null) { UInt160[] accounts; @@ -518,8 +518,7 @@ public Transaction MakeTransaction(DataCache snapshot, TransferOutput[] outputs, } script = sb.ToArray(); } - if (balances_gas is null) - balances_gas = accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList(); + balances_gas ??= accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList(); return MakeTransaction(snapshot, script, cosignerList.Values.ToArray(), Array.Empty(), balances_gas, persistingBlock: persistingBlock); } @@ -530,11 +529,11 @@ public Transaction MakeTransaction(DataCache snapshot, TransferOutput[] outputs, /// The snapshot used to read data. /// The script to be loaded in the transaction. /// The sender of the transaction. - /// The cosigners to be added to the transction. - /// The attributes to be added to the transction. + /// The cosigners to be added to the transaction. + /// The attributes to be added to the transaction. /// The maximum gas that can be spent to execute the script. /// The block environment to execute the transaction. If null, will be used. - /// The created transction. + /// The created transaction. public Transaction MakeTransaction(DataCache snapshot, ReadOnlyMemory script, UInt160 sender = null, Signer[] cosigners = null, TransactionAttribute[] attributes = null, long maxGas = ApplicationEngine.TestModeGas, Block persistingBlock = null) { UInt160[] accounts; @@ -565,7 +564,7 @@ private Transaction MakeTransaction(DataCache snapshot, ReadOnlyMemory scr Attributes = attributes, }; - // will try to execute 'transfer' script to check if it works + // will try to execute 'transfer' script to check if it works using (ApplicationEngine engine = ApplicationEngine.Run(script, snapshot.CreateSnapshot(), tx, settings: ProtocolSettings, gas: maxGas, persistingBlock: persistingBlock)) { if (engine.State == VMState.FAULT) From ca63cc5b8fa08c7bbbf97aec0cae6aaead0a982d Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Mon, 4 Jul 2022 00:54:08 -0400 Subject: [PATCH 2/8] reverse some linq and comments --- src/neo/Cryptography/Base58.cs | 3 +-- src/neo/Helper.cs | 4 +++- src/neo/IO/ByteArrayEqualityComparer.cs | 5 ++++- src/neo/IO/Caching/HashSetCache.cs | 8 +++++++- src/neo/Network/P2P/Message.cs | 3 +-- 5 files changed, 16 insertions(+), 7 deletions(-) diff --git a/src/neo/Cryptography/Base58.cs b/src/neo/Cryptography/Base58.cs index f906f3403e..51d3c2edce 100644 --- a/src/neo/Cryptography/Base58.cs +++ b/src/neo/Cryptography/Base58.cs @@ -50,8 +50,7 @@ public static byte[] Base58CheckDecode(this string input) /// The encoded contains the checksum of the binary data. /// /// The byte array to convert. - /// The representation, - /// in base-58, of the contents of . + /// The representation, in base-58, of the contents of . public static string Base58CheckEncode(this ReadOnlySpan data) { byte[] checksum = data.Sha256().Sha256(); diff --git a/src/neo/Helper.cs b/src/neo/Helper.cs index a3497f8c2e..37db40eab0 100644 --- a/src/neo/Helper.cs +++ b/src/neo/Helper.cs @@ -54,7 +54,9 @@ private static int BitLen(int w) [MethodImpl(MethodImplOptions.AggressiveInlining)] public static byte[] Concat(params byte[][] buffers) { - int length = buffers.Sum(t => t.Length); + int length = 0; + for (int i = 0; i < buffers.Length; i++) + length += buffers[i].Length; byte[] dst = new byte[length]; int p = 0; foreach (byte[] src in buffers) diff --git a/src/neo/IO/ByteArrayEqualityComparer.cs b/src/neo/IO/ByteArrayEqualityComparer.cs index b31f5c82ab..166cbbe1ff 100644 --- a/src/neo/IO/ByteArrayEqualityComparer.cs +++ b/src/neo/IO/ByteArrayEqualityComparer.cs @@ -48,7 +48,10 @@ public int GetHashCode(byte[] obj) { unchecked { - return obj.Aggregate(17, (current, element) => current * 31 + element); + int hash = 17; + foreach (byte element in obj) + hash = hash * 31 + element; + return hash; } } } diff --git a/src/neo/IO/Caching/HashSetCache.cs b/src/neo/IO/Caching/HashSetCache.cs index 55083a9ce2..50b73a0855 100644 --- a/src/neo/IO/Caching/HashSetCache.cs +++ b/src/neo/IO/Caching/HashSetCache.cs @@ -103,7 +103,13 @@ public void ExceptWith(IEnumerable items) public IEnumerator GetEnumerator() { - return sets.SelectMany(set => set).GetEnumerator(); + foreach (var set in sets) + { + foreach (var item in set) + { + yield return item; + } + } } IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); diff --git a/src/neo/Network/P2P/Message.cs b/src/neo/Network/P2P/Message.cs index fa3f1b17ea..8bd50cc697 100644 --- a/src/neo/Network/P2P/Message.cs +++ b/src/neo/Network/P2P/Message.cs @@ -53,8 +53,7 @@ public class Message : ISerializable /// Creates a new instance of the class. /// /// The command of the message. - /// The payload of the message. - /// For the messages that don't require a payload, it should be . + /// The payload of the message. For the messages that don't require a payload, it should be . /// public static Message Create(MessageCommand command, ISerializable payload = null) { From b2ceda1551ca141be285f14f3b2c2171327635b4 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 4 Jul 2022 12:24:32 +0200 Subject: [PATCH 3/8] Update src/neo/IO/ByteArrayEqualityComparer.cs --- src/neo/IO/ByteArrayEqualityComparer.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/neo/IO/ByteArrayEqualityComparer.cs b/src/neo/IO/ByteArrayEqualityComparer.cs index 166cbbe1ff..8be43ce0c7 100644 --- a/src/neo/IO/ByteArrayEqualityComparer.cs +++ b/src/neo/IO/ByteArrayEqualityComparer.cs @@ -9,8 +9,6 @@ // modifications are permitted. using System.Collections.Generic; -using System.Linq; - namespace Neo.IO { internal class ByteArrayEqualityComparer : IEqualityComparer From d39a1c712f619620da1f035fe96c954a40f85306 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 4 Jul 2022 12:24:39 +0200 Subject: [PATCH 4/8] Update src/neo/IO/Caching/HashSetCache.cs --- src/neo/IO/Caching/HashSetCache.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/neo/IO/Caching/HashSetCache.cs b/src/neo/IO/Caching/HashSetCache.cs index 50b73a0855..e20892621f 100644 --- a/src/neo/IO/Caching/HashSetCache.cs +++ b/src/neo/IO/Caching/HashSetCache.cs @@ -11,8 +11,6 @@ using System; using System.Collections; using System.Collections.Generic; -using System.Linq; - namespace Neo.IO.Caching { class HashSetCache : IReadOnlyCollection where T : IEquatable From 32b5c82815bd826e410f33485c39b82ef7062928 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 4 Jul 2022 12:25:09 +0200 Subject: [PATCH 5/8] Update ByteArrayEqualityComparer.cs --- src/neo/IO/ByteArrayEqualityComparer.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/neo/IO/ByteArrayEqualityComparer.cs b/src/neo/IO/ByteArrayEqualityComparer.cs index 8be43ce0c7..d6121fc9fb 100644 --- a/src/neo/IO/ByteArrayEqualityComparer.cs +++ b/src/neo/IO/ByteArrayEqualityComparer.cs @@ -9,6 +9,7 @@ // modifications are permitted. using System.Collections.Generic; + namespace Neo.IO { internal class ByteArrayEqualityComparer : IEqualityComparer From a840ade3f72c15cc439513a7ca3f6932ad8d1020 Mon Sep 17 00:00:00 2001 From: Shargon Date: Mon, 4 Jul 2022 12:25:22 +0200 Subject: [PATCH 6/8] Update HashSetCache.cs --- src/neo/IO/Caching/HashSetCache.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/neo/IO/Caching/HashSetCache.cs b/src/neo/IO/Caching/HashSetCache.cs index e20892621f..ba15393787 100644 --- a/src/neo/IO/Caching/HashSetCache.cs +++ b/src/neo/IO/Caching/HashSetCache.cs @@ -11,6 +11,7 @@ using System; using System.Collections; using System.Collections.Generic; + namespace Neo.IO.Caching { class HashSetCache : IReadOnlyCollection where T : IEquatable From 3699c2244164f99c343c545d77cfb0c598350df3 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 9 Jul 2022 16:23:15 -0400 Subject: [PATCH 7/8] revert everything but typos and comments --- src/neo/BigDecimal.cs | 11 ++-- src/neo/Cryptography/Base58.cs | 8 +-- src/neo/Cryptography/BloomFilter.cs | 10 ++-- src/neo/Cryptography/ECC/ECFieldElement.cs | 12 ++-- src/neo/Cryptography/ECC/ECPoint.cs | 13 +++-- src/neo/Helper.cs | 10 ++-- src/neo/IO/Actors/PriorityMailbox.cs | 12 ++-- src/neo/IO/Caching/IndexedQueue.cs | 8 +-- src/neo/IO/Caching/OrderedDictionary.cs | 21 +++++-- src/neo/IO/Helper.cs | 13 +++-- src/neo/IO/Json/JArray.cs | 34 ++++++++--- src/neo/IO/Json/JObject.cs | 20 +++++-- src/neo/Ledger/Blockchain.cs | 12 ++-- src/neo/Ledger/MemoryPool.cs | 8 +-- src/neo/Ledger/PoolItem.cs | 11 ++-- src/neo/NeoSystem.cs | 11 ++-- src/neo/Network/P2P/LocalNode.cs | 8 +-- src/neo/Network/P2P/Message.cs | 8 +-- .../P2P/Payloads/GetBlockByIndexPayload.cs | 10 ++-- src/neo/Network/P2P/Payloads/Header.cs | 8 +-- src/neo/Network/P2P/Payloads/PingPayload.cs | 8 +-- src/neo/Network/P2P/Payloads/Signer.cs | 8 +-- src/neo/Network/P2P/Payloads/Transaction.cs | 11 ++-- src/neo/Network/P2P/Payloads/Witness.cs | 17 +++--- .../Network/P2P/RemoteNode.ProtocolHandler.cs | 15 +++-- src/neo/Network/P2P/RemoteNode.cs | 10 ++-- src/neo/Network/P2P/TaskManager.cs | 37 ++++++------ src/neo/Persistence/ClonedCache.cs | 12 ++-- src/neo/Persistence/DataCache.cs | 20 +++---- src/neo/Plugins/Plugin.cs | 8 +-- .../ApplicationEngine.Iterator.cs | 8 +-- .../ApplicationEngine.Storage.cs | 10 ++-- src/neo/SmartContract/ContractParameter.cs | 38 ++++++------- .../ContractParametersContext.cs | 8 +-- src/neo/SmartContract/Helper.cs | 12 ++-- src/neo/SmartContract/KeyBuilder.cs | 12 ++-- src/neo/SmartContract/Manifest/ContractAbi.cs | 15 +++-- .../Manifest/ContractEventDescriptor.cs | 17 +++--- .../SmartContract/Manifest/ContractGroup.cs | 17 +++--- .../Manifest/ContractManifest.cs | 14 ++--- .../Manifest/ContractParameterDefinition.cs | 17 +++--- .../Manifest/ContractPermission.cs | 8 +-- .../Manifest/ContractPermissionDescriptor.cs | 10 ++-- .../Manifest/WildCardContainer.cs | 10 ++-- src/neo/Wallets/NEP6/NEP6Account.cs | 14 +++-- src/neo/Wallets/NEP6/NEP6Contract.cs | 29 +++++----- src/neo/Wallets/NEP6/NEP6Wallet.cs | 56 ++++++++++--------- src/neo/Wallets/NEP6/ScryptParameters.cs | 19 +++---- src/neo/Wallets/SQLite/UserWallet.cs | 15 +++-- .../Wallets/SQLite/VerificationContract.cs | 11 ++-- src/neo/Wallets/Wallet.cs | 10 ++-- 51 files changed, 399 insertions(+), 345 deletions(-) diff --git a/src/neo/BigDecimal.cs b/src/neo/BigDecimal.cs index 2e807e4672..f9c6e0ffb1 100644 --- a/src/neo/BigDecimal.cs +++ b/src/neo/BigDecimal.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -193,7 +193,8 @@ public int CompareTo(BigDecimal other) public override bool Equals(object obj) { - return obj is BigDecimal @decimal && Equals(@decimal); + if (obj is not BigDecimal @decimal) return false; + return Equals(@decimal); } public bool Equals(BigDecimal other) diff --git a/src/neo/Cryptography/Base58.cs b/src/neo/Cryptography/Base58.cs index 51d3c2edce..7d52704a95 100644 --- a/src/neo/Cryptography/Base58.cs +++ b/src/neo/Cryptography/Base58.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Cryptography/BloomFilter.cs b/src/neo/Cryptography/BloomFilter.cs index 1b1517c672..49e7aee983 100644 --- a/src/neo/Cryptography/BloomFilter.cs +++ b/src/neo/Cryptography/BloomFilter.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -85,7 +85,7 @@ public void Add(ReadOnlyMemory element) /// if is found in the ; otherwise, . public bool Check(byte[] element) { - foreach (uint i in seeds.AsParallel().Select(element.Murmur32)) + foreach (uint i in seeds.AsParallel().Select(s => element.Murmur32(s))) if (!bits.Get((int)(i % (uint)bits.Length))) return false; return true; diff --git a/src/neo/Cryptography/ECC/ECFieldElement.cs b/src/neo/Cryptography/ECC/ECFieldElement.cs index 907aaff276..d138666b3f 100644 --- a/src/neo/Cryptography/ECC/ECFieldElement.cs +++ b/src/neo/Cryptography/ECC/ECFieldElement.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,8 +40,10 @@ public override bool Equals(object obj) if (obj == this) return true; - return obj is ECFieldElement other && Equals(other); + if (obj is not ECFieldElement other) + return false; + return Equals(other); } public bool Equals(ECFieldElement other) diff --git a/src/neo/Cryptography/ECC/ECPoint.cs b/src/neo/Cryptography/ECC/ECPoint.cs index 9919d514c1..d49a0641da 100644 --- a/src/neo/Cryptography/ECC/ECPoint.cs +++ b/src/neo/Cryptography/ECC/ECPoint.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -29,7 +29,10 @@ public class ECPoint : IComparable, IEquatable, ISerializable /// /// Indicates whether it is a point at infinity. /// - public bool IsInfinity => X == null && Y == null; + public bool IsInfinity + { + get { return X == null && Y == null; } + } public int Size => IsInfinity ? 1 : 33; diff --git a/src/neo/Helper.cs b/src/neo/Helper.cs index 37db40eab0..c81e34bf41 100644 --- a/src/neo/Helper.cs +++ b/src/neo/Helper.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -146,7 +146,7 @@ internal static string GetVersion(this Assembly assembly) /// The converted byte array. public static byte[] HexToBytes(this string value) { - if (string.IsNullOrEmpty(value)) + if (value == null || value.Length == 0) return Array.Empty(); if (value.Length % 2 == 1) throw new FormatException(); diff --git a/src/neo/IO/Actors/PriorityMailbox.cs b/src/neo/IO/Actors/PriorityMailbox.cs index 1a6d3a6ec5..6dc8f0b429 100644 --- a/src/neo/IO/Actors/PriorityMailbox.cs +++ b/src/neo/IO/Actors/PriorityMailbox.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -28,7 +28,7 @@ public override IMessageQueue Create(IActorRef owner, ActorSystem system) return new PriorityMessageQueue(ShallDrop, IsHighPriority); } - protected internal virtual bool IsHighPriority(object message) => false; - protected internal virtual bool ShallDrop(object message, IEnumerable queue) => false; + internal protected virtual bool IsHighPriority(object message) => false; + internal protected virtual bool ShallDrop(object message, IEnumerable queue) => false; } } diff --git a/src/neo/IO/Caching/IndexedQueue.cs b/src/neo/IO/Caching/IndexedQueue.cs index 2cb043574e..40fc8e6a89 100644 --- a/src/neo/IO/Caching/IndexedQueue.cs +++ b/src/neo/IO/Caching/IndexedQueue.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/IO/Caching/OrderedDictionary.cs b/src/neo/IO/Caching/OrderedDictionary.cs index 53c7d43d4e..7f384d1380 100644 --- a/src/neo/IO/Caching/OrderedDictionary.cs +++ b/src/neo/IO/Caching/OrderedDictionary.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,7 +40,10 @@ protected override TKey GetKeyForItem(TItem item) public TValue this[TKey key] { - get => collection[key].Value; + get + { + return collection[key].Value; + } set { if (collection.TryGetValue(key, out var entry)) @@ -50,7 +53,13 @@ public TValue this[TKey key] } } - public TValue this[int index] => collection[index].Value; + public TValue this[int index] + { + get + { + return collection[index].Value; + } + } public void Add(TKey key, TValue value) { diff --git a/src/neo/IO/Helper.cs b/src/neo/IO/Helper.cs index 8f52d768c2..adaf127081 100644 --- a/src/neo/IO/Helper.cs +++ b/src/neo/IO/Helper.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -132,9 +132,10 @@ public static int GetVarSize(int value) { if (value < 0xFD) return sizeof(byte); - if (value <= 0xFFFF) + else if (value <= 0xFFFF) return sizeof(byte) + sizeof(ushort); - return sizeof(byte) + sizeof(uint); + else + return sizeof(byte) + sizeof(uint); } /// diff --git a/src/neo/IO/Json/JArray.cs b/src/neo/IO/Json/JArray.cs index 238c2c282c..eee381eda4 100644 --- a/src/neo/IO/Json/JArray.cs +++ b/src/neo/IO/Json/JArray.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -41,13 +41,31 @@ public JArray(IEnumerable items) public override JObject this[int index] { - get => items[index]; - set => items[index] = value; + get + { + return items[index]; + } + set + { + items[index] = value; + } } - public int Count => items.Count; + public int Count + { + get + { + return items.Count; + } + } - public bool IsReadOnly => false; + public bool IsReadOnly + { + get + { + return false; + } + } public void Add(JObject item) { diff --git a/src/neo/IO/Json/JObject.cs b/src/neo/IO/Json/JObject.cs index 30895cf2c8..678c1d85db 100644 --- a/src/neo/IO/Json/JObject.cs +++ b/src/neo/IO/Json/JObject.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -40,8 +40,16 @@ public class JObject /// The property with the specified name. public JObject this[string name] { - get => Properties.TryGetValue(name, out JObject value) ? value : null; - set => Properties[name] = value; + get + { + if (Properties.TryGetValue(name, out JObject value)) + return value; + return null; + } + set + { + Properties[name] = value; + } } /// diff --git a/src/neo/Ledger/Blockchain.cs b/src/neo/Ledger/Blockchain.cs index 45aba850a9..52b3c37ce5 100644 --- a/src/neo/Ledger/Blockchain.cs +++ b/src/neo/Ledger/Blockchain.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -119,7 +119,7 @@ internal class Initialize { } public static event CommittingHandler Committing; public static event CommittedHandler Committed; - private static readonly Script onPersistScript, postPersistScript; + private readonly static Script onPersistScript, postPersistScript; private const int MaxTxToReverifyPerIdle = 10; private readonly NeoSystem system; private readonly Dictionary block_cache = new(); @@ -496,7 +496,7 @@ public BlockchainMailbox(Settings settings, Config config) { } - protected internal override bool IsHighPriority(object message) + internal protected override bool IsHighPriority(object message) { return message switch { diff --git a/src/neo/Ledger/MemoryPool.cs b/src/neo/Ledger/MemoryPool.cs index 2f64b90786..6ade372ee1 100644 --- a/src/neo/Ledger/MemoryPool.cs +++ b/src/neo/Ledger/MemoryPool.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Ledger/PoolItem.cs b/src/neo/Ledger/PoolItem.cs index fde291014c..37dfb906c5 100644 --- a/src/neo/Ledger/PoolItem.cs +++ b/src/neo/Ledger/PoolItem.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -59,7 +59,8 @@ public int CompareTo(Transaction otherTx) public int CompareTo(PoolItem otherItem) { - return otherItem == null ? 1 : CompareTo(otherItem.Tx); + if (otherItem == null) return 1; + return CompareTo(otherItem.Tx); } } } diff --git a/src/neo/NeoSystem.cs b/src/neo/NeoSystem.cs index 334da2f4db..1007e0f40d 100644 --- a/src/neo/NeoSystem.cs +++ b/src/neo/NeoSystem.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -274,7 +274,8 @@ public SnapshotCache GetSnapshot() /// if the transaction exists; otherwise, . public bool ContainsTransaction(UInt256 hash) { - return MemPool.ContainsKey(hash) || NativeContract.Ledger.ContainsTransaction(StoreView, hash); + if (MemPool.ContainsKey(hash)) return true; + return NativeContract.Ledger.ContainsTransaction(StoreView, hash); } } } diff --git a/src/neo/Network/P2P/LocalNode.cs b/src/neo/Network/P2P/LocalNode.cs index d023de61dd..6dbbf31d88 100644 --- a/src/neo/Network/P2P/LocalNode.cs +++ b/src/neo/Network/P2P/LocalNode.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Network/P2P/Message.cs b/src/neo/Network/P2P/Message.cs index 8bd50cc697..00242c5fec 100644 --- a/src/neo/Network/P2P/Message.cs +++ b/src/neo/Network/P2P/Message.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs b/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs index e332e55abf..115bc14c3d 100644 --- a/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs +++ b/src/neo/Network/P2P/Payloads/GetBlockByIndexPayload.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -50,7 +50,7 @@ void ISerializable.Deserialize(ref MemoryReader reader) { IndexStart = reader.ReadUInt32(); Count = reader.ReadInt16(); - if (Count is < -1 or 0 or > HeadersPayload.MaxHeadersCount) + if (Count < -1 || Count == 0 || Count > HeadersPayload.MaxHeadersCount) throw new FormatException(); } diff --git a/src/neo/Network/P2P/Payloads/Header.cs b/src/neo/Network/P2P/Payloads/Header.cs index a5888f6838..b973321c2d 100644 --- a/src/neo/Network/P2P/Payloads/Header.cs +++ b/src/neo/Network/P2P/Payloads/Header.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Network/P2P/Payloads/PingPayload.cs b/src/neo/Network/P2P/Payloads/PingPayload.cs index 3234895288..d744702c3a 100644 --- a/src/neo/Network/P2P/Payloads/PingPayload.cs +++ b/src/neo/Network/P2P/Payloads/PingPayload.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Network/P2P/Payloads/Signer.cs b/src/neo/Network/P2P/Payloads/Signer.cs index ab5de4187e..e6a2ce0a78 100644 --- a/src/neo/Network/P2P/Payloads/Signer.cs +++ b/src/neo/Network/P2P/Payloads/Signer.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/Network/P2P/Payloads/Transaction.cs b/src/neo/Network/P2P/Payloads/Transaction.cs index efe60a0fc5..82900545c1 100644 --- a/src/neo/Network/P2P/Payloads/Transaction.cs +++ b/src/neo/Network/P2P/Payloads/Transaction.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -244,7 +244,8 @@ public void DeserializeUnsigned(ref MemoryReader reader) public bool Equals(Transaction other) { if (other is null) return false; - return ReferenceEquals(this, other) || Hash.Equals(other.Hash); + if (ReferenceEquals(this, other)) return true; + return Hash.Equals(other.Hash); } public override bool Equals(object obj) diff --git a/src/neo/Network/P2P/Payloads/Witness.cs b/src/neo/Network/P2P/Payloads/Witness.cs index f3f7b12b02..113487cd6c 100644 --- a/src/neo/Network/P2P/Payloads/Witness.cs +++ b/src/neo/Network/P2P/Payloads/Witness.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -74,11 +74,10 @@ void ISerializable.Serialize(BinaryWriter writer) /// The witness represented by a JSON object. public JObject ToJson() { - return new JObject - { - ["invocation"] = Convert.ToBase64String(InvocationScript.Span), - ["verification"] = Convert.ToBase64String(VerificationScript.Span) - }; + JObject json = new(); + json["invocation"] = Convert.ToBase64String(InvocationScript.Span); + json["verification"] = Convert.ToBase64String(VerificationScript.Span); + return json; } } } diff --git a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs index d0999d8d3d..ad6350a777 100644 --- a/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs +++ b/src/neo/Network/P2P/RemoteNode.ProtocolHandler.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -56,10 +56,9 @@ public static event MessageReceivedHandler MessageReceived private void OnMessage(Message msg) { - if (handlers.Any(handler => !handler(system, msg))) - { - return; - } + foreach (MessageReceivedHandler handler in handlers) + if (!handler(system, msg)) + return; if (Version == null) { if (msg.Command != MessageCommand.Version) diff --git a/src/neo/Network/P2P/RemoteNode.cs b/src/neo/Network/P2P/RemoteNode.cs index 2a066fe09c..84dd11f922 100644 --- a/src/neo/Network/P2P/RemoteNode.cs +++ b/src/neo/Network/P2P/RemoteNode.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -246,7 +246,7 @@ internal class RemoteNodeMailbox : PriorityMailbox { public RemoteNodeMailbox(Settings settings, Config config) : base(settings, config) { } - protected internal override bool IsHighPriority(object message) + internal protected override bool IsHighPriority(object message) { return message switch { diff --git a/src/neo/Network/P2P/TaskManager.cs b/src/neo/Network/P2P/TaskManager.cs index bf5eaed719..ace01b16f9 100644 --- a/src/neo/Network/P2P/TaskManager.cs +++ b/src/neo/Network/P2P/TaskManager.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -231,6 +231,7 @@ private void OnTaskCompleted(IInventory inventory) if (block.Hash != block_old.Hash) { Sender.Tell(Tcp.Abort.Instance); + return; } } else @@ -248,21 +249,25 @@ private void OnTaskCompleted(IInventory inventory) [MethodImpl(MethodImplOptions.AggressiveInlining)] private void DecrementGlobalTask(UInt256 hash) { - if (!globalInvTasks.TryGetValue(hash, out var value)) return; - if (value == 1) - globalInvTasks.Remove(hash); - else - globalInvTasks[hash] = value - 1; + if (globalInvTasks.TryGetValue(hash, out var value)) + { + if (value == 1) + globalInvTasks.Remove(hash); + else + globalInvTasks[hash] = value - 1; + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] private void DecrementGlobalTask(uint index) { - if (!globalIndexTasks.TryGetValue(index, out var value)) return; - if (value == 1) - globalIndexTasks.Remove(index); - else - globalIndexTasks[index] = value - 1; + if (globalIndexTasks.TryGetValue(index, out var value)) + { + if (value == 1) + globalIndexTasks.Remove(index); + else + globalIndexTasks[index] = value - 1; + } } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -413,7 +418,7 @@ public TaskManagerMailbox(Akka.Actor.Settings settings, Config config) { } - protected internal override bool IsHighPriority(object message) + internal protected override bool IsHighPriority(object message) { switch (message) { @@ -430,7 +435,7 @@ protected internal override bool IsHighPriority(object message) } } - protected internal override bool ShallDrop(object message, IEnumerable queue) + internal protected override bool ShallDrop(object message, IEnumerable queue) { if (message is not TaskManager.NewTasks tasks) return false; // Remove duplicate tasks diff --git a/src/neo/Persistence/ClonedCache.cs b/src/neo/Persistence/ClonedCache.cs index 72a308e55a..ed25a957e4 100644 --- a/src/neo/Persistence/ClonedCache.cs +++ b/src/neo/Persistence/ClonedCache.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -42,9 +42,9 @@ protected override StorageItem GetInternal(StorageKey key) return innerCache[key].Clone(); } - protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPrefix, SeekDirection direction) + protected override IEnumerable<(StorageKey, StorageItem)> SeekInternal(byte[] keyOrPreifx, SeekDirection direction) { - foreach (var (key, value) in innerCache.Seek(keyOrPrefix, direction)) + foreach (var (key, value) in innerCache.Seek(keyOrPreifx, direction)) yield return (key, value.Clone()); } diff --git a/src/neo/Persistence/DataCache.cs b/src/neo/Persistence/DataCache.cs index 04a4f261dc..b387b2cde3 100644 --- a/src/neo/Persistence/DataCache.cs +++ b/src/neo/Persistence/DataCache.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -125,7 +125,6 @@ public virtual void Commit() { LinkedList deletedItem = new(); foreach (Trackable trackable in GetChangeSet()) - { switch (trackable.State) { case TrackState.Added: @@ -141,16 +140,11 @@ public virtual void Commit() deletedItem.AddFirst(trackable.Key); break; } - } - lock (dictionary) + foreach (StorageKey key in deletedItem) { - foreach (StorageKey key in deletedItem) - { - dictionary.Remove(key); - } - changeSet.Clear(); + dictionary.Remove(key); } - + changeSet.Clear(); } /// diff --git a/src/neo/Plugins/Plugin.cs b/src/neo/Plugins/Plugin.cs index 2aee3cb0b8..fa8818d8ec 100644 --- a/src/neo/Plugins/Plugin.cs +++ b/src/neo/Plugins/Plugin.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/SmartContract/ApplicationEngine.Iterator.cs b/src/neo/SmartContract/ApplicationEngine.Iterator.cs index 66ca698e1f..6b1ccb2762 100644 --- a/src/neo/SmartContract/ApplicationEngine.Iterator.cs +++ b/src/neo/SmartContract/ApplicationEngine.Iterator.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/SmartContract/ApplicationEngine.Storage.cs b/src/neo/SmartContract/ApplicationEngine.Storage.cs index d597a3e97f..1ae615ce54 100644 --- a/src/neo/SmartContract/ApplicationEngine.Storage.cs +++ b/src/neo/SmartContract/ApplicationEngine.Storage.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -104,7 +104,7 @@ protected internal StorageContext GetReadOnlyContext() /// /// The storage context to convert. /// The readonly storage context. - protected internal static StorageContext AsReadOnly(StorageContext context) + internal protected static StorageContext AsReadOnly(StorageContext context) { if (!context.IsReadOnly) context = new StorageContext diff --git a/src/neo/SmartContract/ContractParameter.cs b/src/neo/SmartContract/ContractParameter.cs index 66bcade4f7..0c4a79f518 100644 --- a/src/neo/SmartContract/ContractParameter.cs +++ b/src/neo/SmartContract/ContractParameter.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -192,7 +192,6 @@ public override string ToString() private static string ToString(ContractParameter parameter, HashSet context) { - StringBuilder sb; switch (parameter.Value) { case null: @@ -200,25 +199,26 @@ private static string ToString(ContractParameter parameter, HashSet data: - context ??= new HashSet(); + if (context is null) context = new HashSet(); if (context.Contains(parameter)) { return "(array)"; } - - context.Add(parameter); - sb = new StringBuilder(); - sb.Append('['); - foreach (ContractParameter item in data) + else { - sb.Append(ToString(item, context)); - sb.Append(", "); + context.Add(parameter); + StringBuilder sb = new(); + sb.Append('['); + foreach (ContractParameter item in data) + { + sb.Append(ToString(item, context)); + sb.Append(", "); + } + if (data.Count > 0) + sb.Length -= 2; + sb.Append(']'); + return sb.ToString(); } - if (data.Count > 0) - sb.Length -= 2; - sb.Append(']'); - return sb.ToString(); - case IList> data: if (context is null) context = new HashSet(); if (context.Contains(parameter)) @@ -228,7 +228,7 @@ private static string ToString(ContractParameter parameter, HashSet script, out int m, out m = BinaryPrimitives.ReadUInt16LittleEndian(script[++i..]); i += 2; break; - case byte b and >= (byte)OpCode.PUSH1 and <= (byte)OpCode.PUSH16: + case byte b when b >= (byte)OpCode.PUSH1 && b <= (byte)OpCode.PUSH16: m = b - (byte)OpCode.PUSH0; ++i; break; @@ -198,7 +198,7 @@ private static bool IsMultiSigContract(ReadOnlySpan script, out int m, out if (script.Length < i + 3 || n != BinaryPrimitives.ReadUInt16LittleEndian(script[++i..])) return false; i += 2; break; - case byte b and >= (byte)OpCode.PUSH1 and <= (byte)OpCode.PUSH16: + case byte b when b >= (byte)OpCode.PUSH1 && b <= (byte)OpCode.PUSH16: if (n != b - (byte)OpCode.PUSH0) return false; ++i; break; diff --git a/src/neo/SmartContract/KeyBuilder.cs b/src/neo/SmartContract/KeyBuilder.cs index 378e0b71af..3a723c48a3 100644 --- a/src/neo/SmartContract/KeyBuilder.cs +++ b/src/neo/SmartContract/KeyBuilder.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -64,7 +64,7 @@ public KeyBuilder Add(ISerializable key) /// The type of the parameter. /// Part of the key. /// A reference to this instance after the add operation has completed. - public unsafe KeyBuilder Add(T key) where T : unmanaged + unsafe public KeyBuilder Add(T key) where T : unmanaged { return Add(new ReadOnlySpan(&key, sizeof(T))); } @@ -75,7 +75,7 @@ public unsafe KeyBuilder Add(T key) where T : unmanaged /// The type of the parameter. /// Part of the key. /// A reference to this instance after the add operation has completed. - public unsafe KeyBuilder AddBigEndian(T key) where T : unmanaged + unsafe public KeyBuilder AddBigEndian(T key) where T : unmanaged { ReadOnlySpan buffer = new(&key, sizeof(T)); for (int i = buffer.Length - 1; i >= 0; i--) diff --git a/src/neo/SmartContract/Manifest/ContractAbi.cs b/src/neo/SmartContract/Manifest/ContractAbi.cs index 8eadbee946..5345a6042e 100644 --- a/src/neo/SmartContract/Manifest/ContractAbi.cs +++ b/src/neo/SmartContract/Manifest/ContractAbi.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -76,14 +76,17 @@ public static ContractAbi FromJson(JObject json) /// The method that matches the specified name and number of parameters. If is set to -1, the first method with the specified name will be returned. public ContractMethodDescriptor GetMethod(string name, int pcount) { - if (pcount is < -1 or > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(pcount)); + if (pcount < -1 || pcount > ushort.MaxValue) throw new ArgumentOutOfRangeException(nameof(pcount)); if (pcount >= 0) { methodDictionary ??= Methods.ToDictionary(p => (p.Name, p.Parameters.Length)); methodDictionary.TryGetValue((name, pcount), out var method); return method; } - return Methods.FirstOrDefault(p => p.Name == name); + else + { + return Methods.FirstOrDefault(p => p.Name == name); + } } /// diff --git a/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs b/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs index 3243bf3e94..eaf8123a70 100644 --- a/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs +++ b/src/neo/SmartContract/Manifest/ContractEventDescriptor.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -71,11 +71,10 @@ public static ContractEventDescriptor FromJson(JObject json) /// The event represented by a JSON object. public virtual JObject ToJson() { - return new JObject - { - ["name"] = Name, - ["parameters"] = new JArray(Parameters.Select(u => u.ToJson()).ToArray()) - }; + var json = new JObject(); + json["name"] = Name; + json["parameters"] = new JArray(Parameters.Select(u => u.ToJson()).ToArray()); + return json; } } } diff --git a/src/neo/SmartContract/Manifest/ContractGroup.cs b/src/neo/SmartContract/Manifest/ContractGroup.cs index af01685e67..22ab762d88 100644 --- a/src/neo/SmartContract/Manifest/ContractGroup.cs +++ b/src/neo/SmartContract/Manifest/ContractGroup.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -79,11 +79,10 @@ public bool IsValid(UInt160 hash) /// The group represented by a JSON object. public JObject ToJson() { - return new JObject - { - ["pubkey"] = PubKey.ToString(), - ["signature"] = Convert.ToBase64String(Signature) - }; + var json = new JObject(); + json["pubkey"] = PubKey.ToString(); + json["signature"] = Convert.ToBase64String(Signature); + return json; } } } diff --git a/src/neo/SmartContract/Manifest/ContractManifest.cs b/src/neo/SmartContract/Manifest/ContractManifest.cs index de0df87650..b440813330 100644 --- a/src/neo/SmartContract/Manifest/ContractManifest.cs +++ b/src/neo/SmartContract/Manifest/ContractManifest.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -111,10 +111,10 @@ public static ContractManifest FromJson(JObject json) ContractManifest manifest = new() { Name = json["name"].GetString(), - Groups = ((JArray)json["groups"]).Select(ContractGroup.FromJson).ToArray(), + Groups = ((JArray)json["groups"]).Select(u => ContractGroup.FromJson(u)).ToArray(), SupportedStandards = ((JArray)json["supportedstandards"]).Select(u => u.GetString()).ToArray(), Abi = ContractAbi.FromJson(json["abi"]), - Permissions = ((JArray)json["permissions"]).Select(ContractPermission.FromJson).ToArray(), + Permissions = ((JArray)json["permissions"]).Select(u => ContractPermission.FromJson(u)).ToArray(), Trusts = WildcardContainer.FromJson(json["trusts"], u => ContractPermissionDescriptor.FromJson(u)), Extra = json["extra"] }; @@ -123,7 +123,7 @@ public static ContractManifest FromJson(JObject json) _ = manifest.Groups.ToDictionary(p => p.PubKey); if (json["features"].Properties.Count != 0) throw new FormatException(); - if (manifest.SupportedStandards.Any(string.IsNullOrEmpty)) + if (manifest.SupportedStandards.Any(p => string.IsNullOrEmpty(p))) throw new FormatException(); _ = manifest.SupportedStandards.ToDictionary(p => p); _ = manifest.Permissions.ToDictionary(p => p.Contract); diff --git a/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs b/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs index 8a12e9e943..15cda61b11 100644 --- a/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs +++ b/src/neo/SmartContract/Manifest/ContractParameterDefinition.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -67,11 +67,10 @@ public static ContractParameterDefinition FromJson(JObject json) /// The parameter represented by a JSON object. public JObject ToJson() { - return new JObject - { - ["name"] = Name, - ["type"] = Type.ToString() - }; + var json = new JObject(); + json["name"] = Name; + json["type"] = Type.ToString(); + return json; } } } diff --git a/src/neo/SmartContract/Manifest/ContractPermission.cs b/src/neo/SmartContract/Manifest/ContractPermission.cs index f9d3ff8b9d..c0aa1b2eaf 100644 --- a/src/neo/SmartContract/Manifest/ContractPermission.cs +++ b/src/neo/SmartContract/Manifest/ContractPermission.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. diff --git a/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs b/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs index af0ef517c9..6a7e3b299e 100644 --- a/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs +++ b/src/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -107,7 +107,7 @@ public bool Equals(ContractPermissionDescriptor other) if (this == other) return true; if (IsWildcard == other.IsWildcard) return true; if (IsHash) return Hash.Equals(other.Hash); - return Group.Equals(other.Group); + else return Group.Equals(other.Group); } public override int GetHashCode() diff --git a/src/neo/SmartContract/Manifest/WildCardContainer.cs b/src/neo/SmartContract/Manifest/WildCardContainer.cs index 8517ffe1a8..19e60f91a0 100644 --- a/src/neo/SmartContract/Manifest/WildCardContainer.cs +++ b/src/neo/SmartContract/Manifest/WildCardContainer.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -65,7 +65,7 @@ public static WildcardContainer FromJson(JObject json, Func eleme if (str.Value != "*") throw new FormatException(); return CreateWildcard(); case JArray array: - return Create(array.Select(elementSelector).ToArray()); + return Create(array.Select(p => elementSelector(p)).ToArray()); default: throw new FormatException(); } diff --git a/src/neo/Wallets/NEP6/NEP6Account.cs b/src/neo/Wallets/NEP6/NEP6Account.cs index 7c0575a27d..754d502764 100644 --- a/src/neo/Wallets/NEP6/NEP6Account.cs +++ b/src/neo/Wallets/NEP6/NEP6Account.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -53,7 +53,11 @@ public static NEP6Account FromJson(JObject json, NEP6Wallet wallet) public override KeyPair GetKey() { if (nep2key == null) return null; - return key ??= wallet.DecryptKey(nep2key); + if (key == null) + { + key = wallet.DecryptKey(nep2key); + } + return key; } public KeyPair GetKey(string password) diff --git a/src/neo/Wallets/NEP6/NEP6Contract.cs b/src/neo/Wallets/NEP6/NEP6Contract.cs index 4803650b0f..8ef4470eaa 100644 --- a/src/neo/Wallets/NEP6/NEP6Contract.cs +++ b/src/neo/Wallets/NEP6/NEP6Contract.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -34,18 +34,17 @@ public static NEP6Contract FromJson(JObject json) public JObject ToJson() { - return new JObject + JObject contract = new(); + contract["script"] = Convert.ToBase64String(Script); + contract["parameters"] = new JArray(ParameterList.Zip(ParameterNames, (type, name) => { - ["script"] = Convert.ToBase64String(Script), - ["parameters"] = new JArray(ParameterList.Zip(ParameterNames, (type, name) => - { - JObject parameter = new(); - parameter["name"] = name; - parameter["type"] = type; - return parameter; - })), - ["deployed"] = Deployed - }; + JObject parameter = new(); + parameter["name"] = name; + parameter["type"] = type; + return parameter; + })); + contract["deployed"] = Deployed; + return contract; } } } diff --git a/src/neo/Wallets/NEP6/NEP6Wallet.cs b/src/neo/Wallets/NEP6/NEP6Wallet.cs index 487575251a..e6d4c92fb4 100644 --- a/src/neo/Wallets/NEP6/NEP6Wallet.cs +++ b/src/neo/Wallets/NEP6/NEP6Wallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -285,7 +285,7 @@ public override WalletAccount Import(string nep2, string passphrase, int N = 163 /// public JObject ToJson() { - return new JObject + return new() { ["name"] = name, ["version"] = version.ToString(), @@ -309,20 +309,27 @@ private bool VerifyPasswordInternal(string password) { lock (accounts) { - NEP6Account account = accounts.Values.FirstOrDefault(p => !p.Decrypted) ?? accounts.Values.FirstOrDefault(p => p.HasKey); + NEP6Account account = accounts.Values.FirstOrDefault(p => !p.Decrypted); + if (account == null) + { + account = accounts.Values.FirstOrDefault(p => p.HasKey); + } if (account == null) return true; if (account.Decrypted) { return account.VerifyPassword(password); } - try - { - account.GetKey(password); - return true; - } - catch (FormatException) + else { - return false; + try + { + account.GetKey(password); + return true; + } + catch (FormatException) + { + return false; + } } } } @@ -340,18 +347,17 @@ public override bool ChangePassword(string oldPassword, string newPassword) succeed = false; } }); - - if (succeed) - { - foreach (NEP6Account account in accounts.Values) - account.ChangePasswordCommit(); - password = newPassword; - } - else - { - foreach (NEP6Account account in accounts.Values) - account.ChangePasswordRoolback(); - } + } + if (succeed) + { + foreach (NEP6Account account in accounts.Values) + account.ChangePasswordCommit(); + password = newPassword; + } + else + { + foreach (NEP6Account account in accounts.Values) + account.ChangePasswordRoolback(); } return succeed; } diff --git a/src/neo/Wallets/NEP6/ScryptParameters.cs b/src/neo/Wallets/NEP6/ScryptParameters.cs index 22d86b3f59..15b6f08fc2 100644 --- a/src/neo/Wallets/NEP6/ScryptParameters.cs +++ b/src/neo/Wallets/NEP6/ScryptParameters.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2021 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -66,12 +66,11 @@ public static ScryptParameters FromJson(JObject json) /// The parameters represented by a JSON object. public JObject ToJson() { - return new JObject - { - ["n"] = N, - ["r"] = R, - ["p"] = P - }; + JObject json = new(); + json["n"] = N; + json["r"] = R; + json["p"] = P; + return json; } } } diff --git a/src/neo/Wallets/SQLite/UserWallet.cs b/src/neo/Wallets/SQLite/UserWallet.cs index 357e4e8cc6..4da956a573 100644 --- a/src/neo/Wallets/SQLite/UserWallet.cs +++ b/src/neo/Wallets/SQLite/UserWallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -104,7 +104,10 @@ private void AddAccount(UserWalletAccount account) { if (accounts.TryGetValue(account.ScriptHash, out UserWalletAccount account_old)) { - account.Contract ??= account_old.Contract; + if (account.Contract == null) + { + account.Contract = account_old.Contract; + } } accounts[account.ScriptHash] = account; } @@ -332,7 +335,7 @@ private byte[] LoadStoredData(string name) /// The password of the wallet. /// The to be used by the wallet. /// The opened wallet. - public new static UserWallet Open(string path, string password, ProtocolSettings settings) + public static new UserWallet Open(string path, string password, ProtocolSettings settings) { return new UserWallet(path, password.ToAesKey(), settings); } diff --git a/src/neo/Wallets/SQLite/VerificationContract.cs b/src/neo/Wallets/SQLite/VerificationContract.cs index b816404429..d4d600440a 100644 --- a/src/neo/Wallets/SQLite/VerificationContract.cs +++ b/src/neo/Wallets/SQLite/VerificationContract.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -36,7 +36,8 @@ public void Deserialize(ref MemoryReader reader) public bool Equals(VerificationContract other) { if (ReferenceEquals(this, other)) return true; - return other is not null && ScriptHash.Equals(other.ScriptHash); + if (other is null) return false; + return ScriptHash.Equals(other.ScriptHash); } public override bool Equals(object obj) diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index edad02c949..2813d64618 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -1,10 +1,10 @@ // Copyright (C) 2015-2022 The Neo Project. -// -// The neo is free software distributed under the MIT software license, +// +// The neo is free software distributed under the MIT software license, // see the accompanying file LICENSE in the main directory of the -// project or http://www.opensource.org/licenses/mit-license.php +// project or http://www.opensource.org/licenses/mit-license.php // for more details. -// +// // Redistribution and use in source and binary forms with or without // modifications are permitted. @@ -249,7 +249,7 @@ public virtual WalletAccount GetDefaultAccount() foreach (WalletAccount account in GetAccounts()) { if (account.IsDefault) return account; - first ??= account; + if (first == null) first = account; } return first; } From 1d2c2fcabaa8c113b8008e88f95b5f14ca652529 Mon Sep 17 00:00:00 2001 From: Jinghui Liao Date: Sat, 9 Jul 2022 16:29:11 -0400 Subject: [PATCH 8/8] revert code style changes --- src/neo/Network/P2P/Payloads/Header.cs | 27 +++++++++---------- src/neo/Network/P2P/RemoteNode.cs | 2 +- .../ApplicationEngine.Iterator.cs | 4 +-- src/neo/SmartContract/Manifest/ContractAbi.cs | 9 +++---- .../Manifest/WildCardContainer.cs | 2 +- src/neo/Wallets/Wallet.cs | 3 ++- 6 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/neo/Network/P2P/Payloads/Header.cs b/src/neo/Network/P2P/Payloads/Header.cs index b973321c2d..0cee55b052 100644 --- a/src/neo/Network/P2P/Payloads/Header.cs +++ b/src/neo/Network/P2P/Payloads/Header.cs @@ -220,20 +220,19 @@ void IVerifiable.SerializeUnsigned(BinaryWriter writer) /// The header represented by a JSON object. public JObject ToJson(ProtocolSettings settings) { - return new JObject - { - ["hash"] = Hash.ToString(), - ["size"] = Size, - ["version"] = version, - ["previousblockhash"] = prevHash.ToString(), - ["merkleroot"] = merkleRoot.ToString(), - ["time"] = timestamp, - ["nonce"] = nonce.ToString("X16"), - ["index"] = index, - ["primary"] = primaryIndex, - ["nextconsensus"] = nextConsensus.ToAddress(settings.AddressVersion), - ["witnesses"] = new JArray(Witness.ToJson()) - }; + JObject json = new(); + json["hash"] = Hash.ToString(); + json["size"] = Size; + json["version"] = version; + json["previousblockhash"] = prevHash.ToString(); + json["merkleroot"] = merkleRoot.ToString(); + json["time"] = timestamp; + json["nonce"] = nonce.ToString("X16"); + json["index"] = index; + json["primary"] = primaryIndex; + json["nextconsensus"] = nextConsensus.ToAddress(settings.AddressVersion); + json["witnesses"] = new JArray(Witness.ToJson()); + return json; } internal bool Verify(ProtocolSettings settings, DataCache snapshot) diff --git a/src/neo/Network/P2P/RemoteNode.cs b/src/neo/Network/P2P/RemoteNode.cs index 84dd11f922..e7444433c9 100644 --- a/src/neo/Network/P2P/RemoteNode.cs +++ b/src/neo/Network/P2P/RemoteNode.cs @@ -260,7 +260,7 @@ internal protected override bool IsHighPriority(object message) }; } - protected internal override bool ShallDrop(object message, IEnumerable queue) + internal protected override bool ShallDrop(object message, IEnumerable queue) { if (message is not Message msg) return false; return msg.Command switch diff --git a/src/neo/SmartContract/ApplicationEngine.Iterator.cs b/src/neo/SmartContract/ApplicationEngine.Iterator.cs index 6b1ccb2762..2280f2dced 100644 --- a/src/neo/SmartContract/ApplicationEngine.Iterator.cs +++ b/src/neo/SmartContract/ApplicationEngine.Iterator.cs @@ -33,7 +33,7 @@ partial class ApplicationEngine /// /// The iterator to be advanced. /// if the iterator was successfully advanced to the next element; if the iterator has passed the end of the collection. - protected internal static bool IteratorNext(IIterator iterator) + internal protected static bool IteratorNext(IIterator iterator) { return iterator.Next(); } @@ -44,7 +44,7 @@ protected internal static bool IteratorNext(IIterator iterator) /// /// The iterator to be used. /// The element in the collection at the current position of the iterator. - protected internal StackItem IteratorValue(IIterator iterator) + internal protected StackItem IteratorValue(IIterator iterator) { return iterator.Value(ReferenceCounter); } diff --git a/src/neo/SmartContract/Manifest/ContractAbi.cs b/src/neo/SmartContract/Manifest/ContractAbi.cs index 5345a6042e..278ac28cda 100644 --- a/src/neo/SmartContract/Manifest/ContractAbi.cs +++ b/src/neo/SmartContract/Manifest/ContractAbi.cs @@ -95,11 +95,10 @@ public ContractMethodDescriptor GetMethod(string name, int pcount) /// The ABI represented by a JSON object. public JObject ToJson() { - return new JObject - { - ["methods"] = new JArray(Methods.Select(u => u.ToJson()).ToArray()), - ["events"] = new JArray(Events.Select(u => u.ToJson()).ToArray()) - }; + var json = new JObject(); + json["methods"] = new JArray(Methods.Select(u => u.ToJson()).ToArray()); + json["events"] = new JArray(Events.Select(u => u.ToJson()).ToArray()); + return json; } } } diff --git a/src/neo/SmartContract/Manifest/WildCardContainer.cs b/src/neo/SmartContract/Manifest/WildCardContainer.cs index 19e60f91a0..135afb5408 100644 --- a/src/neo/SmartContract/Manifest/WildCardContainer.cs +++ b/src/neo/SmartContract/Manifest/WildCardContainer.cs @@ -87,7 +87,7 @@ public IEnumerator GetEnumerator() public JObject ToJson(Func elementSelector) { if (IsWildcard) return "*"; - return _data.Select(elementSelector).ToArray(); + return _data.Select(p => elementSelector(p)).ToArray(); } } } diff --git a/src/neo/Wallets/Wallet.cs b/src/neo/Wallets/Wallet.cs index 2813d64618..33076b7b36 100644 --- a/src/neo/Wallets/Wallet.cs +++ b/src/neo/Wallets/Wallet.cs @@ -518,7 +518,8 @@ public Transaction MakeTransaction(DataCache snapshot, TransferOutput[] outputs, } script = sb.ToArray(); } - balances_gas ??= accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList(); + if (balances_gas is null) + balances_gas = accounts.Select(p => (Account: p, Value: NativeContract.GAS.BalanceOf(snapshot, p))).Where(p => p.Value.Sign > 0).ToList(); return MakeTransaction(snapshot, script, cosignerList.Values.ToArray(), Array.Empty(), balances_gas, persistingBlock: persistingBlock); }