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); }
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()); }
public static byte[] EncodeSpentTx(SpentTx spentTx) { using (var stream = new MemoryStream()) using (var writer = new BinaryWriter(stream)) { EncodeSpentTx(writer, spentTx); return stream.ToArray(); } }
public static void EncodeSpentTx(BinaryWriter writer, SpentTx spentTx) { writer.WriteUInt256(spentTx.TxHash); writer.WriteInt32(spentTx.ConfirmedBlockIndex); writer.WriteInt32(spentTx.TxIndex); writer.WriteInt32(spentTx.OutputCount); }