Ejemplo n.º 1
0
        public SpentTransactionsStorage(string baseDirectory)
            : base(baseDirectory, "SpentTransactions",
                   keyPairs =>
        {
            using (var stream = new MemoryStream())
            {
                foreach (var keyPair in keyPairs)
                {
                    DataEncoder.EncodeUInt256(stream, keyPair.Key);
                    DataEncoder.EncodeSpentTx(stream, keyPair.Value);
                }

                return(stream.ToArray());
            }
        },
                   (blockHash, bytes) =>
        {
            using (var stream = new MemoryStream(bytes))
            {
                var keyPairs = ImmutableList.CreateBuilder <KeyValuePair <UInt256, SpentTx> >();

                while (stream.Position < stream.Length)
                {
                    var txHash  = DataEncoder.DecodeUInt256(stream);
                    var spentTx = DataEncoder.DecodeSpentTx(stream);

                    keyPairs.Add(new KeyValuePair <UInt256, SpentTx>(txHash, spentTx));
                }

                return(keyPairs.ToImmutable());
            }
        })
        { }