/// <summary> /// Initializes an instance of the stack using existing coinview. /// </summary> /// <param name="top">Coinview at the top of the stack.</param> public CoinViewStack(CoinView top) { this.Top = top; CoinView current = top; while (current is IBackedCoinView) { current = ((IBackedCoinView)current).Inner; } this.Bottom = current; }
/// <summary> /// Enumerates coinviews in the stack ordered from the top to the bottom. /// </summary> /// <returns>Enumeration of coin views in the stack ordered from the top to the bottom.</returns> public IEnumerable <CoinView> GetElements() { CoinView current = this.Top; while (current is IBackedCoinView) { yield return(current); current = ((IBackedCoinView)current).Inner; } yield return(current); }
/// <summary> /// Finds a coinview of specific type in the stack. /// </summary> /// <typeparam name="T">Type of the coinview to search for.</typeparam> /// <returns>Coinview of the specific type from the stack or <c>null</c> if such a coinview is not in the stack.</returns> public T Find <T>() { CoinView current = this.Top; if (current is T) { return((T)(object)current); } while (current is IBackedCoinView) { current = ((IBackedCoinView)current).Inner; if (current is T) { return((T)(object)current); } } return(default(T)); }
/// <summary> /// Initializes instance of the object based on memory based coinview. /// </summary> /// <param name="inner">Underlaying coinview with memory based storage.</param> /// <param name="dateTimeProvider">Provider of time functions.</param> /// <param name="loggerFactory">Factory to be used to create logger for the puller.</param> /// <param name="stakeChainStore">Storage of POS block information.</param> /// <remarks> /// This is used for testing the coinview. /// It allows a coin view that only has in-memory entries. /// </remarks> public CachedCoinView(InMemoryCoinView inner, IDateTimeProvider dateTimeProvider, ILoggerFactory loggerFactory, StakeChainStore stakeChainStore = null) : this(dateTimeProvider, loggerFactory, stakeChainStore) { Guard.NotNull(inner, nameof(inner)); this.inner = inner; }