Пример #1
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(Network network, Stream stream)
        {
            var toReturn = new List <MempoolPersistenceEntry>();

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

            bitcoinReader.ConsensusFactory = network.Consensus.ConsensusFactory;
            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);
        }
Пример #2
0
        /// <inheritdoc />
        public MemPoolSaveResult Save(Network network, ITxMempool memPool, string fileName = null)
        {
            fileName = fileName ?? DefaultFilename;
            IEnumerable <MempoolPersistenceEntry> toSave = memPool.MapTx.Values.ToArray().Select(tx => MempoolPersistenceEntry.FromTxMempoolEntry(tx));

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