Exemplo n.º 1
0
        public void ReadConsistentTest1()
        {
            Span <CoinEvent> events = stackalloc CoinEvent[3];

            events[0] = new CoinEvent(_1, CoinEventKind.Production);
            events[1] = new CoinEvent(_2_0, CoinEventKind.Consumption);
            events[2] = new CoinEvent(_2_1, CoinEventKind.Consumption);

            var hasEvents = _lineage.TryGetEventsInContext(events, _2_0, out var production, out var consumption);

            Assert.Equal(production, _1);
            Assert.Equal(consumption, _2_0);
            Assert.True(hasEvents);
        }
Exemplo n.º 2
0
        public bool TryGet(ulong outpointHash, ref Outpoint outpoint, BlockAlias context, ILineage lineage, out Coin coin,
                           out BlockAlias production, out BlockAlias consumption)
        {
            production  = BlockAlias.Undefined;
            consumption = BlockAlias.Undefined;

            if (_coins.TryGetValue(outpoint, out var fatCoin))
            {
                foreach (var ev in fatCoin.Events)
                {
                    if (ev.Kind == CoinEventKind.Production)
                    {
                        production = ev.BlockAlias;
                    }

                    if (ev.Kind == CoinEventKind.Consumption)
                    {
                        consumption = ev.BlockAlias;
                    }
                }

                if (lineage == null || lineage.TryGetEventsInContext(fatCoin.Events.ToArray(), context, out production, out consumption))
                {
                    coin = fatCoin.Coin;

                    return(true);
                }
            }

            coin = Coin.Empty;
            return(false);
        }
Exemplo n.º 3
0
        public bool TryGet(ulong outpointHash, ref Outpoint outpoint, BlockAlias context, ILineage lineage,
                           out Coin coin, out BlockAlias production, out BlockAlias consumption)
        {
            var sectorIndex = (uint)(outpointHash % (uint)_store.SectorCount);

            production  = BlockAlias.Undefined;
            consumption = BlockAlias.Undefined;

            // Check layer 0.
            var pack0 = _store.Read(layerIndex: 0, sectorIndex);

            if (pack0.TryGet(ref outpoint, out coin))
            {
                return(lineage.TryGetEventsInContext(coin.Events, context, out production, out consumption));
            }

            var sig = OutpointSig.From(outpointHash);

            // Layer 0 has a probabilistic filter. No false negative are possible.
            if (!pack0.PositiveMatch(sig))
            {
                return(false);
            }

            // Check next layers.
            for (var layerIndex = 1; layerIndex < _store.LayerCount; layerIndex++)
            {
                var packN = _store.Read(layerIndex: layerIndex, sectorIndex);

                if (packN.TryGet(ref outpoint, out coin))
                {
                    return(lineage.TryGetEventsInContext(coin.Events, context, out production, out consumption));
                }
            }

            // Not found, it was a false positive on the probabilistic filter.
            return(false);
        }