public static string ToExcerptString(this IBlockExcerpt excerpt) => $"{excerpt.GetType().Name} {{" + $" {nameof(IBlockExcerpt.ProtocolVersion)} = {excerpt.ProtocolVersion}," + $" {nameof(IBlockExcerpt.Index)} = {excerpt.Index}," + $" {nameof(IBlockExcerpt.Hash)} = {excerpt.Hash}," + $" {nameof(IBlockExcerpt.TotalDifficulty)} = {excerpt.TotalDifficulty}" + " }";
public static bool ExcerptEquals(this IBlockExcerpt excerpt, IBlockExcerpt other) { return(excerpt.ProtocolVersion.Equals(other.ProtocolVersion) && excerpt.Index.Equals(other.Index) && excerpt.Hash.Equals(other.Hash) && excerpt.TotalDifficulty.Equals(other.TotalDifficulty)); }
public BlockPerception(IBlockExcerpt blockExcerpt, DateTimeOffset perceivedTime) { ProtocolVersion = blockExcerpt.ProtocolVersion; Index = blockExcerpt.Index; Hash = blockExcerpt.Hash; TotalDifficulty = blockExcerpt.TotalDifficulty; PerceivedTime = perceivedTime; }
public override string ToString() { const string F = nameof(BlockExcerpt); IBlockExcerpt excerpt = BlockExcerpt; return ($"{nameof(BlockPerception)} {{" + $" {F}.{nameof(excerpt.ProtocolVersion)} = {excerpt.ProtocolVersion}," + $" {F}.{nameof(excerpt.Index)} = {excerpt.Index}," + $" {F}.{nameof(excerpt.Hash)} = {excerpt.Hash}," + $" {F}.{nameof(excerpt.TotalDifficulty)} = {excerpt.TotalDifficulty}," + $" {nameof(PerceivedTime)} = {PerceivedTime}" + " }"); }
public int Compare(BlockPerception x, BlockPerception y) { DateTimeOffset outdateBefore = _currentTimeGetter() - OutdateAfter; bool xOutdated = x.PerceivedTime <= outdateBefore, yOutdated = y.PerceivedTime <= outdateBefore; if (xOutdated != yOutdated) { return(xOutdated ? -1 : 1); } IBlockExcerpt xBlock = x.BlockExcerpt, yBlock = y.BlockExcerpt; int vcmp = xBlock.ProtocolVersion.CompareTo(yBlock.ProtocolVersion); return(vcmp == 0 ? xBlock.TotalDifficulty.CompareTo(yBlock.TotalDifficulty) : vcmp); }
/// <summary> /// Creates a pair with setting <see cref="PerceivedTime"/> to the current time. /// </summary> /// <param name="blockExcerpt">The block perceived by the local node.</param> public BlockPerception(IBlockExcerpt blockExcerpt) : this(blockExcerpt, DateTimeOffset.UtcNow) { }
/// <summary> /// Creates a pair. /// </summary> /// <param name="blockExcerpt">The block perceived by the local node.</param> /// <param name="perceivedTime">The time the local node perceived the /// <paramref name="blockExcerpt"/>.</param> public BlockPerception(IBlockExcerpt blockExcerpt, DateTimeOffset perceivedTime) { BlockExcerpt = blockExcerpt; PerceivedTime = perceivedTime; }