Represents a transaction that has been fully spent and removed from the UTXO. The spent transaction information is needed when pruning spent transactions from the tx index and from blocks.
Example #1
0
        public void TestReadByBlock()
        {
            var spentTx0_0 = new SpentTx((UInt256)0, 0, 1, 0);
            var spentTx1_0 = new SpentTx((UInt256)1, 1, 0, 0);
            var spentTx1_1 = new SpentTx((UInt256)2, 1, 1, 0);
            var spentTx2_0 = new SpentTx((UInt256)3, 2, 0, 0);

            var builder = new BlockSpentTxesBuilder();
            builder.AddSpentTx(spentTx1_0);
            builder.AddSpentTx(spentTx2_0);
            builder.AddSpentTx(spentTx1_1);
            builder.AddSpentTx(spentTx0_0);

            var spentTxes = builder.ToImmutable();

            var expectedByBlock = new[]
            {
                Tuple.Create(0, (IImmutableList<SpentTx>)ImmutableList.Create(spentTx0_0)),
                Tuple.Create(1, (IImmutableList<SpentTx>)ImmutableList.Create(spentTx1_0, spentTx1_1)),
                Tuple.Create(2, (IImmutableList<SpentTx>)ImmutableList.Create(spentTx2_0)),
            }.ToList();

            var actualByBlock = spentTxes.ReadByBlock().ToList();

            Assert.AreEqual(expectedByBlock.Count, actualByBlock.Count);
            for (var i = 0; i < actualByBlock.Count; i++)
            {
                Assert.AreEqual(expectedByBlock[i].Item1, actualByBlock[i].Item1);
                CollectionAssert.AreEqual(expectedByBlock[i].Item2.ToList(), actualByBlock[i].Item2.ToList());
            }
        }
        public void AddSpentTx(SpentTx spentTx)
        {
            var blockIndex = spentTx.ConfirmedBlockIndex;

            List<SpentTx> spentTxes;
            if (!spentTxesByBlock.TryGetValue(blockIndex, out spentTxes))
            {
                spentTxes = new List<SpentTx>();
                spentTxesByBlock.Add(blockIndex, spentTxes);
            }

            spentTxes.Add(spentTx);
        }
Example #3
0
        public void TestBlockSpentTxes()
        {
            var spentTx0_0 = new SpentTx((UInt256)0, 0, 1, 0);
            var spentTx1_0 = new SpentTx((UInt256)1, 1, 0, 0);
            var spentTx1_1 = new SpentTx((UInt256)2, 1, 1, 0);
            var spentTx2_0 = new SpentTx((UInt256)3, 2, 0, 0);

            var builder = new BlockSpentTxesBuilder();
            builder.AddSpentTx(spentTx1_0);
            builder.AddSpentTx(spentTx2_0);
            builder.AddSpentTx(spentTx1_1);
            builder.AddSpentTx(spentTx0_0);

            var spentTxes = builder.ToImmutable();

            CollectionAssert.AreEqual(new[] { spentTx0_0, spentTx1_0, spentTx1_1, spentTx2_0 }, spentTxes.ToList());
        }
Example #4
0
 public static byte[] EncodeSpentTx(SpentTx spentTx)
 {
     using (var stream = new MemoryStream())
     using (var writer = new BinaryWriter(stream))
     {
         EncodeSpentTx(writer, spentTx);
         return stream.ToArray();
     }
 }
Example #5
0
 public static void EncodeSpentTx(BinaryWriter writer, SpentTx spentTx)
 {
     writer.WriteUInt256(spentTx.TxHash);
     writer.WriteInt32(spentTx.ConfirmedBlockIndex);
     writer.WriteInt32(spentTx.TxIndex);
     writer.WriteInt32(spentTx.OutputCount);
 }