private static ImmutableList <Block <T> > GetFastForwardPath( BlockChain <T> chain, BlockHash originHash) { if (!chain.ContainsBlock(originHash)) { throw new KeyNotFoundException( $"Given chain {chain.Id} must contain origin hash {originHash}"); } return(GetRewindPath(chain, originHash).Reverse()); }
private static ImmutableList <Block <T> > GetRewindPath( BlockChain <T> chain, BlockHash targetHash) { if (!chain.ContainsBlock(targetHash)) { throw new KeyNotFoundException( $"Given chain {chain.Id} must contain target hash {targetHash}"); } Block <T> target = chain[targetHash]; List <Block <T> > path = new List <Block <T> >(); for ( Block <T> current = chain.Tip; current.Index > target.Index && current.PreviousHash is { } ph; current = chain[ph]) { path.Add(current); } return(path.ToImmutableList()); }