Exemplo n.º 1
0
        /// <summary>
        /// Compares whether two persistence entries are equal.
        /// </summary>
        /// <param name="obj">Object to compare this persistence entry to.</param>
        /// <returns>Whether the objects are equal.</returns>
        public override bool Equals(object obj)
        {
            MempoolPersistenceEntry toCompare = obj as MempoolPersistenceEntry;

            if (toCompare == null)
            {
                return(false);
            }

            if ((this.tx == null) != (toCompare.tx == null))
            {
                return(false);
            }

            if (!this.time.Equals(toCompare.time) || !this.feeDelta.Equals(toCompare.feeDelta))
            {
                return(false);
            }

            if ((this.tx == null) && (toCompare.tx == null))
            {
                return(true);
            }

            return(this.tx.ToHex().Equals(toCompare.tx.ToHex()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a collection of memory pool transactions from a persistence stream.
        /// </summary>
        /// <param name="stream">Stream to load transactions from.</param>
        /// <returns>Collection of memory pool transactions.</returns>
        internal IEnumerable <MempoolPersistenceEntry> LoadFromStream(Stream stream)
        {
            var toReturn = new List <MempoolPersistenceEntry>();

            ulong version       = 0;
            long  numEntries    = -1;
            var   bitcoinReader = new BitcoinStream(stream, false);

            bool exitWithError = false;

            try
            {
                bitcoinReader.ReadWrite(ref version);
                if (version != MempoolDumpVersion)
                {
                    this.mempoolLogger.LogWarning($"Memorypool data is wrong version ({version}) aborting...");
                    return(null);
                }
                bitcoinReader.ReadWrite(ref numEntries);
            }
            catch
            {
                this.mempoolLogger.LogWarning($"Memorypool data is corrupt at header, aborting...");
                return(null);
            }

            for (int i = 0; i < numEntries && !exitWithError; i++)
            {
                MempoolPersistenceEntry entry = default(MempoolPersistenceEntry);
                try
                {
                    bitcoinReader.ReadWrite(ref entry);
                }
                catch
                {
                    this.mempoolLogger.LogWarning($"Memorypool data is corrupt at item {i + 1}, aborting...");
                    return(null);
                }

                toReturn.Add(entry);
            }

            return(toReturn);
        }
Exemplo n.º 3
0
        /// <inheritdoc />
        public MemPoolSaveResult Save(ITxMempool memPool, string fileName = null)
        {
            fileName = fileName ?? DefaultFilename;
            IEnumerable <MempoolPersistenceEntry> toSave = memPool.MapTx.Values.ToArray().Select(tx => MempoolPersistenceEntry.FromTxMempoolEntry(tx));

            return(this.Save(toSave, fileName));
        }