예제 #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());
            }
        })
        { }
예제 #2
0
        public bool TryGetBlockSpentTxes(int blockIndex, out IImmutableList <SpentTx> spentTxes)
        {
            Api.JetSetCurrentIndex(this.jetSession, this.spentTxTableId, "IX_SpentBlockIndex");

            Api.MakeKey(this.jetSession, this.spentTxTableId, blockIndex, MakeKeyGrbit.NewKey);

            if (Api.TrySeek(this.jetSession, this.spentTxTableId, SeekGrbit.SeekEQ))
            {
                var spentTxesBytes = Api.RetrieveColumn(this.jetSession, this.spentTxTableId, this.spentDataColumnId);

                using (var stream = new MemoryStream(spentTxesBytes))
                    using (var reader = new BinaryReader(stream))
                    {
                        spentTxes = ImmutableList.CreateRange(reader.ReadList(() => DataEncoder.DecodeSpentTx(stream)));
                    }

                return(true);
            }
            else
            {
                spentTxes = null;
                return(false);
            }
        }