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());
            }
        }
Beispiel #2
0
        //TODO thread safety
        //TODO need to rescan utxo when addresses are added as well
        public void AddAddress(IWalletAddress address)
        {
            //TODO add to queue, cannot monitor address until chain position moves
            var startChainPosition = ChainPosition.Fake();
            var monitoredRange = new[] { Tuple.Create(startChainPosition, startChainPosition) }.ToList();

            foreach (var outputScriptHash in address.GetOutputScriptHashes())
            {
                List<MonitoredWalletAddress> addresses;
                if (!this.addressesByOutputScriptHash.TryGetValue(outputScriptHash, out addresses))
                {
                    addresses = new List<MonitoredWalletAddress>();
                    this.addressesByOutputScriptHash.Add(outputScriptHash, addresses);
                }

                addresses.Add(new MonitoredWalletAddress(address, monitoredRange));
            }

            if (address.IsMatcher)
            {
                this.matcherAddresses.Add(new MonitoredWalletAddress(address, monitoredRange));
            }
        }