Ejemplo n.º 1
0
 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));
 }
Ejemplo n.º 3
0
 public BlockPerception(IBlockExcerpt blockExcerpt, DateTimeOffset perceivedTime)
 {
     ProtocolVersion = blockExcerpt.ProtocolVersion;
     Index           = blockExcerpt.Index;
     Hash            = blockExcerpt.Hash;
     TotalDifficulty = blockExcerpt.TotalDifficulty;
     PerceivedTime   = perceivedTime;
 }
Ejemplo n.º 4
0
        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}" +
                 " }");
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
 /// <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)
 {
 }
Ejemplo n.º 7
0
 /// <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;
 }