public static Dictionary MarshalBlockMetadata(IBlockMetadata metadata) { string timestamp = metadata.Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture); Dictionary dict = Dictionary.Empty .Add(IndexKey, metadata.Index) .Add(TimestampKey, timestamp) .Add(DifficultyKey, metadata.Difficulty) .Add(TotalDifficultyKey, (IValue) new Integer(metadata.TotalDifficulty)); if (metadata.ProtocolVersion != 0) { dict = dict.Add(ProtocolVersionKey, metadata.ProtocolVersion); } if (metadata.PreviousHash is { } prev) { dict = dict.Add(PreviousHashKey, prev.ByteArray); } if (metadata.TxHash is { } th) { dict = dict.Add(TxHashKey, th.ByteArray); } dict = metadata.PublicKey is { } pubKey ? dict.Add(PublicKeyKey, pubKey.Format(compress: true)) : dict.Add(MinerKey, metadata.Miner.ByteArray); return(dict); }
/// <summary> /// Creates a <see cref="PreEvaluationBlockHeader"/> instance with its /// <paramref name="metadata"/> and a valid proof-of-work <paramref name="nonce"/> which /// satisfies the required <see cref="Difficulty"/>. /// </summary> /// <param name="metadata">Block's metadata.</param> /// <param name="hashAlgorithm">The hash algorithm used for calculating /// <see cref="PreEvaluationHash"/>.</param> /// <param name="nonce">A valid proof-of-work nonce which satisfies the required /// <see cref="Difficulty"/>.</param> /// <exception cref="InvalidBlockProtocolVersionException">Thrown when /// the <paramref name="metadata"/>'s to set is <see cref="IBlockMetadata.ProtocolVersion"/> /// is less than 0, or greater than <see cref="BlockMetadata.CurrentProtocolVersion"/>, /// the latest known protocol version.</exception> /// <exception cref="InvalidBlockIndexException">Thrown when the <paramref name="metadata"/> /// has a negative <see cref="IBlockMetadata.Index"/>.</exception> /// <exception cref="InvalidBlockDifficultyException">Thrown when /// the <paramref name="metadata"/>'s <see cref="IBlockMetadata.Difficulty"/> is negative. /// </exception> /// <exception cref="InvalidBlockTotalDifficultyException">Thrown when /// the <paramref name="metadata"/>'s <see cref="IBlockMetadata.TotalDifficulty"/> is less /// than its <see cref="IBlockMetadata.Difficulty"/>.</exception> /// <exception cref="InvalidBlockNonceException">Thrown when the given proof-of-work /// <paramref name="nonce"/> does not satisfy the required <see cref="Difficulty"/>. /// </exception> /// <remarks><see cref="PreEvaluationHash"/> is automatically derived from the given /// arguments.</remarks> public PreEvaluationBlockHeader( IBlockMetadata metadata, HashAlgorithmType hashAlgorithm, Nonce nonce ) : this(new BlockMetadata(metadata), hashAlgorithm, nonce) { }
/// <summary> /// Creates a <see cref="PreEvaluationBlockHeader"/> instance with its /// <paramref name="metadata"/>, a valid proof-of-work <paramref name="nonce"/> which /// satisfies the required <see cref="Difficulty"/>, and /// a <paramref name="preEvaluationHash"/> digest derived from them. /// </summary> /// <param name="metadata">Block's metadata.</param> /// <param name="hashAlgorithm">The hash algorithm used for calculating /// <see cref="PreEvaluationHash"/>.</param> /// <param name="nonce">A valid proof-of-work nonce which satisfies the required /// <see cref="Difficulty"/>.</param> /// <param name="preEvaluationHash">The hash digest of the <paramref name="hashAlgorithm"/> /// derived from the given arguments.</param> /// <exception cref="InvalidBlockProtocolVersionException">Thrown when /// the <paramref name="metadata"/>'s to set is <see cref="IBlockMetadata.ProtocolVersion"/> /// is less than 0, or greater than <see cref="BlockMetadata.CurrentProtocolVersion"/>, /// the latest known protocol version.</exception> /// <exception cref="InvalidBlockIndexException">Thrown when the <paramref name="metadata"/> /// has a negative <see cref="IBlockMetadata.Index"/>.</exception> /// <exception cref="InvalidBlockDifficultyException">Thrown when /// the <paramref name="metadata"/>'s <see cref="IBlockMetadata.Difficulty"/> is negative. /// </exception> /// <exception cref="InvalidBlockTotalDifficultyException">Thrown when /// the <paramref name="metadata"/>'s <see cref="IBlockMetadata.TotalDifficulty"/> is less /// than its <see cref="IBlockMetadata.Difficulty"/>.</exception> /// <exception cref="InvalidBlockPreEvaluationHashException">Thrown when the given /// <paramref name="preEvaluationHash"/> is invalid.</exception> /// <exception cref="InvalidBlockNonceException">Thrown when the given proof-of-work /// <paramref name="nonce"/> does not satisfy the required <see cref="Difficulty"/>. /// </exception> public PreEvaluationBlockHeader( IBlockMetadata metadata, HashAlgorithmType hashAlgorithm, Nonce nonce, ImmutableArray <byte> preEvaluationHash ) : this(new BlockMetadata(metadata), hashAlgorithm, nonce, preEvaluationHash) { }
public VulkanMemoryBlock(VulkanMemoryAllocator allocator, VulkanMemoryPool?pool, int memoryTypeIndex, DeviceMemory memory, uint id, IBlockMetadata metaObject) { Allocator = allocator; ParentPool = pool; MemoryTypeIndex = memoryTypeIndex; DeviceMemory = memory; ID = id; MetaData = metaObject; }
public BlockMetadata(IBlockMetadata metadata) { ProtocolVersion = metadata.ProtocolVersion; Index = metadata.Index; Timestamp = metadata.Timestamp; Miner = metadata.Miner; PublicKey = metadata.PublicKey; Difficulty = metadata.Difficulty; TotalDifficulty = metadata.TotalDifficulty; PreviousHash = metadata.PreviousHash; _txHash = metadata.TxHash; }
public static void AssertBlockMetadataEqual(IBlockMetadata expected, IBlockMetadata actual) { Assert.NotNull(expected); Assert.NotNull(actual); Assert.Equal(expected.ProtocolVersion, actual.ProtocolVersion); Assert.Equal(expected.Index, actual.Index); Assert.Equal(expected.Timestamp, actual.Timestamp); AssertBytesEqual(expected.Miner, actual.Miner); Assert.Equal(expected.Difficulty, actual.Difficulty); Assert.Equal(expected.TotalDifficulty, actual.TotalDifficulty); AssertBytesEqual(expected.PreviousHash, actual.PreviousHash); AssertBytesEqual(expected.TxHash, actual.TxHash); }
private ViewEngineResult FindFirstView(IBlockMetadata blockMetadata, IEnumerable <string> templates, ViewContext viewContext, out ICollection <string> searchedLocations) { searchedLocations = new List <string>(); foreach (var template in templates) { var viewName = string.Concat("BlockTemplates/", blockMetadata.SystemName, "/", template); var viewResult = ViewEngines.Engines.FindPartialView(viewContext, viewName); searchedLocations.AddRange(viewResult.SearchedLocations); if (viewResult.View != null) { return(viewResult); } } return(null); }
public static void ValidateTimestamp( this IBlockMetadata blockMetadata, DateTimeOffset currentTime ) { if (currentTime + TimestampThreshold < blockMetadata.Timestamp) { string hash = blockMetadata is IBlockExcerpt h ? $" {h.Hash}" : string.Empty; throw new InvalidBlockTimestampException( $"The block #{blockMetadata.Index}{hash}'s timestamp " + $"({blockMetadata.Timestamp}) is later than now ({currentTime}, " + $"threshold: {TimestampThreshold})." ); } }
private static ViewEngineResult FindFirstView(IBlockMetadata blockMetadata, IEnumerable <string> templates, ActionContext actionContext, out ICollection <string> searchedLocations) { searchedLocations = new List <string>(); var viewEngine = actionContext.HttpContext.RequestServices.GetRequiredService <IRazorViewEngine>(); foreach (var template in templates) { var viewName = string.Concat("BlockTemplates/", blockMetadata.SystemName, "/", template); var viewResult = viewEngine.FindView(actionContext, viewName, false); searchedLocations.AddRange(viewResult.SearchedLocations); if (viewResult.View != null) { return(viewResult); } } return(null); }
public BlockContent(IBlockMetadata metadata) : this(metadata, Enumerable.Empty <Transaction <T> >()) { }
public BlockContent(IBlockMetadata metadata, IEnumerable <Transaction <T> > transactions) : base(metadata) { Transactions = transactions.ToImmutableArray(); TxHash = metadata.TxHash; }
public static void ValidateTimestamp(this IBlockMetadata blockMetadata) => ValidateTimestamp(blockMetadata, DateTimeOffset.UtcNow);
public static BlockMetadata Copy(this IBlockMetadata metadata) => new BlockMetadata(metadata);