diff --git a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs index 01a76eeee4..efb06d93be 100644 --- a/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs +++ b/neo.UnitTests/Network/P2P/Payloads/UT_Witness.cs @@ -122,7 +122,7 @@ public void MaxSize_OK() witness.Size.Should().Be(1003); witness.InvocationScript.GetVarSize().Should().Be(653); witness.VerificationScript.GetVarSize().Should().Be(350); - + Assert.IsTrue(witness.Size <= 1024); var copy = witness.ToArray().AsSerializable(); diff --git a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs index c531c8c138..ade2472ba8 100644 --- a/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs +++ b/neo.UnitTests/Wallets/NEP6/UT_NEP6Account.cs @@ -18,7 +18,8 @@ public class UT_NEP6Account private static KeyPair keyPair; [ClassInitialize] - public static void ClassSetup(TestContext context) { + public static void ClassSetup(TestContext context) + { byte[] privateKey = { 0x01,0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01}; keyPair = new KeyPair(privateKey); diff --git a/neo/BigDecimal.cs b/neo/BigDecimal.cs index 1d65859b0f..aaf541caa9 100644 --- a/neo/BigDecimal.cs +++ b/neo/BigDecimal.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Numerics; namespace Neo diff --git a/neo/Consensus/ChangeView.cs b/neo/Consensus/ChangeView.cs index 4c18b3fb3f..607e44cfd5 100644 --- a/neo/Consensus/ChangeView.cs +++ b/neo/Consensus/ChangeView.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Neo.Consensus { diff --git a/neo/Consensus/ChangeViewReason.cs b/neo/Consensus/ChangeViewReason.cs index eb06b7494a..066ecc1085 100644 --- a/neo/Consensus/ChangeViewReason.cs +++ b/neo/Consensus/ChangeViewReason.cs @@ -1,4 +1,4 @@ -namespace Neo.Consensus +namespace Neo.Consensus { public enum ChangeViewReason : byte { diff --git a/neo/Consensus/Commit.cs b/neo/Consensus/Commit.cs index f7c17e559a..84585e1ee4 100644 --- a/neo/Consensus/Commit.cs +++ b/neo/Consensus/Commit.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Neo.Consensus { diff --git a/neo/Consensus/ConsensusContext.cs b/neo/Consensus/ConsensusContext.cs index a06c6c965b..fbb21d8cd7 100644 --- a/neo/Consensus/ConsensusContext.cs +++ b/neo/Consensus/ConsensusContext.cs @@ -6,7 +6,7 @@ using Neo.Persistence; using Neo.SmartContract; using Neo.SmartContract.Native; -using Neo.VM; +using Neo.VM; using Neo.Wallets; using System; using System.Collections.Generic; @@ -39,11 +39,11 @@ internal class ConsensusContext : IDisposable, ISerializable public Snapshot Snapshot { get; private set; } private KeyPair keyPair; - private int _witnessSize; + private int _witnessSize; private readonly Wallet wallet; private readonly Store store; private readonly Random random = new Random(); - + public int F => (Validators.Length - 1) / 3; public int M => Validators.Length - F; public bool IsPrimary => MyIndex == Block.ConsensusData.PrimaryIndex; @@ -205,40 +205,40 @@ private void SignPayload(ConsensusPayload payload) return; } payload.Witness = sc.GetWitnesses()[0]; - } - + } + /// /// Return the expected block size /// - internal int GetExpectedBlockSize() - { - return GetExpectedBlockSizeWithoutTransactions(Transactions.Count) + // Base size - Transactions.Values.Sum(u => u.Size); // Sum Txs + internal int GetExpectedBlockSize() + { + return GetExpectedBlockSizeWithoutTransactions(Transactions.Count) + // Base size + Transactions.Values.Sum(u => u.Size); // Sum Txs } - /// - /// Return the expected block size without txs - /// - /// Expected transactions - internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions) - { - var blockSize = - // BlockBase - sizeof(uint) + //Version - UInt256.Length + //PrevHash - UInt256.Length + //MerkleRoot - sizeof(ulong) + //Timestamp - sizeof(uint) + //Index - UInt160.Length + //NextConsensus - 1 + // - _witnessSize; //Witness - - blockSize += - // Block - Block.ConsensusData.Size + //ConsensusData - IO.Helper.GetVarSize(expectedTransactions + 1); //Transactions count - - return blockSize; + /// + /// Return the expected block size without txs + /// + /// Expected transactions + internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions) + { + var blockSize = + // BlockBase + sizeof(uint) + //Version + UInt256.Length + //PrevHash + UInt256.Length + //MerkleRoot + sizeof(ulong) + //Timestamp + sizeof(uint) + //Index + UInt160.Length + //NextConsensus + 1 + // + _witnessSize; //Witness + + blockSize += + // Block + Block.ConsensusData.Size + //ConsensusData + IO.Helper.GetVarSize(expectedTransactions + 1); //Transactions count + + return blockSize; } /// @@ -247,18 +247,18 @@ internal int GetExpectedBlockSizeWithoutTransactions(int expectedTransactions) /// Ordered transactions internal void EnsureMaxBlockSize(IEnumerable txs) { - uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot); - uint maxTransactionsPerBlock = NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot); + uint maxBlockSize = NativeContract.Policy.GetMaxBlockSize(Snapshot); + uint maxTransactionsPerBlock = NativeContract.Policy.GetMaxTransactionsPerBlock(Snapshot); // Limit Speaker proposal to the limit `MaxTransactionsPerBlock` or all available transactions of the mempool txs = txs.Take((int)maxTransactionsPerBlock); List hashes = new List(); Transactions = new Dictionary(); - Block.Transactions = new Transaction[0]; - - // We need to know the expected block size - - var blockSize = GetExpectedBlockSizeWithoutTransactions(txs.Count()); + Block.Transactions = new Transaction[0]; + + // We need to know the expected block size + + var blockSize = GetExpectedBlockSizeWithoutTransactions(txs.Count()); // Iterate transaction until reach the size @@ -271,8 +271,8 @@ internal void EnsureMaxBlockSize(IEnumerable txs) hashes.Add(tx.Hash); Transactions.Add(tx.Hash, tx); } - - TransactionHashes = hashes.ToArray(); + + TransactionHashes = hashes.ToArray(); } public ConsensusPayload MakePrepareRequest() @@ -281,8 +281,8 @@ public ConsensusPayload MakePrepareRequest() random.NextBytes(buffer); Block.ConsensusData.Nonce = BitConverter.ToUInt64(buffer, 0); EnsureMaxBlockSize(Blockchain.Singleton.MemPool.GetSortedVerifiedTransactions()); - Block.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1); - + Block.Timestamp = Math.Max(TimeProvider.Current.UtcNow.ToTimestampMS(), PrevHeader.Timestamp + 1); + return PreparationPayloads[MyIndex] = MakeSignedPayload(new PrepareRequest { Timestamp = Block.Timestamp, @@ -348,21 +348,21 @@ public void Reset(byte viewNumber) }; var pv = Validators; Validators = NativeContract.NEO.GetNextBlockValidators(Snapshot); - if (_witnessSize == 0 || (pv != null && pv.Length != Validators.Length)) - { - // Compute the expected size of the witness - using (ScriptBuilder sb = new ScriptBuilder()) - { - for (int x = 0; x < M; x++) - { - sb.EmitPush(new byte[64]); - } - _witnessSize = new Witness - { - InvocationScript = sb.ToArray(), - VerificationScript = Contract.CreateMultiSigRedeemScript(M, Validators) - }.Size; - } + if (_witnessSize == 0 || (pv != null && pv.Length != Validators.Length)) + { + // Compute the expected size of the witness + using (ScriptBuilder sb = new ScriptBuilder()) + { + for (int x = 0; x < M; x++) + { + sb.EmitPush(new byte[64]); + } + _witnessSize = new Witness + { + InvocationScript = sb.ToArray(), + VerificationScript = Contract.CreateMultiSigRedeemScript(M, Validators) + }.Size; + } } MyIndex = -1; ChangeViewPayloads = new ConsensusPayload[Validators.Length]; diff --git a/neo/Consensus/ConsensusMessage.cs b/neo/Consensus/ConsensusMessage.cs index 85bf3174e5..af16db03e3 100644 --- a/neo/Consensus/ConsensusMessage.cs +++ b/neo/Consensus/ConsensusMessage.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Caching; using System; using System.IO; diff --git a/neo/Consensus/ConsensusMessageType.cs b/neo/Consensus/ConsensusMessageType.cs index 0aff263595..fe13207db1 100644 --- a/neo/Consensus/ConsensusMessageType.cs +++ b/neo/Consensus/ConsensusMessageType.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; namespace Neo.Consensus { diff --git a/neo/Consensus/ConsensusService.cs b/neo/Consensus/ConsensusService.cs index ee5c91d635..cac657c95f 100644 --- a/neo/Consensus/ConsensusService.cs +++ b/neo/Consensus/ConsensusService.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Neo.Cryptography; using Neo.IO; diff --git a/neo/Consensus/PrepareRequest.cs b/neo/Consensus/PrepareRequest.cs index 85823fe957..2369b4f9f7 100644 --- a/neo/Consensus/PrepareRequest.cs +++ b/neo/Consensus/PrepareRequest.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using System; using System.IO; diff --git a/neo/Consensus/PrepareResponse.cs b/neo/Consensus/PrepareResponse.cs index 93eb95833a..7c2956ccc2 100644 --- a/neo/Consensus/PrepareResponse.cs +++ b/neo/Consensus/PrepareResponse.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.IO; namespace Neo.Consensus diff --git a/neo/Consensus/RecoveryMessage.ChangeViewPayloadCompact.cs b/neo/Consensus/RecoveryMessage.ChangeViewPayloadCompact.cs index 6d4d6a7ae2..dfc46385c0 100644 --- a/neo/Consensus/RecoveryMessage.ChangeViewPayloadCompact.cs +++ b/neo/Consensus/RecoveryMessage.ChangeViewPayloadCompact.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using System.IO; diff --git a/neo/Consensus/RecoveryMessage.CommitPayloadCompact.cs b/neo/Consensus/RecoveryMessage.CommitPayloadCompact.cs index d9347b71bc..72962f92b3 100644 --- a/neo/Consensus/RecoveryMessage.CommitPayloadCompact.cs +++ b/neo/Consensus/RecoveryMessage.CommitPayloadCompact.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using System.IO; diff --git a/neo/Consensus/RecoveryMessage.PreparationPayloadCompact.cs b/neo/Consensus/RecoveryMessage.PreparationPayloadCompact.cs index 8c0e52f59f..962ae69185 100644 --- a/neo/Consensus/RecoveryMessage.PreparationPayloadCompact.cs +++ b/neo/Consensus/RecoveryMessage.PreparationPayloadCompact.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using System.IO; diff --git a/neo/Consensus/RecoveryMessage.cs b/neo/Consensus/RecoveryMessage.cs index afae45470b..a5e1c09ac6 100644 --- a/neo/Consensus/RecoveryMessage.cs +++ b/neo/Consensus/RecoveryMessage.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Ledger; using Neo.Network.P2P.Payloads; using Neo.SmartContract; diff --git a/neo/Consensus/RecoveryRequest.cs b/neo/Consensus/RecoveryRequest.cs index c02ceb176c..6ea0d7c2f7 100644 --- a/neo/Consensus/RecoveryRequest.cs +++ b/neo/Consensus/RecoveryRequest.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Neo.Consensus { diff --git a/neo/Cryptography/Base58.cs b/neo/Cryptography/Base58.cs index fd5bf4d432..b64f12216b 100644 --- a/neo/Cryptography/Base58.cs +++ b/neo/Cryptography/Base58.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Numerics; using System.Text; diff --git a/neo/Cryptography/BloomFilter.cs b/neo/Cryptography/BloomFilter.cs index 637cd9fac5..c4b79d01f2 100644 --- a/neo/Cryptography/BloomFilter.cs +++ b/neo/Cryptography/BloomFilter.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Linq; namespace Neo.Cryptography diff --git a/neo/Cryptography/Crypto.cs b/neo/Cryptography/Crypto.cs index ae1c8cd168..c835e3eebb 100644 --- a/neo/Cryptography/Crypto.cs +++ b/neo/Cryptography/Crypto.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Security.Cryptography; diff --git a/neo/Cryptography/ECC/ECCurve.cs b/neo/Cryptography/ECC/ECCurve.cs index 9d43bcd25f..45d70d31f4 100644 --- a/neo/Cryptography/ECC/ECCurve.cs +++ b/neo/Cryptography/ECC/ECCurve.cs @@ -1,4 +1,4 @@ -using System.Globalization; +using System.Globalization; using System.Numerics; namespace Neo.Cryptography.ECC diff --git a/neo/Cryptography/ECC/ECDsa.cs b/neo/Cryptography/ECC/ECDsa.cs index a254b4248e..07373a7844 100644 --- a/neo/Cryptography/ECC/ECDsa.cs +++ b/neo/Cryptography/ECC/ECDsa.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Numerics; using System.Security.Cryptography; diff --git a/neo/Cryptography/ECC/ECFieldElement.cs b/neo/Cryptography/ECC/ECFieldElement.cs index e33cab4206..331e1e4408 100644 --- a/neo/Cryptography/ECC/ECFieldElement.cs +++ b/neo/Cryptography/ECC/ECFieldElement.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Numerics; diff --git a/neo/Cryptography/ECC/ECPoint.cs b/neo/Cryptography/ECC/ECPoint.cs index dbd556eb50..803aab9987 100644 --- a/neo/Cryptography/ECC/ECPoint.cs +++ b/neo/Cryptography/ECC/ECPoint.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; using System.Linq; diff --git a/neo/Cryptography/Helper.cs b/neo/Cryptography/Helper.cs index ff1bb8d3d7..07c9ce74e9 100644 --- a/neo/Cryptography/Helper.cs +++ b/neo/Cryptography/Helper.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using System; using System.Collections.Generic; diff --git a/neo/Cryptography/MerkleTree.cs b/neo/Cryptography/MerkleTree.cs index 8d73f56a23..0d8e617f3f 100644 --- a/neo/Cryptography/MerkleTree.cs +++ b/neo/Cryptography/MerkleTree.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/neo/Cryptography/MerkleTreeNode.cs b/neo/Cryptography/MerkleTreeNode.cs index 6bfc75c8d1..73b84b43e9 100644 --- a/neo/Cryptography/MerkleTreeNode.cs +++ b/neo/Cryptography/MerkleTreeNode.cs @@ -1,4 +1,4 @@ -namespace Neo.Cryptography +namespace Neo.Cryptography { internal class MerkleTreeNode { diff --git a/neo/Cryptography/Murmur3.cs b/neo/Cryptography/Murmur3.cs index e54c19ebc1..6296bb20be 100644 --- a/neo/Cryptography/Murmur3.cs +++ b/neo/Cryptography/Murmur3.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.CompilerServices; using System.Security.Cryptography; diff --git a/neo/Cryptography/RIPEMD160Managed.cs b/neo/Cryptography/RIPEMD160Managed.cs index 898780dc47..22ffafb835 100644 --- a/neo/Cryptography/RIPEMD160Managed.cs +++ b/neo/Cryptography/RIPEMD160Managed.cs @@ -1,4 +1,4 @@ -#if !NET47 +#if !NET47 using System; using System.Runtime.InteropServices; using System.Security; diff --git a/neo/Cryptography/SCrypt.cs b/neo/Cryptography/SCrypt.cs index 3022af296c..e40c2c83c5 100644 --- a/neo/Cryptography/SCrypt.cs +++ b/neo/Cryptography/SCrypt.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Security.Cryptography; namespace Neo.Cryptography diff --git a/neo/Helper.cs b/neo/Helper.cs index d8409b64bd..1a513ec79e 100644 --- a/neo/Helper.cs +++ b/neo/Helper.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using Neo.Plugins; using System; using System.Collections.Generic; diff --git a/neo/IO/Actors/Idle.cs b/neo/IO/Actors/Idle.cs index 4bb8655bd8..bd4a2d05fa 100644 --- a/neo/IO/Actors/Idle.cs +++ b/neo/IO/Actors/Idle.cs @@ -1,4 +1,4 @@ -namespace Neo.IO.Actors +namespace Neo.IO.Actors { internal sealed class Idle { diff --git a/neo/IO/Actors/PriorityMailbox.cs b/neo/IO/Actors/PriorityMailbox.cs index c6c8a8fbe2..31a50c9a89 100644 --- a/neo/IO/Actors/PriorityMailbox.cs +++ b/neo/IO/Actors/PriorityMailbox.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Akka.Dispatch; using Akka.Dispatch.MessageQueues; diff --git a/neo/IO/Actors/PriorityMessageQueue.cs b/neo/IO/Actors/PriorityMessageQueue.cs index d22f7626fe..b7820b065a 100644 --- a/neo/IO/Actors/PriorityMessageQueue.cs +++ b/neo/IO/Actors/PriorityMessageQueue.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Dispatch; using Akka.Dispatch.MessageQueues; using System; diff --git a/neo/IO/ByteArrayComparer.cs b/neo/IO/ByteArrayComparer.cs index 956ab758e6..478c6e3c7d 100644 --- a/neo/IO/ByteArrayComparer.cs +++ b/neo/IO/ByteArrayComparer.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace Neo.IO diff --git a/neo/IO/Caching/Cache.cs b/neo/IO/Caching/Cache.cs index 5b97d3a223..b5095231f3 100644 --- a/neo/IO/Caching/Cache.cs +++ b/neo/IO/Caching/Cache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; diff --git a/neo/IO/Caching/CloneCache.cs b/neo/IO/Caching/CloneCache.cs index f13865a41b..0dd030fcb6 100644 --- a/neo/IO/Caching/CloneCache.cs +++ b/neo/IO/Caching/CloneCache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; namespace Neo.IO.Caching diff --git a/neo/IO/Caching/CloneMetaCache.cs b/neo/IO/Caching/CloneMetaCache.cs index 6b354e256e..3cb0d83201 100644 --- a/neo/IO/Caching/CloneMetaCache.cs +++ b/neo/IO/Caching/CloneMetaCache.cs @@ -1,4 +1,4 @@ -namespace Neo.IO.Caching +namespace Neo.IO.Caching { internal class CloneMetaCache : MetaDataCache where T : class, ICloneable, ISerializable, new() diff --git a/neo/IO/Caching/DataCache.cs b/neo/IO/Caching/DataCache.cs index 278c01d650..dc97031d10 100644 --- a/neo/IO/Caching/DataCache.cs +++ b/neo/IO/Caching/DataCache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; diff --git a/neo/IO/Caching/FIFOCache.cs b/neo/IO/Caching/FIFOCache.cs index 4aa7198b50..c96b11bf6e 100644 --- a/neo/IO/Caching/FIFOCache.cs +++ b/neo/IO/Caching/FIFOCache.cs @@ -1,4 +1,4 @@ -namespace Neo.IO.Caching +namespace Neo.IO.Caching { internal abstract class FIFOCache : Cache { diff --git a/neo/IO/Caching/FIFOSet.cs b/neo/IO/Caching/FIFOSet.cs index aba54463ae..98733ce444 100644 --- a/neo/IO/Caching/FIFOSet.cs +++ b/neo/IO/Caching/FIFOSet.cs @@ -1,65 +1,65 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.Collections.Specialized; -using System.Linq; - -namespace Neo.IO.Caching -{ - internal class FIFOSet : IEnumerable where T : IEquatable - { - private readonly int maxCapacity; - private readonly int removeCount; - private readonly OrderedDictionary dictionary; - - public FIFOSet(int maxCapacity, decimal batchSize = 0.1m) - { - if (maxCapacity <= 0) throw new ArgumentOutOfRangeException(nameof(maxCapacity)); - if (batchSize <= 0 || batchSize > 1) throw new ArgumentOutOfRangeException(nameof(batchSize)); - - this.maxCapacity = maxCapacity; - this.removeCount = Math.Max((int)(maxCapacity * batchSize), 1); - this.dictionary = new OrderedDictionary(maxCapacity); - } - - public bool Add(T item) - { - if (dictionary.Contains(item)) return false; - if (dictionary.Count >= maxCapacity) - { - if (removeCount == maxCapacity) - { - dictionary.Clear(); - } - else - { - for (int i = 0; i < removeCount; i++) - dictionary.RemoveAt(0); - } - } - dictionary.Add(item, null); - return true; - } - - public bool Contains(T item) - { - return dictionary.Contains(item); - } - - public void ExceptWith(IEnumerable hashes) - { - foreach (var hash in hashes) - { - dictionary.Remove(hash); - } - } - - public IEnumerator GetEnumerator() - { - var entries = dictionary.Keys.Cast().ToArray(); - foreach (var entry in entries) yield return entry; - } - - IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); - } -} +using System; +using System.Collections; +using System.Collections.Generic; +using System.Collections.Specialized; +using System.Linq; + +namespace Neo.IO.Caching +{ + internal class FIFOSet : IEnumerable where T : IEquatable + { + private readonly int maxCapacity; + private readonly int removeCount; + private readonly OrderedDictionary dictionary; + + public FIFOSet(int maxCapacity, decimal batchSize = 0.1m) + { + if (maxCapacity <= 0) throw new ArgumentOutOfRangeException(nameof(maxCapacity)); + if (batchSize <= 0 || batchSize > 1) throw new ArgumentOutOfRangeException(nameof(batchSize)); + + this.maxCapacity = maxCapacity; + this.removeCount = Math.Max((int)(maxCapacity * batchSize), 1); + this.dictionary = new OrderedDictionary(maxCapacity); + } + + public bool Add(T item) + { + if (dictionary.Contains(item)) return false; + if (dictionary.Count >= maxCapacity) + { + if (removeCount == maxCapacity) + { + dictionary.Clear(); + } + else + { + for (int i = 0; i < removeCount; i++) + dictionary.RemoveAt(0); + } + } + dictionary.Add(item, null); + return true; + } + + public bool Contains(T item) + { + return dictionary.Contains(item); + } + + public void ExceptWith(IEnumerable hashes) + { + foreach (var hash in hashes) + { + dictionary.Remove(hash); + } + } + + public IEnumerator GetEnumerator() + { + var entries = dictionary.Keys.Cast().ToArray(); + foreach (var entry in entries) yield return entry; + } + + IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + } +} diff --git a/neo/IO/Caching/MetaDataCache.cs b/neo/IO/Caching/MetaDataCache.cs index fa3fed6215..f0c40cc59a 100644 --- a/neo/IO/Caching/MetaDataCache.cs +++ b/neo/IO/Caching/MetaDataCache.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Caching { diff --git a/neo/IO/Caching/OrderedDictionary.cs b/neo/IO/Caching/OrderedDictionary.cs index bf12785406..efc85b6305 100644 --- a/neo/IO/Caching/OrderedDictionary.cs +++ b/neo/IO/Caching/OrderedDictionary.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; diff --git a/neo/IO/Caching/ReflectionCache.cs b/neo/IO/Caching/ReflectionCache.cs index 800561c6d9..705366e2fb 100644 --- a/neo/IO/Caching/ReflectionCache.cs +++ b/neo/IO/Caching/ReflectionCache.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Reflection; diff --git a/neo/IO/Caching/ReflectionCacheAttribute.cs b/neo/IO/Caching/ReflectionCacheAttribute.cs index e1c1200278..ba5fd4e1bc 100644 --- a/neo/IO/Caching/ReflectionCacheAttribute.cs +++ b/neo/IO/Caching/ReflectionCacheAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Caching { diff --git a/neo/IO/Caching/RelayCache.cs b/neo/IO/Caching/RelayCache.cs index ec6e35bdce..0bc2884eda 100644 --- a/neo/IO/Caching/RelayCache.cs +++ b/neo/IO/Caching/RelayCache.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P.Payloads; +using Neo.Network.P2P.Payloads; namespace Neo.IO.Caching { diff --git a/neo/IO/Caching/TrackState.cs b/neo/IO/Caching/TrackState.cs index aa144aab34..cba7daec0c 100644 --- a/neo/IO/Caching/TrackState.cs +++ b/neo/IO/Caching/TrackState.cs @@ -1,4 +1,4 @@ -namespace Neo.IO.Caching +namespace Neo.IO.Caching { public enum TrackState : byte { diff --git a/neo/IO/Data/LevelDB/DB.cs b/neo/IO/Data/LevelDB/DB.cs index 559a109594..04e8f50e8f 100644 --- a/neo/IO/Data/LevelDB/DB.cs +++ b/neo/IO/Data/LevelDB/DB.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/Helper.cs b/neo/IO/Data/LevelDB/Helper.cs index 2b58690db0..d4c451f574 100644 --- a/neo/IO/Data/LevelDB/Helper.cs +++ b/neo/IO/Data/LevelDB/Helper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; diff --git a/neo/IO/Data/LevelDB/Iterator.cs b/neo/IO/Data/LevelDB/Iterator.cs index 11e72faf63..b3a6a0bfe0 100644 --- a/neo/IO/Data/LevelDB/Iterator.cs +++ b/neo/IO/Data/LevelDB/Iterator.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/LevelDBException.cs b/neo/IO/Data/LevelDB/LevelDBException.cs index 0fa0578c56..8804f1f7f2 100644 --- a/neo/IO/Data/LevelDB/LevelDBException.cs +++ b/neo/IO/Data/LevelDB/LevelDBException.cs @@ -1,4 +1,4 @@ -using System.Data.Common; +using System.Data.Common; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/Native.cs b/neo/IO/Data/LevelDB/Native.cs index fc3ccd6387..6a19ef4cfe 100644 --- a/neo/IO/Data/LevelDB/Native.cs +++ b/neo/IO/Data/LevelDB/Native.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Runtime.InteropServices; diff --git a/neo/IO/Data/LevelDB/Options.cs b/neo/IO/Data/LevelDB/Options.cs index 676627cb08..53dd6e488b 100644 --- a/neo/IO/Data/LevelDB/Options.cs +++ b/neo/IO/Data/LevelDB/Options.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/ReadOptions.cs b/neo/IO/Data/LevelDB/ReadOptions.cs index d27f0d7b59..9c198cfba1 100644 --- a/neo/IO/Data/LevelDB/ReadOptions.cs +++ b/neo/IO/Data/LevelDB/ReadOptions.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/Slice.cs b/neo/IO/Data/LevelDB/Slice.cs index 95da8c6a44..1f9d927783 100644 --- a/neo/IO/Data/LevelDB/Slice.cs +++ b/neo/IO/Data/LevelDB/Slice.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using System; using System.Linq; using System.Runtime.InteropServices; diff --git a/neo/IO/Data/LevelDB/SliceBuilder.cs b/neo/IO/Data/LevelDB/SliceBuilder.cs index f00ce20454..d5888c6b5e 100644 --- a/neo/IO/Data/LevelDB/SliceBuilder.cs +++ b/neo/IO/Data/LevelDB/SliceBuilder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Text; diff --git a/neo/IO/Data/LevelDB/Snapshot.cs b/neo/IO/Data/LevelDB/Snapshot.cs index 89a89cb55a..d651098388 100644 --- a/neo/IO/Data/LevelDB/Snapshot.cs +++ b/neo/IO/Data/LevelDB/Snapshot.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/WriteBatch.cs b/neo/IO/Data/LevelDB/WriteBatch.cs index eaa3e08bd6..b3a9782108 100644 --- a/neo/IO/Data/LevelDB/WriteBatch.cs +++ b/neo/IO/Data/LevelDB/WriteBatch.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Data/LevelDB/WriteOptions.cs b/neo/IO/Data/LevelDB/WriteOptions.cs index 8a74fb5340..8d120c3997 100644 --- a/neo/IO/Data/LevelDB/WriteOptions.cs +++ b/neo/IO/Data/LevelDB/WriteOptions.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.IO.Data.LevelDB { diff --git a/neo/IO/Helper.cs b/neo/IO/Helper.cs index a306e297d5..c985e676b2 100644 --- a/neo/IO/Helper.cs +++ b/neo/IO/Helper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/neo/IO/ICloneable.cs b/neo/IO/ICloneable.cs index 4df61c84b8..83b4d77725 100644 --- a/neo/IO/ICloneable.cs +++ b/neo/IO/ICloneable.cs @@ -1,4 +1,4 @@ -namespace Neo.IO +namespace Neo.IO { public interface ICloneable { diff --git a/neo/IO/ISerializable.cs b/neo/IO/ISerializable.cs index 28f1ec3e01..d03540deb2 100644 --- a/neo/IO/ISerializable.cs +++ b/neo/IO/ISerializable.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Neo.IO { diff --git a/neo/IO/Json/JArray.cs b/neo/IO/Json/JArray.cs index 3109b3b61c..6de623d29a 100644 --- a/neo/IO/Json/JArray.cs +++ b/neo/IO/Json/JArray.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.IO; diff --git a/neo/IO/Json/JBoolean.cs b/neo/IO/Json/JBoolean.cs index 83a9111422..6b7c7a34c4 100644 --- a/neo/IO/Json/JBoolean.cs +++ b/neo/IO/Json/JBoolean.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Neo.IO.Json diff --git a/neo/IO/Json/JNumber.cs b/neo/IO/Json/JNumber.cs index 2a23dc3157..daac440094 100644 --- a/neo/IO/Json/JNumber.cs +++ b/neo/IO/Json/JNumber.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.IO; using System.Text; diff --git a/neo/IO/Json/JObject.cs b/neo/IO/Json/JObject.cs index 40aa18f5da..cf6f68cbc7 100644 --- a/neo/IO/Json/JObject.cs +++ b/neo/IO/Json/JObject.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using System; using System.Collections.Generic; using System.IO; diff --git a/neo/IO/Json/JString.cs b/neo/IO/Json/JString.cs index 065e7b59f9..032470cf4e 100644 --- a/neo/IO/Json/JString.cs +++ b/neo/IO/Json/JString.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.IO; using System.Text; diff --git a/neo/IO/Wrappers/SerializableWrapper.cs b/neo/IO/Wrappers/SerializableWrapper.cs index 868c9bcba2..098e4b9c7a 100644 --- a/neo/IO/Wrappers/SerializableWrapper.cs +++ b/neo/IO/Wrappers/SerializableWrapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Neo.IO.Wrappers diff --git a/neo/IO/Wrappers/UInt32Wrapper.cs b/neo/IO/Wrappers/UInt32Wrapper.cs index fa8406d50a..6e1fb71da1 100644 --- a/neo/IO/Wrappers/UInt32Wrapper.cs +++ b/neo/IO/Wrappers/UInt32Wrapper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Neo.IO.Wrappers diff --git a/neo/Ledger/Blockchain.ApplicationExecuted.cs b/neo/Ledger/Blockchain.ApplicationExecuted.cs index 2f5d74fcb8..1bcc65563f 100644 --- a/neo/Ledger/Blockchain.ApplicationExecuted.cs +++ b/neo/Ledger/Blockchain.ApplicationExecuted.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P.Payloads; +using Neo.Network.P2P.Payloads; using Neo.SmartContract; using Neo.VM; using System.Linq; diff --git a/neo/Ledger/Blockchain.cs b/neo/Ledger/Blockchain.cs index 7d0b72402d..db879c0732 100644 --- a/neo/Ledger/Blockchain.cs +++ b/neo/Ledger/Blockchain.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Neo.Cryptography.ECC; using Neo.IO; diff --git a/neo/Ledger/ContractState.cs b/neo/Ledger/ContractState.cs index da02db912f..f6c641d7d5 100644 --- a/neo/Ledger/ContractState.cs +++ b/neo/Ledger/ContractState.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Json; using Neo.SmartContract; using Neo.SmartContract.Manifest; diff --git a/neo/Ledger/HashIndexState.cs b/neo/Ledger/HashIndexState.cs index f83aefd34f..04f7b0bd4a 100644 --- a/neo/Ledger/HashIndexState.cs +++ b/neo/Ledger/HashIndexState.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.IO; namespace Neo.Ledger diff --git a/neo/Ledger/HeaderHashList.cs b/neo/Ledger/HeaderHashList.cs index c9e9878235..928a26e5d2 100644 --- a/neo/Ledger/HeaderHashList.cs +++ b/neo/Ledger/HeaderHashList.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.IO; namespace Neo.Ledger diff --git a/neo/Ledger/RelayResultReason.cs b/neo/Ledger/RelayResultReason.cs index e698d0ea34..7bf92afac6 100644 --- a/neo/Ledger/RelayResultReason.cs +++ b/neo/Ledger/RelayResultReason.cs @@ -1,4 +1,4 @@ -namespace Neo.Ledger +namespace Neo.Ledger { public enum RelayResultReason : byte { diff --git a/neo/Ledger/StorageFlags.cs b/neo/Ledger/StorageFlags.cs index a0d7034c1d..cace3c97ef 100644 --- a/neo/Ledger/StorageFlags.cs +++ b/neo/Ledger/StorageFlags.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.Ledger { diff --git a/neo/Ledger/StorageItem.cs b/neo/Ledger/StorageItem.cs index 37a69dba2d..49ea93d8a1 100644 --- a/neo/Ledger/StorageItem.cs +++ b/neo/Ledger/StorageItem.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.IO; namespace Neo.Ledger diff --git a/neo/Ledger/StorageKey.cs b/neo/Ledger/StorageKey.cs index 187a895aa3..c214260c21 100644 --- a/neo/Ledger/StorageKey.cs +++ b/neo/Ledger/StorageKey.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using System; using System.IO; diff --git a/neo/Ledger/TransactionState.cs b/neo/Ledger/TransactionState.cs index c493bd631e..c8a479424a 100644 --- a/neo/Ledger/TransactionState.cs +++ b/neo/Ledger/TransactionState.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Payloads; using Neo.VM; using System.IO; diff --git a/neo/Ledger/TrimmedBlock.cs b/neo/Ledger/TrimmedBlock.cs index 614ee89ac1..2a6f84672b 100644 --- a/neo/Ledger/TrimmedBlock.cs +++ b/neo/Ledger/TrimmedBlock.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Caching; using Neo.IO.Json; using Neo.Network.P2P.Payloads; diff --git a/neo/NeoSystem.cs b/neo/NeoSystem.cs index f53d6efa76..867d4e4201 100644 --- a/neo/NeoSystem.cs +++ b/neo/NeoSystem.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Neo.Consensus; using Neo.Ledger; using Neo.Network.P2P; diff --git a/neo/Network/P2P/Capabilities/FullNodeCapability.cs b/neo/Network/P2P/Capabilities/FullNodeCapability.cs index 7c2ae75845..ccaabbdb5a 100644 --- a/neo/Network/P2P/Capabilities/FullNodeCapability.cs +++ b/neo/Network/P2P/Capabilities/FullNodeCapability.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; namespace Neo.Network.P2P.Capabilities { diff --git a/neo/Network/P2P/Capabilities/NodeCapability.cs b/neo/Network/P2P/Capabilities/NodeCapability.cs index 1160dad912..034afb6be8 100644 --- a/neo/Network/P2P/Capabilities/NodeCapability.cs +++ b/neo/Network/P2P/Capabilities/NodeCapability.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; diff --git a/neo/Network/P2P/Capabilities/NodeCapabilityType.cs b/neo/Network/P2P/Capabilities/NodeCapabilityType.cs index e8eb71850c..5ea0594d7b 100644 --- a/neo/Network/P2P/Capabilities/NodeCapabilityType.cs +++ b/neo/Network/P2P/Capabilities/NodeCapabilityType.cs @@ -1,4 +1,4 @@ -namespace Neo.Network.P2P.Capabilities +namespace Neo.Network.P2P.Capabilities { public enum NodeCapabilityType : byte { diff --git a/neo/Network/P2P/Capabilities/ServerCapability.cs b/neo/Network/P2P/Capabilities/ServerCapability.cs index a27573d438..0ce31e130e 100644 --- a/neo/Network/P2P/Capabilities/ServerCapability.cs +++ b/neo/Network/P2P/Capabilities/ServerCapability.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; namespace Neo.Network.P2P.Capabilities diff --git a/neo/Network/P2P/ChannelsConfig.cs b/neo/Network/P2P/ChannelsConfig.cs index fe09c54996..2882876bd2 100644 --- a/neo/Network/P2P/ChannelsConfig.cs +++ b/neo/Network/P2P/ChannelsConfig.cs @@ -1,4 +1,4 @@ -using System.Net; +using System.Net; namespace Neo.Network.P2P { diff --git a/neo/Network/P2P/Connection.cs b/neo/Network/P2P/Connection.cs index d741f1d0ee..5a00a588ef 100644 --- a/neo/Network/P2P/Connection.cs +++ b/neo/Network/P2P/Connection.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.IO; using System; using System.Net; diff --git a/neo/Network/P2P/Helper.cs b/neo/Network/P2P/Helper.cs index 433725c45b..e3e7cece1b 100644 --- a/neo/Network/P2P/Helper.cs +++ b/neo/Network/P2P/Helper.cs @@ -1,4 +1,4 @@ -using K4os.Compression.LZ4; +using K4os.Compression.LZ4; using Neo.Network.P2P.Payloads; using System; using System.Buffers; diff --git a/neo/Network/P2P/LocalNode.cs b/neo/Network/P2P/LocalNode.cs index 6f30ed50cb..79ad7fb096 100644 --- a/neo/Network/P2P/LocalNode.cs +++ b/neo/Network/P2P/LocalNode.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Neo.IO; using Neo.Ledger; using Neo.Network.P2P.Payloads; diff --git a/neo/Network/P2P/Message.cs b/neo/Network/P2P/Message.cs index 5be16b2be0..61ee4493b4 100644 --- a/neo/Network/P2P/Message.cs +++ b/neo/Network/P2P/Message.cs @@ -1,4 +1,4 @@ -using Akka.IO; +using Akka.IO; using Neo.Cryptography; using Neo.IO; using Neo.Network.P2P.Payloads; diff --git a/neo/Network/P2P/MessageCommand.cs b/neo/Network/P2P/MessageCommand.cs index ce0527e136..ed8dc6b96b 100644 --- a/neo/Network/P2P/MessageCommand.cs +++ b/neo/Network/P2P/MessageCommand.cs @@ -1,4 +1,4 @@ -namespace Neo.Network.P2P +namespace Neo.Network.P2P { public enum MessageCommand : byte { diff --git a/neo/Network/P2P/MessageFlags.cs b/neo/Network/P2P/MessageFlags.cs index 9af64e5fbc..4e8a34c1a7 100644 --- a/neo/Network/P2P/MessageFlags.cs +++ b/neo/Network/P2P/MessageFlags.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.Network.P2P { diff --git a/neo/Network/P2P/Payloads/AddrPayload.cs b/neo/Network/P2P/Payloads/AddrPayload.cs index 65337f0869..0a8f09c71e 100644 --- a/neo/Network/P2P/Payloads/AddrPayload.cs +++ b/neo/Network/P2P/Payloads/AddrPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/Block.cs b/neo/Network/P2P/Payloads/Block.cs index 75e5d7c424..d339b536a0 100644 --- a/neo/Network/P2P/Payloads/Block.cs +++ b/neo/Network/P2P/Payloads/Block.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using Neo.IO.Json; using Neo.Ledger; diff --git a/neo/Network/P2P/Payloads/BlockBase.cs b/neo/Network/P2P/Payloads/BlockBase.cs index 20a0c98211..90b1531cd0 100644 --- a/neo/Network/P2P/Payloads/BlockBase.cs +++ b/neo/Network/P2P/Payloads/BlockBase.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using Neo.IO.Json; using Neo.Persistence; diff --git a/neo/Network/P2P/Payloads/ConsensusData.cs b/neo/Network/P2P/Payloads/ConsensusData.cs index 622c42e464..48d3d14ac8 100644 --- a/neo/Network/P2P/Payloads/ConsensusData.cs +++ b/neo/Network/P2P/Payloads/ConsensusData.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using Neo.IO.Json; using Neo.Ledger; diff --git a/neo/Network/P2P/Payloads/ConsensusPayload.cs b/neo/Network/P2P/Payloads/ConsensusPayload.cs index a4c6e86ee6..062e5d9830 100644 --- a/neo/Network/P2P/Payloads/ConsensusPayload.cs +++ b/neo/Network/P2P/Payloads/ConsensusPayload.cs @@ -1,4 +1,4 @@ -using Neo.Consensus; +using Neo.Consensus; using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO; diff --git a/neo/Network/P2P/Payloads/Cosigner.cs b/neo/Network/P2P/Payloads/Cosigner.cs index 2d1f42039c..99672ecf4d 100644 --- a/neo/Network/P2P/Payloads/Cosigner.cs +++ b/neo/Network/P2P/Payloads/Cosigner.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.IO; using Neo.IO.Json; using System; diff --git a/neo/Network/P2P/Payloads/FilterAddPayload.cs b/neo/Network/P2P/Payloads/FilterAddPayload.cs index 71bddea5dc..3a7a4a9e6f 100644 --- a/neo/Network/P2P/Payloads/FilterAddPayload.cs +++ b/neo/Network/P2P/Payloads/FilterAddPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.IO; namespace Neo.Network.P2P.Payloads diff --git a/neo/Network/P2P/Payloads/FilterLoadPayload.cs b/neo/Network/P2P/Payloads/FilterLoadPayload.cs index 5d337c8dac..dfba728fc0 100644 --- a/neo/Network/P2P/Payloads/FilterLoadPayload.cs +++ b/neo/Network/P2P/Payloads/FilterLoadPayload.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/GetBlocksPayload.cs b/neo/Network/P2P/Payloads/GetBlocksPayload.cs index f7e39927f1..eccd66ed19 100644 --- a/neo/Network/P2P/Payloads/GetBlocksPayload.cs +++ b/neo/Network/P2P/Payloads/GetBlocksPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/Header.cs b/neo/Network/P2P/Payloads/Header.cs index abd7fbd370..eaef0dc160 100644 --- a/neo/Network/P2P/Payloads/Header.cs +++ b/neo/Network/P2P/Payloads/Header.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.Ledger; using Neo.Wallets; using System; diff --git a/neo/Network/P2P/Payloads/HeadersPayload.cs b/neo/Network/P2P/Payloads/HeadersPayload.cs index 54948a142d..3b13405d24 100644 --- a/neo/Network/P2P/Payloads/HeadersPayload.cs +++ b/neo/Network/P2P/Payloads/HeadersPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System.Collections.Generic; using System.IO; using System.Linq; diff --git a/neo/Network/P2P/Payloads/IInventory.cs b/neo/Network/P2P/Payloads/IInventory.cs index dcf3114a8b..26b62346d9 100644 --- a/neo/Network/P2P/Payloads/IInventory.cs +++ b/neo/Network/P2P/Payloads/IInventory.cs @@ -1,4 +1,4 @@ -using Neo.Persistence; +using Neo.Persistence; namespace Neo.Network.P2P.Payloads { diff --git a/neo/Network/P2P/Payloads/IVerifiable.cs b/neo/Network/P2P/Payloads/IVerifiable.cs index 50651ad9ff..8540d8a626 100644 --- a/neo/Network/P2P/Payloads/IVerifiable.cs +++ b/neo/Network/P2P/Payloads/IVerifiable.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Persistence; using System.IO; diff --git a/neo/Network/P2P/Payloads/InvPayload.cs b/neo/Network/P2P/Payloads/InvPayload.cs index a3bc82a4d9..613d280234 100644 --- a/neo/Network/P2P/Payloads/InvPayload.cs +++ b/neo/Network/P2P/Payloads/InvPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.Collections.Generic; using System.IO; diff --git a/neo/Network/P2P/Payloads/InventoryType.cs b/neo/Network/P2P/Payloads/InventoryType.cs index 58ad12471b..775eed958f 100644 --- a/neo/Network/P2P/Payloads/InventoryType.cs +++ b/neo/Network/P2P/Payloads/InventoryType.cs @@ -1,4 +1,4 @@ -namespace Neo.Network.P2P.Payloads +namespace Neo.Network.P2P.Payloads { public enum InventoryType : byte { diff --git a/neo/Network/P2P/Payloads/MerkleBlockPayload.cs b/neo/Network/P2P/Payloads/MerkleBlockPayload.cs index 11b9fb3a6e..0d00434cd4 100644 --- a/neo/Network/P2P/Payloads/MerkleBlockPayload.cs +++ b/neo/Network/P2P/Payloads/MerkleBlockPayload.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using System.Collections; using System.IO; diff --git a/neo/Network/P2P/Payloads/NetworkAddressWithTime.cs b/neo/Network/P2P/Payloads/NetworkAddressWithTime.cs index 01508524a5..6fcda2f809 100644 --- a/neo/Network/P2P/Payloads/NetworkAddressWithTime.cs +++ b/neo/Network/P2P/Payloads/NetworkAddressWithTime.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Capabilities; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/PingPayload.cs b/neo/Network/P2P/Payloads/PingPayload.cs index 107dd501d5..680de9dd0a 100644 --- a/neo/Network/P2P/Payloads/PingPayload.cs +++ b/neo/Network/P2P/Payloads/PingPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/TransactionAttribute.cs b/neo/Network/P2P/Payloads/TransactionAttribute.cs index 99d1671ebd..5adc34db8e 100644 --- a/neo/Network/P2P/Payloads/TransactionAttribute.cs +++ b/neo/Network/P2P/Payloads/TransactionAttribute.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Json; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs b/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs index 89c1a1cec2..9bf5cc204c 100644 --- a/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs +++ b/neo/Network/P2P/Payloads/TransactionAttributeUsage.cs @@ -1,4 +1,4 @@ -namespace Neo.Network.P2P.Payloads +namespace Neo.Network.P2P.Payloads { public enum TransactionAttributeUsage : byte { diff --git a/neo/Network/P2P/Payloads/VersionPayload.cs b/neo/Network/P2P/Payloads/VersionPayload.cs index 754000e062..16c401b7db 100644 --- a/neo/Network/P2P/Payloads/VersionPayload.cs +++ b/neo/Network/P2P/Payloads/VersionPayload.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.Network.P2P.Capabilities; using System; using System.IO; diff --git a/neo/Network/P2P/Payloads/Witness.cs b/neo/Network/P2P/Payloads/Witness.cs index 52a2186ee8..227d810a39 100644 --- a/neo/Network/P2P/Payloads/Witness.cs +++ b/neo/Network/P2P/Payloads/Witness.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Json; using Neo.SmartContract; using Neo.VM; diff --git a/neo/Network/P2P/Payloads/WitnessScope.cs b/neo/Network/P2P/Payloads/WitnessScope.cs index e67706cbbf..f35e550a34 100644 --- a/neo/Network/P2P/Payloads/WitnessScope.cs +++ b/neo/Network/P2P/Payloads/WitnessScope.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.Network.P2P.Payloads { diff --git a/neo/Network/P2P/Peer.cs b/neo/Network/P2P/Peer.cs index eb21095685..0cbd6cbaff 100644 --- a/neo/Network/P2P/Peer.cs +++ b/neo/Network/P2P/Peer.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.IO; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; diff --git a/neo/Network/P2P/ProtocolHandler.cs b/neo/Network/P2P/ProtocolHandler.cs index 63ecbe3318..aa7f0e06f2 100644 --- a/neo/Network/P2P/ProtocolHandler.cs +++ b/neo/Network/P2P/ProtocolHandler.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Neo.Cryptography; using Neo.IO; diff --git a/neo/Network/P2P/RemoteNode.cs b/neo/Network/P2P/RemoteNode.cs index 7700c896b2..ec2a16e047 100644 --- a/neo/Network/P2P/RemoteNode.cs +++ b/neo/Network/P2P/RemoteNode.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Akka.IO; using Neo.Cryptography; diff --git a/neo/Network/P2P/TaskManager.cs b/neo/Network/P2P/TaskManager.cs index cd96547df8..2c0f7ae07b 100644 --- a/neo/Network/P2P/TaskManager.cs +++ b/neo/Network/P2P/TaskManager.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Akka.Configuration; using Neo.IO.Actors; using Neo.IO.Caching; diff --git a/neo/Network/P2P/TaskSession.cs b/neo/Network/P2P/TaskSession.cs index 5617e0efa1..a1cf8a0ffc 100644 --- a/neo/Network/P2P/TaskSession.cs +++ b/neo/Network/P2P/TaskSession.cs @@ -1,4 +1,4 @@ -using Akka.Actor; +using Akka.Actor; using Neo.Network.P2P.Capabilities; using Neo.Network.P2P.Payloads; using System; diff --git a/neo/Network/RPC/Models/RpcBlock.cs b/neo/Network/RPC/Models/RpcBlock.cs index 0d49b3b53a..f71af51168 100644 --- a/neo/Network/RPC/Models/RpcBlock.cs +++ b/neo/Network/RPC/Models/RpcBlock.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcBlockHeader.cs b/neo/Network/RPC/Models/RpcBlockHeader.cs index 250acfd818..2b9293ecaf 100644 --- a/neo/Network/RPC/Models/RpcBlockHeader.cs +++ b/neo/Network/RPC/Models/RpcBlockHeader.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcInvokeResult.cs b/neo/Network/RPC/Models/RpcInvokeResult.cs index 9df9492e2b..73f2c6a2af 100644 --- a/neo/Network/RPC/Models/RpcInvokeResult.cs +++ b/neo/Network/RPC/Models/RpcInvokeResult.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Newtonsoft.Json; using System.Linq; diff --git a/neo/Network/RPC/Models/RpcNep5Balances.cs b/neo/Network/RPC/Models/RpcNep5Balances.cs index f29f0c5564..b471ab4545 100644 --- a/neo/Network/RPC/Models/RpcNep5Balances.cs +++ b/neo/Network/RPC/Models/RpcNep5Balances.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; using System.Numerics; diff --git a/neo/Network/RPC/Models/RpcPeers.cs b/neo/Network/RPC/Models/RpcPeers.cs index 5caa99a66a..fac73842de 100644 --- a/neo/Network/RPC/Models/RpcPeers.cs +++ b/neo/Network/RPC/Models/RpcPeers.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcPlugin.cs b/neo/Network/RPC/Models/RpcPlugin.cs index ae778ee87a..db03f70eb3 100644 --- a/neo/Network/RPC/Models/RpcPlugin.cs +++ b/neo/Network/RPC/Models/RpcPlugin.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcRawMemPool.cs b/neo/Network/RPC/Models/RpcRawMemPool.cs index df439bf3a6..c5ebd63419 100644 --- a/neo/Network/RPC/Models/RpcRawMemPool.cs +++ b/neo/Network/RPC/Models/RpcRawMemPool.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcRequest.cs b/neo/Network/RPC/Models/RpcRequest.cs index 010e3037b8..1970adedbf 100644 --- a/neo/Network/RPC/Models/RpcRequest.cs +++ b/neo/Network/RPC/Models/RpcRequest.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcResponse.cs b/neo/Network/RPC/Models/RpcResponse.cs index ff20200519..e4ebcaed1b 100644 --- a/neo/Network/RPC/Models/RpcResponse.cs +++ b/neo/Network/RPC/Models/RpcResponse.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; namespace Neo.Network.RPC.Models { diff --git a/neo/Network/RPC/Models/RpcTransaction.cs b/neo/Network/RPC/Models/RpcTransaction.cs index 3e45830ae6..f41c04710a 100644 --- a/neo/Network/RPC/Models/RpcTransaction.cs +++ b/neo/Network/RPC/Models/RpcTransaction.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.Network.P2P.Payloads; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcValidateAddressResult.cs b/neo/Network/RPC/Models/RpcValidateAddressResult.cs index f33467356e..5e0a704797 100644 --- a/neo/Network/RPC/Models/RpcValidateAddressResult.cs +++ b/neo/Network/RPC/Models/RpcValidateAddressResult.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; namespace Neo.Network.RPC.Models { diff --git a/neo/Network/RPC/Models/RpcValidator.cs b/neo/Network/RPC/Models/RpcValidator.cs index b694a6dfcd..f3116ed2e4 100644 --- a/neo/Network/RPC/Models/RpcValidator.cs +++ b/neo/Network/RPC/Models/RpcValidator.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Numerics; namespace Neo.Network.RPC.Models diff --git a/neo/Network/RPC/Models/RpcVersion.cs b/neo/Network/RPC/Models/RpcVersion.cs index 02f4dc3407..8163875b64 100644 --- a/neo/Network/RPC/Models/RpcVersion.cs +++ b/neo/Network/RPC/Models/RpcVersion.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; namespace Neo.Network.RPC.Models { diff --git a/neo/Network/RPC/RpcClient.cs b/neo/Network/RPC/RpcClient.cs index 4b968163c7..69352b8cfd 100644 --- a/neo/Network/RPC/RpcClient.cs +++ b/neo/Network/RPC/RpcClient.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.Ledger; using Neo.Network.RPC.Models; using System; diff --git a/neo/Network/RPC/RpcException.cs b/neo/Network/RPC/RpcException.cs index 5a2120f083..b5030750ca 100644 --- a/neo/Network/RPC/RpcException.cs +++ b/neo/Network/RPC/RpcException.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.Network.RPC { diff --git a/neo/Persistence/CloneSnapshot.cs b/neo/Persistence/CloneSnapshot.cs index 9f86f2a1bf..0b79bd2739 100644 --- a/neo/Persistence/CloneSnapshot.cs +++ b/neo/Persistence/CloneSnapshot.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Wrappers; using Neo.Ledger; diff --git a/neo/Persistence/Helper.cs b/neo/Persistence/Helper.cs index d884e0da6b..7f412e47d3 100644 --- a/neo/Persistence/Helper.cs +++ b/neo/Persistence/Helper.cs @@ -1,4 +1,4 @@ -using Neo.Ledger; +using Neo.Ledger; using Neo.Network.P2P.Payloads; namespace Neo.Persistence diff --git a/neo/Persistence/IPersistence.cs b/neo/Persistence/IPersistence.cs index 34f1169f9b..0632b5d0fa 100644 --- a/neo/Persistence/IPersistence.cs +++ b/neo/Persistence/IPersistence.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Wrappers; using Neo.Ledger; diff --git a/neo/Persistence/LevelDB/DbCache.cs b/neo/Persistence/LevelDB/DbCache.cs index 86ff7a39ea..ae55b31326 100644 --- a/neo/Persistence/LevelDB/DbCache.cs +++ b/neo/Persistence/LevelDB/DbCache.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Caching; using Neo.IO.Data.LevelDB; using System; diff --git a/neo/Persistence/LevelDB/DbMetaDataCache.cs b/neo/Persistence/LevelDB/DbMetaDataCache.cs index e2c03ca2fd..0163d84e39 100644 --- a/neo/Persistence/LevelDB/DbMetaDataCache.cs +++ b/neo/Persistence/LevelDB/DbMetaDataCache.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Caching; using Neo.IO.Data.LevelDB; using System; diff --git a/neo/Persistence/LevelDB/DbSnapshot.cs b/neo/Persistence/LevelDB/DbSnapshot.cs index f7ade52ad8..365584fa7c 100644 --- a/neo/Persistence/LevelDB/DbSnapshot.cs +++ b/neo/Persistence/LevelDB/DbSnapshot.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Data.LevelDB; using Neo.IO.Wrappers; using Neo.Ledger; diff --git a/neo/Persistence/LevelDB/LevelDBStore.cs b/neo/Persistence/LevelDB/LevelDBStore.cs index 189f0cfbb5..bb6ac26698 100644 --- a/neo/Persistence/LevelDB/LevelDBStore.cs +++ b/neo/Persistence/LevelDB/LevelDBStore.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Data.LevelDB; using Neo.IO.Wrappers; using Neo.Ledger; diff --git a/neo/Persistence/LevelDB/Prefixes.cs b/neo/Persistence/LevelDB/Prefixes.cs index 605e9f1451..f40359a55a 100644 --- a/neo/Persistence/LevelDB/Prefixes.cs +++ b/neo/Persistence/LevelDB/Prefixes.cs @@ -1,4 +1,4 @@ -namespace Neo.Persistence.LevelDB +namespace Neo.Persistence.LevelDB { internal static class Prefixes { diff --git a/neo/Persistence/Snapshot.cs b/neo/Persistence/Snapshot.cs index f058562200..1e900800b0 100644 --- a/neo/Persistence/Snapshot.cs +++ b/neo/Persistence/Snapshot.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Wrappers; using Neo.Ledger; using Neo.Network.P2P.Payloads; diff --git a/neo/Persistence/Store.cs b/neo/Persistence/Store.cs index 7b5b3b6435..3dc7127f3a 100644 --- a/neo/Persistence/Store.cs +++ b/neo/Persistence/Store.cs @@ -1,4 +1,4 @@ -using Neo.IO.Caching; +using Neo.IO.Caching; using Neo.IO.Wrappers; using Neo.Ledger; diff --git a/neo/Plugins/ILogPlugin.cs b/neo/Plugins/ILogPlugin.cs index ff1052be2e..c0733f9143 100644 --- a/neo/Plugins/ILogPlugin.cs +++ b/neo/Plugins/ILogPlugin.cs @@ -1,4 +1,4 @@ -namespace Neo.Plugins +namespace Neo.Plugins { public interface ILogPlugin { diff --git a/neo/Plugins/IMemoryPoolTxObserverPlugin.cs b/neo/Plugins/IMemoryPoolTxObserverPlugin.cs index e596b9a7b5..3dd1cb3ef2 100644 --- a/neo/Plugins/IMemoryPoolTxObserverPlugin.cs +++ b/neo/Plugins/IMemoryPoolTxObserverPlugin.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using Neo.Network.P2P.Payloads; namespace Neo.Plugins diff --git a/neo/Plugins/IP2PPlugin.cs b/neo/Plugins/IP2PPlugin.cs index 3029aaf849..e2043104fc 100644 --- a/neo/Plugins/IP2PPlugin.cs +++ b/neo/Plugins/IP2PPlugin.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P; +using Neo.Network.P2P; using Neo.Network.P2P.Payloads; namespace Neo.Plugins diff --git a/neo/Plugins/IPersistencePlugin.cs b/neo/Plugins/IPersistencePlugin.cs index af3cbe05b8..0f06ae51eb 100644 --- a/neo/Plugins/IPersistencePlugin.cs +++ b/neo/Plugins/IPersistencePlugin.cs @@ -1,4 +1,4 @@ -using System; +using System; using Neo.Persistence; using System.Collections.Generic; using static Neo.Ledger.Blockchain; diff --git a/neo/Plugins/IRpcPlugin.cs b/neo/Plugins/IRpcPlugin.cs index 19e5b71808..92e7a0fa48 100644 --- a/neo/Plugins/IRpcPlugin.cs +++ b/neo/Plugins/IRpcPlugin.cs @@ -1,4 +1,4 @@ -using Microsoft.AspNetCore.Http; +using Microsoft.AspNetCore.Http; using Neo.IO.Json; namespace Neo.Plugins diff --git a/neo/Plugins/LogLevel.cs b/neo/Plugins/LogLevel.cs index 72158c8aad..8f6e0b9df7 100644 --- a/neo/Plugins/LogLevel.cs +++ b/neo/Plugins/LogLevel.cs @@ -1,4 +1,4 @@ -namespace Neo.Plugins +namespace Neo.Plugins { public enum LogLevel : byte { diff --git a/neo/Plugins/MemoryPoolTxRemovalReason.cs b/neo/Plugins/MemoryPoolTxRemovalReason.cs index f7320dc60e..d08a37eba2 100644 --- a/neo/Plugins/MemoryPoolTxRemovalReason.cs +++ b/neo/Plugins/MemoryPoolTxRemovalReason.cs @@ -1,4 +1,4 @@ -namespace Neo.Plugins +namespace Neo.Plugins { public enum MemoryPoolTxRemovalReason : byte { diff --git a/neo/Plugins/Plugin.cs b/neo/Plugins/Plugin.cs index 72c7ce3b14..aa04b0778d 100644 --- a/neo/Plugins/Plugin.cs +++ b/neo/Plugins/Plugin.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using System; using System.Collections.Generic; using System.IO; diff --git a/neo/ProtocolSettings.cs b/neo/ProtocolSettings.cs index 381e56c8a7..18c915d614 100644 --- a/neo/ProtocolSettings.cs +++ b/neo/ProtocolSettings.cs @@ -1,4 +1,4 @@ -using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Configuration; using System; using System.Linq; using System.Threading; diff --git a/neo/SmartContract/ApplicationEngine.OpCodePrices.cs b/neo/SmartContract/ApplicationEngine.OpCodePrices.cs index 9da0f6c75d..271a76f935 100644 --- a/neo/SmartContract/ApplicationEngine.OpCodePrices.cs +++ b/neo/SmartContract/ApplicationEngine.OpCodePrices.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System.Collections.Generic; namespace Neo.SmartContract diff --git a/neo/SmartContract/ApplicationEngine.cs b/neo/SmartContract/ApplicationEngine.cs index 45763ed30a..2eeeef52e0 100644 --- a/neo/SmartContract/ApplicationEngine.cs +++ b/neo/SmartContract/ApplicationEngine.cs @@ -49,16 +49,16 @@ private bool AddGas(long gas) return testMode || GasConsumed <= gas_amount; } - protected override void LoadContext(ExecutionContext context) - { - // Set default execution context state - - context.SetState(new ExecutionContextState() - { - ScriptHash = ((byte[])context.Script).ToScriptHash() - }); - - base.LoadContext(context); + protected override void LoadContext(ExecutionContext context) + { + // Set default execution context state + + context.SetState(new ExecutionContextState() + { + ScriptHash = ((byte[])context.Script).ToScriptHash() + }); + + base.LoadContext(context); } public override void Dispose() diff --git a/neo/SmartContract/ContainerPlaceholder.cs b/neo/SmartContract/ContainerPlaceholder.cs index 14e97ae848..a379ddd9d3 100644 --- a/neo/SmartContract/ContainerPlaceholder.cs +++ b/neo/SmartContract/ContainerPlaceholder.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System; namespace Neo.SmartContract diff --git a/neo/SmartContract/Contract.cs b/neo/SmartContract/Contract.cs index 8d23997006..19fcceb7ca 100644 --- a/neo/SmartContract/Contract.cs +++ b/neo/SmartContract/Contract.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.VM; using Neo.Wallets; using System; diff --git a/neo/SmartContract/ContractParameter.cs b/neo/SmartContract/ContractParameter.cs index 5e78005e13..cae59229b8 100644 --- a/neo/SmartContract/ContractParameter.cs +++ b/neo/SmartContract/ContractParameter.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.IO.Json; using System; using System.Collections.Generic; diff --git a/neo/SmartContract/ContractParameterType.cs b/neo/SmartContract/ContractParameterType.cs index 67191852fa..748ff86654 100644 --- a/neo/SmartContract/ContractParameterType.cs +++ b/neo/SmartContract/ContractParameterType.cs @@ -1,4 +1,4 @@ -namespace Neo.SmartContract +namespace Neo.SmartContract { public enum ContractParameterType : byte { diff --git a/neo/SmartContract/ContractParametersContext.cs b/neo/SmartContract/ContractParametersContext.cs index 35a2c36898..8a91c936b8 100644 --- a/neo/SmartContract/ContractParametersContext.cs +++ b/neo/SmartContract/ContractParametersContext.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.IO.Json; using Neo.Ledger; using Neo.Network.P2P.Payloads; @@ -72,14 +72,14 @@ public bool Completed } } - /// - /// Cache for public ScriptHashes field + /// + /// Cache for public ScriptHashes field /// private UInt160[] _ScriptHashes = null; - /// - /// ScriptHashes are the verifiable ScriptHashes from Verifiable element - /// Equivalent to: Verifiable.GetScriptHashesForVerifying(Blockchain.Singleton.GetSnapshot()) + /// + /// ScriptHashes are the verifiable ScriptHashes from Verifiable element + /// Equivalent to: Verifiable.GetScriptHashesForVerifying(Blockchain.Singleton.GetSnapshot()) /// public IReadOnlyList ScriptHashes { diff --git a/neo/SmartContract/Enumerators/ConcatenatedEnumerator.cs b/neo/SmartContract/Enumerators/ConcatenatedEnumerator.cs index 36e8c4fe97..2b75b1d46b 100644 --- a/neo/SmartContract/Enumerators/ConcatenatedEnumerator.cs +++ b/neo/SmartContract/Enumerators/ConcatenatedEnumerator.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; namespace Neo.SmartContract.Enumerators { diff --git a/neo/SmartContract/Enumerators/IEnumerator.cs b/neo/SmartContract/Enumerators/IEnumerator.cs index 27e30b5e18..4d1f11fe65 100644 --- a/neo/SmartContract/Enumerators/IEnumerator.cs +++ b/neo/SmartContract/Enumerators/IEnumerator.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System; namespace Neo.SmartContract.Enumerators diff --git a/neo/SmartContract/Enumerators/IteratorKeysWrapper.cs b/neo/SmartContract/Enumerators/IteratorKeysWrapper.cs index ef2e49d49f..d134eb884c 100644 --- a/neo/SmartContract/Enumerators/IteratorKeysWrapper.cs +++ b/neo/SmartContract/Enumerators/IteratorKeysWrapper.cs @@ -1,4 +1,4 @@ -using Neo.SmartContract.Iterators; +using Neo.SmartContract.Iterators; using Neo.VM; namespace Neo.SmartContract.Enumerators diff --git a/neo/SmartContract/Enumerators/IteratorValuesWrapper.cs b/neo/SmartContract/Enumerators/IteratorValuesWrapper.cs index fb69070d40..15e06f2223 100644 --- a/neo/SmartContract/Enumerators/IteratorValuesWrapper.cs +++ b/neo/SmartContract/Enumerators/IteratorValuesWrapper.cs @@ -1,4 +1,4 @@ -using Neo.SmartContract.Iterators; +using Neo.SmartContract.Iterators; using Neo.VM; namespace Neo.SmartContract.Enumerators diff --git a/neo/SmartContract/ExecutionContextState.cs b/neo/SmartContract/ExecutionContextState.cs index 7895d943a2..11e6f88a00 100644 --- a/neo/SmartContract/ExecutionContextState.cs +++ b/neo/SmartContract/ExecutionContextState.cs @@ -1,10 +1,10 @@ -namespace Neo.SmartContract -{ - public class ExecutionContextState - { - /// - /// Script hash - /// - public UInt160 ScriptHash { get; set; } - } +namespace Neo.SmartContract +{ + public class ExecutionContextState + { + /// + /// Script hash + /// + public UInt160 ScriptHash { get; set; } + } } \ No newline at end of file diff --git a/neo/SmartContract/Helper.cs b/neo/SmartContract/Helper.cs index 259e997b09..6a22249cd7 100644 --- a/neo/SmartContract/Helper.cs +++ b/neo/SmartContract/Helper.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using Neo.Network.P2P.Payloads; using Neo.Persistence; diff --git a/neo/SmartContract/InteropDescriptor.cs b/neo/SmartContract/InteropDescriptor.cs index c283e474de..6db599ea64 100644 --- a/neo/SmartContract/InteropDescriptor.cs +++ b/neo/SmartContract/InteropDescriptor.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System; namespace Neo.SmartContract diff --git a/neo/SmartContract/InteropService.NEO.cs b/neo/SmartContract/InteropService.NEO.cs index 91b941649f..7f0d857fe9 100644 --- a/neo/SmartContract/InteropService.NEO.cs +++ b/neo/SmartContract/InteropService.NEO.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO.Json; using Neo.Ledger; using Neo.Network.P2P; diff --git a/neo/SmartContract/InteropService.cs b/neo/SmartContract/InteropService.cs index 9fbb5c6675..b4121d7a24 100644 --- a/neo/SmartContract/InteropService.cs +++ b/neo/SmartContract/InteropService.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO; using Neo.Ledger; diff --git a/neo/SmartContract/Iterators/ArrayWrapper.cs b/neo/SmartContract/Iterators/ArrayWrapper.cs index 3284f1317f..883327bee0 100644 --- a/neo/SmartContract/Iterators/ArrayWrapper.cs +++ b/neo/SmartContract/Iterators/ArrayWrapper.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System; using System.Collections.Generic; diff --git a/neo/SmartContract/Iterators/IIterator.cs b/neo/SmartContract/Iterators/IIterator.cs index ca67ae0331..3438286615 100644 --- a/neo/SmartContract/Iterators/IIterator.cs +++ b/neo/SmartContract/Iterators/IIterator.cs @@ -1,4 +1,4 @@ -using Neo.SmartContract.Enumerators; +using Neo.SmartContract.Enumerators; using Neo.VM; namespace Neo.SmartContract.Iterators diff --git a/neo/SmartContract/Iterators/MapWrapper.cs b/neo/SmartContract/Iterators/MapWrapper.cs index d42f940fac..343b946982 100644 --- a/neo/SmartContract/Iterators/MapWrapper.cs +++ b/neo/SmartContract/Iterators/MapWrapper.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System.Collections.Generic; namespace Neo.SmartContract.Iterators diff --git a/neo/SmartContract/Iterators/StorageIterator.cs b/neo/SmartContract/Iterators/StorageIterator.cs index 2dd604d5d8..45c9d21ebd 100644 --- a/neo/SmartContract/Iterators/StorageIterator.cs +++ b/neo/SmartContract/Iterators/StorageIterator.cs @@ -1,4 +1,4 @@ -using Neo.Ledger; +using Neo.Ledger; using Neo.VM; using System.Collections.Generic; diff --git a/neo/SmartContract/JsonSerializer.cs b/neo/SmartContract/JsonSerializer.cs index d635c6c7b8..a4853fc39a 100644 --- a/neo/SmartContract/JsonSerializer.cs +++ b/neo/SmartContract/JsonSerializer.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.VM; using Neo.VM.Types; using System; diff --git a/neo/SmartContract/LogEventArgs.cs b/neo/SmartContract/LogEventArgs.cs index d124b6f9ab..8c007fe101 100644 --- a/neo/SmartContract/LogEventArgs.cs +++ b/neo/SmartContract/LogEventArgs.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P.Payloads; +using Neo.Network.P2P.Payloads; using System; namespace Neo.SmartContract diff --git a/neo/SmartContract/Manifest/ContractAbi.cs b/neo/SmartContract/Manifest/ContractAbi.cs index 033306f8e6..1d27ae4f1b 100644 --- a/neo/SmartContract/Manifest/ContractAbi.cs +++ b/neo/SmartContract/Manifest/ContractAbi.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.SmartContract.Manifest diff --git a/neo/SmartContract/Manifest/ContractEventDescriptor.cs b/neo/SmartContract/Manifest/ContractEventDescriptor.cs index b06b64f341..00748f9b09 100644 --- a/neo/SmartContract/Manifest/ContractEventDescriptor.cs +++ b/neo/SmartContract/Manifest/ContractEventDescriptor.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System.Linq; namespace Neo.SmartContract.Manifest diff --git a/neo/SmartContract/Manifest/ContractFeatures.cs b/neo/SmartContract/Manifest/ContractFeatures.cs index dd8336f695..9f94a9d3f1 100644 --- a/neo/SmartContract/Manifest/ContractFeatures.cs +++ b/neo/SmartContract/Manifest/ContractFeatures.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.SmartContract.Manifest { diff --git a/neo/SmartContract/Manifest/ContractGroup.cs b/neo/SmartContract/Manifest/ContractGroup.cs index fd73787a09..75359e782a 100644 --- a/neo/SmartContract/Manifest/ContractGroup.cs +++ b/neo/SmartContract/Manifest/ContractGroup.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.Cryptography.ECC; using Neo.IO.Json; diff --git a/neo/SmartContract/Manifest/ContractManifest.cs b/neo/SmartContract/Manifest/ContractManifest.cs index 967a10e856..ebbcd61f2c 100644 --- a/neo/SmartContract/Manifest/ContractManifest.cs +++ b/neo/SmartContract/Manifest/ContractManifest.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.IO.Json; using System.IO; using System.Linq; diff --git a/neo/SmartContract/Manifest/ContractMethodDescriptor.cs b/neo/SmartContract/Manifest/ContractMethodDescriptor.cs index c631aa0450..476ec546a6 100644 --- a/neo/SmartContract/Manifest/ContractMethodDescriptor.cs +++ b/neo/SmartContract/Manifest/ContractMethodDescriptor.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System; using System.Linq; diff --git a/neo/SmartContract/Manifest/ContractParameterDefinition.cs b/neo/SmartContract/Manifest/ContractParameterDefinition.cs index af07315a3a..3f184d6ba8 100644 --- a/neo/SmartContract/Manifest/ContractParameterDefinition.cs +++ b/neo/SmartContract/Manifest/ContractParameterDefinition.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System; namespace Neo.SmartContract.Manifest diff --git a/neo/SmartContract/Manifest/ContractPermission.cs b/neo/SmartContract/Manifest/ContractPermission.cs index b7d1d54bb9..890de9d200 100644 --- a/neo/SmartContract/Manifest/ContractPermission.cs +++ b/neo/SmartContract/Manifest/ContractPermission.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System; using System.Linq; diff --git a/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs b/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs index 7b64a66935..909ae27e42 100644 --- a/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs +++ b/neo/SmartContract/Manifest/ContractPermissionDescriptor.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.IO.Json; using System; diff --git a/neo/SmartContract/Manifest/WildCardContainer.cs b/neo/SmartContract/Manifest/WildCardContainer.cs index aab6ba838e..12dbac60fe 100644 --- a/neo/SmartContract/Manifest/WildCardContainer.cs +++ b/neo/SmartContract/Manifest/WildCardContainer.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System; using System.Collections; using System.Collections.Generic; diff --git a/neo/SmartContract/Native/ContractMethodAttribute.cs b/neo/SmartContract/Native/ContractMethodAttribute.cs index 393737d92e..42b414eed6 100644 --- a/neo/SmartContract/Native/ContractMethodAttribute.cs +++ b/neo/SmartContract/Native/ContractMethodAttribute.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.SmartContract.Native { diff --git a/neo/SmartContract/Native/ContractMethodMetadata.cs b/neo/SmartContract/Native/ContractMethodMetadata.cs index f63344eec9..9267bb7db9 100644 --- a/neo/SmartContract/Native/ContractMethodMetadata.cs +++ b/neo/SmartContract/Native/ContractMethodMetadata.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using System; using VMArray = Neo.VM.Types.Array; diff --git a/neo/SmartContract/Native/NativeContract.cs b/neo/SmartContract/Native/NativeContract.cs index 08971dcf6b..546743fc49 100644 --- a/neo/SmartContract/Native/NativeContract.cs +++ b/neo/SmartContract/Native/NativeContract.cs @@ -1,4 +1,4 @@ -#pragma warning disable IDE0060 +#pragma warning disable IDE0060 using Neo.IO; using Neo.Ledger; diff --git a/neo/SmartContract/Native/PolicyContract.cs b/neo/SmartContract/Native/PolicyContract.cs index c5820cfd15..3ffe8199e5 100644 --- a/neo/SmartContract/Native/PolicyContract.cs +++ b/neo/SmartContract/Native/PolicyContract.cs @@ -1,4 +1,4 @@ -#pragma warning disable IDE0051 +#pragma warning disable IDE0051 #pragma warning disable IDE0060 using Neo.IO; diff --git a/neo/SmartContract/Native/Tokens/GasToken.cs b/neo/SmartContract/Native/Tokens/GasToken.cs index fd39979670..7ef522dab7 100644 --- a/neo/SmartContract/Native/Tokens/GasToken.cs +++ b/neo/SmartContract/Native/Tokens/GasToken.cs @@ -1,4 +1,4 @@ -#pragma warning disable IDE0051 +#pragma warning disable IDE0051 using Neo.Cryptography.ECC; using Neo.Ledger; diff --git a/neo/SmartContract/Native/Tokens/Nep5AccountState.cs b/neo/SmartContract/Native/Tokens/Nep5AccountState.cs index c775f044ec..aa62cf4bec 100644 --- a/neo/SmartContract/Native/Tokens/Nep5AccountState.cs +++ b/neo/SmartContract/Native/Tokens/Nep5AccountState.cs @@ -1,4 +1,4 @@ -using Neo.VM; +using Neo.VM; using Neo.VM.Types; using System.Numerics; diff --git a/neo/SmartContract/Native/Tokens/Nep5Token.cs b/neo/SmartContract/Native/Tokens/Nep5Token.cs index 6a2e1c78b3..a95885a665 100644 --- a/neo/SmartContract/Native/Tokens/Nep5Token.cs +++ b/neo/SmartContract/Native/Tokens/Nep5Token.cs @@ -1,4 +1,4 @@ -#pragma warning disable IDE0060 +#pragma warning disable IDE0060 using Neo.Ledger; using Neo.Persistence; diff --git a/neo/SmartContract/NefFile.cs b/neo/SmartContract/NefFile.cs index 52507eda08..e0068b7213 100644 --- a/neo/SmartContract/NefFile.cs +++ b/neo/SmartContract/NefFile.cs @@ -1,129 +1,129 @@ -using Neo.Cryptography; -using Neo.IO; -using System; -using System.IO; - -namespace Neo.SmartContract -{ - /// - /// +------------+-----------+------------------------------------------------------------+ - /// | Field | Length | Comment | - /// +------------+-----------+------------------------------------------------------------+ - /// | Magic | 4 bytes | Magic header | - /// | Compiler | 32 bytes | Compiler used | - /// | Version | 16 bytes | Compiler version (Mayor, Minor, Build, Version) | - /// | ScriptHash | 20 bytes | ScriptHash for the script | - /// +------------+-----------+------------------------------------------------------------+ - /// | Checksum | 4 bytes | Sha256 of the header (CRC) | - /// +------------+-----------+------------------------------------------------------------+ - /// | Script | Var bytes | Var bytes for the payload | - /// +------------+-----------+------------------------------------------------------------+ - /// - public class NefFile : ISerializable - { - /// - /// NEO Executable Format 3 (NEF3) - /// - private const uint Magic = 0x3346454E; - - /// - /// Compiler - /// - public string Compiler { get; set; } - - /// - /// Version - /// - public Version Version { get; set; } - - /// - /// Script Hash - /// - public UInt160 ScriptHash { get; set; } - - /// - /// Checksum - /// - public uint CheckSum { get; set; } - - /// - /// Script - /// - public byte[] Script { get; set; } - - private const int HeaderSize = - sizeof(uint) + // Magic - 32 + // Compiler - (sizeof(int) * 4) + // Version - UInt160.Length + // ScriptHash - sizeof(uint); // Checksum - - public int Size => - HeaderSize + // Header - Script.GetVarSize(); // Script - - public void Serialize(BinaryWriter writer) - { - writer.Write(Magic); - writer.WriteFixedString(Compiler, 32); - - // Version - writer.Write(Version.Major); - writer.Write(Version.Minor); - writer.Write(Version.Build); - writer.Write(Version.Revision); - - writer.Write(ScriptHash); - writer.Write(CheckSum); - writer.WriteVarBytes(Script ?? new byte[0]); - } - - public void Deserialize(BinaryReader reader) - { - if (reader.ReadUInt32() != Magic) - { - throw new FormatException("Wrong magic"); - } - - Compiler = reader.ReadFixedString(32); - Version = new Version(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); - ScriptHash = reader.ReadSerializable(); - CheckSum = reader.ReadUInt32(); - - if (CheckSum != ComputeChecksum(this)) - { - throw new FormatException("CRC verification fail"); - } - - Script = reader.ReadVarBytes(1024 * 1024); - - if (Script.ToScriptHash() != ScriptHash) - { - throw new FormatException("ScriptHash is different"); - } - } - - /// - /// Compute checksum for a file - /// - /// File - /// Return checksum - public static uint ComputeChecksum(NefFile file) - { - using (var ms = new MemoryStream()) - using (var wr = new BinaryWriter(ms)) - { - file.Serialize(wr); - wr.Flush(); - - // Read header without CRC - - var buffer = new byte[HeaderSize - sizeof(uint)]; - ms.Seek(0, SeekOrigin.Begin); - ms.Read(buffer, 0, buffer.Length); - - return BitConverter.ToUInt32(buffer.Sha256(), 0); - } - } - } -} +using Neo.Cryptography; +using Neo.IO; +using System; +using System.IO; + +namespace Neo.SmartContract +{ + /// + /// +------------+-----------+------------------------------------------------------------+ + /// | Field | Length | Comment | + /// +------------+-----------+------------------------------------------------------------+ + /// | Magic | 4 bytes | Magic header | + /// | Compiler | 32 bytes | Compiler used | + /// | Version | 16 bytes | Compiler version (Mayor, Minor, Build, Version) | + /// | ScriptHash | 20 bytes | ScriptHash for the script | + /// +------------+-----------+------------------------------------------------------------+ + /// | Checksum | 4 bytes | Sha256 of the header (CRC) | + /// +------------+-----------+------------------------------------------------------------+ + /// | Script | Var bytes | Var bytes for the payload | + /// +------------+-----------+------------------------------------------------------------+ + /// + public class NefFile : ISerializable + { + /// + /// NEO Executable Format 3 (NEF3) + /// + private const uint Magic = 0x3346454E; + + /// + /// Compiler + /// + public string Compiler { get; set; } + + /// + /// Version + /// + public Version Version { get; set; } + + /// + /// Script Hash + /// + public UInt160 ScriptHash { get; set; } + + /// + /// Checksum + /// + public uint CheckSum { get; set; } + + /// + /// Script + /// + public byte[] Script { get; set; } + + private const int HeaderSize = + sizeof(uint) + // Magic + 32 + // Compiler + (sizeof(int) * 4) + // Version + UInt160.Length + // ScriptHash + sizeof(uint); // Checksum + + public int Size => + HeaderSize + // Header + Script.GetVarSize(); // Script + + public void Serialize(BinaryWriter writer) + { + writer.Write(Magic); + writer.WriteFixedString(Compiler, 32); + + // Version + writer.Write(Version.Major); + writer.Write(Version.Minor); + writer.Write(Version.Build); + writer.Write(Version.Revision); + + writer.Write(ScriptHash); + writer.Write(CheckSum); + writer.WriteVarBytes(Script ?? new byte[0]); + } + + public void Deserialize(BinaryReader reader) + { + if (reader.ReadUInt32() != Magic) + { + throw new FormatException("Wrong magic"); + } + + Compiler = reader.ReadFixedString(32); + Version = new Version(reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32(), reader.ReadInt32()); + ScriptHash = reader.ReadSerializable(); + CheckSum = reader.ReadUInt32(); + + if (CheckSum != ComputeChecksum(this)) + { + throw new FormatException("CRC verification fail"); + } + + Script = reader.ReadVarBytes(1024 * 1024); + + if (Script.ToScriptHash() != ScriptHash) + { + throw new FormatException("ScriptHash is different"); + } + } + + /// + /// Compute checksum for a file + /// + /// File + /// Return checksum + public static uint ComputeChecksum(NefFile file) + { + using (var ms = new MemoryStream()) + using (var wr = new BinaryWriter(ms)) + { + file.Serialize(wr); + wr.Flush(); + + // Read header without CRC + + var buffer = new byte[HeaderSize - sizeof(uint)]; + ms.Seek(0, SeekOrigin.Begin); + ms.Read(buffer, 0, buffer.Length); + + return BitConverter.ToUInt32(buffer.Sha256(), 0); + } + } + } +} diff --git a/neo/SmartContract/NotifyEventArgs.cs b/neo/SmartContract/NotifyEventArgs.cs index f4e4e169b8..8fab961408 100644 --- a/neo/SmartContract/NotifyEventArgs.cs +++ b/neo/SmartContract/NotifyEventArgs.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P.Payloads; +using Neo.Network.P2P.Payloads; using Neo.VM; using System; diff --git a/neo/SmartContract/StackItemType.cs b/neo/SmartContract/StackItemType.cs index 94ee4f23ba..b47999e157 100644 --- a/neo/SmartContract/StackItemType.cs +++ b/neo/SmartContract/StackItemType.cs @@ -1,4 +1,4 @@ -namespace Neo.SmartContract +namespace Neo.SmartContract { internal enum StackItemType : byte { diff --git a/neo/SmartContract/StorageContext.cs b/neo/SmartContract/StorageContext.cs index 1c3336c9ac..abea2e343d 100644 --- a/neo/SmartContract/StorageContext.cs +++ b/neo/SmartContract/StorageContext.cs @@ -1,4 +1,4 @@ -namespace Neo.SmartContract +namespace Neo.SmartContract { internal class StorageContext { diff --git a/neo/SmartContract/WitnessWrapper.cs b/neo/SmartContract/WitnessWrapper.cs index f67690cad5..28019be0c2 100644 --- a/neo/SmartContract/WitnessWrapper.cs +++ b/neo/SmartContract/WitnessWrapper.cs @@ -1,4 +1,4 @@ -using Neo.Network.P2P.Payloads; +using Neo.Network.P2P.Payloads; using Neo.Persistence; using System.Linq; diff --git a/neo/UInt160.cs b/neo/UInt160.cs index 0c6bea4b5a..0052d45569 100644 --- a/neo/UInt160.cs +++ b/neo/UInt160.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Linq; diff --git a/neo/UInt256.cs b/neo/UInt256.cs index ec79ae21ea..72719f0e90 100644 --- a/neo/UInt256.cs +++ b/neo/UInt256.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Globalization; using System.Linq; diff --git a/neo/UIntBase.cs b/neo/UIntBase.cs index 22431c4cae..af26e36d0a 100644 --- a/neo/UIntBase.cs +++ b/neo/UIntBase.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using System; using System.IO; using System.Linq; diff --git a/neo/VM/Helper.cs b/neo/VM/Helper.cs index 6a7a37d7d5..e996463e3f 100644 --- a/neo/VM/Helper.cs +++ b/neo/VM/Helper.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography.ECC; +using Neo.Cryptography.ECC; using Neo.IO; using Neo.SmartContract; using Neo.VM.Types; diff --git a/neo/Wallets/AssetDescriptor.cs b/neo/Wallets/AssetDescriptor.cs index 49144834bb..dca0b10b25 100644 --- a/neo/Wallets/AssetDescriptor.cs +++ b/neo/Wallets/AssetDescriptor.cs @@ -1,4 +1,4 @@ -using Neo.SmartContract; +using Neo.SmartContract; using Neo.VM; using System; diff --git a/neo/Wallets/Helper.cs b/neo/Wallets/Helper.cs index 4b26982db1..5960876fe2 100644 --- a/neo/Wallets/Helper.cs +++ b/neo/Wallets/Helper.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.Network.P2P; using Neo.Network.P2P.Payloads; using System; diff --git a/neo/Wallets/KeyPair.cs b/neo/Wallets/KeyPair.cs index 0125d10f99..afea8e822a 100644 --- a/neo/Wallets/KeyPair.cs +++ b/neo/Wallets/KeyPair.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.SmartContract; using System; using System.Linq; diff --git a/neo/Wallets/NEP6/NEP6Account.cs b/neo/Wallets/NEP6/NEP6Account.cs index ddeace2523..990612d542 100644 --- a/neo/Wallets/NEP6/NEP6Account.cs +++ b/neo/Wallets/NEP6/NEP6Account.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using System; namespace Neo.Wallets.NEP6 diff --git a/neo/Wallets/NEP6/NEP6Contract.cs b/neo/Wallets/NEP6/NEP6Contract.cs index a3dd36f414..45f0b5e157 100644 --- a/neo/Wallets/NEP6/NEP6Contract.cs +++ b/neo/Wallets/NEP6/NEP6Contract.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.SmartContract; using System.Linq; diff --git a/neo/Wallets/NEP6/NEP6Wallet.cs b/neo/Wallets/NEP6/NEP6Wallet.cs index 9f0d0a1315..f76640e886 100644 --- a/neo/Wallets/NEP6/NEP6Wallet.cs +++ b/neo/Wallets/NEP6/NEP6Wallet.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; using Neo.SmartContract; using System; using System.Collections.Generic; diff --git a/neo/Wallets/NEP6/ScryptParameters.cs b/neo/Wallets/NEP6/ScryptParameters.cs index 018f0bfd46..a987159ad6 100644 --- a/neo/Wallets/NEP6/ScryptParameters.cs +++ b/neo/Wallets/NEP6/ScryptParameters.cs @@ -1,4 +1,4 @@ -using Neo.IO.Json; +using Neo.IO.Json; namespace Neo.Wallets.NEP6 { diff --git a/neo/Wallets/NEP6/WalletLocker.cs b/neo/Wallets/NEP6/WalletLocker.cs index 6f28779361..45574b5cfe 100644 --- a/neo/Wallets/NEP6/WalletLocker.cs +++ b/neo/Wallets/NEP6/WalletLocker.cs @@ -1,4 +1,4 @@ -using System; +using System; namespace Neo.Wallets.NEP6 { diff --git a/neo/Wallets/SQLite/Account.cs b/neo/Wallets/SQLite/Account.cs index 5c91556fb2..ce8ed1e01e 100644 --- a/neo/Wallets/SQLite/Account.cs +++ b/neo/Wallets/SQLite/Account.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets.SQLite +namespace Neo.Wallets.SQLite { internal class Account { diff --git a/neo/Wallets/SQLite/Address.cs b/neo/Wallets/SQLite/Address.cs index 79ef9e1031..a5abe4dcfc 100644 --- a/neo/Wallets/SQLite/Address.cs +++ b/neo/Wallets/SQLite/Address.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets.SQLite +namespace Neo.Wallets.SQLite { internal class Address { diff --git a/neo/Wallets/SQLite/Contract.cs b/neo/Wallets/SQLite/Contract.cs index a69c0f0968..96ba3c51a6 100644 --- a/neo/Wallets/SQLite/Contract.cs +++ b/neo/Wallets/SQLite/Contract.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets.SQLite +namespace Neo.Wallets.SQLite { internal class Contract { diff --git a/neo/Wallets/SQLite/Key.cs b/neo/Wallets/SQLite/Key.cs index 97c063a3f2..f493b7310d 100644 --- a/neo/Wallets/SQLite/Key.cs +++ b/neo/Wallets/SQLite/Key.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets.SQLite +namespace Neo.Wallets.SQLite { internal class Key { diff --git a/neo/Wallets/SQLite/UserWallet.cs b/neo/Wallets/SQLite/UserWallet.cs index df4cccfe08..efb477a61a 100644 --- a/neo/Wallets/SQLite/UserWallet.cs +++ b/neo/Wallets/SQLite/UserWallet.cs @@ -1,4 +1,4 @@ -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Neo.Cryptography; using Neo.IO; using Neo.SmartContract; diff --git a/neo/Wallets/SQLite/UserWalletAccount.cs b/neo/Wallets/SQLite/UserWalletAccount.cs index 2d3ac74836..d586f59d36 100644 --- a/neo/Wallets/SQLite/UserWalletAccount.cs +++ b/neo/Wallets/SQLite/UserWalletAccount.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets.SQLite +namespace Neo.Wallets.SQLite { internal class UserWalletAccount : WalletAccount { diff --git a/neo/Wallets/SQLite/VerificationContract.cs b/neo/Wallets/SQLite/VerificationContract.cs index 41f8d44055..587a0fe468 100644 --- a/neo/Wallets/SQLite/VerificationContract.cs +++ b/neo/Wallets/SQLite/VerificationContract.cs @@ -1,4 +1,4 @@ -using Neo.IO; +using Neo.IO; using Neo.SmartContract; using Neo.VM; using System; diff --git a/neo/Wallets/SQLite/WalletDataContext.cs b/neo/Wallets/SQLite/WalletDataContext.cs index cba60cb00d..6d1ec957a8 100644 --- a/neo/Wallets/SQLite/WalletDataContext.cs +++ b/neo/Wallets/SQLite/WalletDataContext.cs @@ -1,4 +1,4 @@ -using Microsoft.Data.Sqlite; +using Microsoft.Data.Sqlite; using Microsoft.EntityFrameworkCore; namespace Neo.Wallets.SQLite diff --git a/neo/Wallets/TransferOutput.cs b/neo/Wallets/TransferOutput.cs index 6e45baa04b..9431f5616d 100644 --- a/neo/Wallets/TransferOutput.cs +++ b/neo/Wallets/TransferOutput.cs @@ -1,4 +1,4 @@ -namespace Neo.Wallets +namespace Neo.Wallets { public class TransferOutput { diff --git a/neo/Wallets/Wallet.cs b/neo/Wallets/Wallet.cs index d22c8ff128..eb816c7a0a 100644 --- a/neo/Wallets/Wallet.cs +++ b/neo/Wallets/Wallet.cs @@ -1,4 +1,4 @@ -using Neo.Cryptography; +using Neo.Cryptography; using Neo.IO; using Neo.Ledger; using Neo.Network.P2P.Payloads; diff --git a/neo/Wallets/WalletAccount.cs b/neo/Wallets/WalletAccount.cs index a427a9e50b..5e2408a1d0 100644 --- a/neo/Wallets/WalletAccount.cs +++ b/neo/Wallets/WalletAccount.cs @@ -1,4 +1,4 @@ -using Neo.SmartContract; +using Neo.SmartContract; namespace Neo.Wallets { diff --git a/neo/neo.csproj b/neo/neo.csproj index 66e85016bc..54ba724da9 100644 --- a/neo/neo.csproj +++ b/neo/neo.csproj @@ -1,4 +1,4 @@ - + 2015-2019 The Neo Project