internal RawBlock ToRawBlock( bool includeHash, bool includeTransactionData ) { IEnumerable transactions = Transactions.Select( tx => includeTransactionData ? tx.ToRawTransaction(true) as object : tx.Id.ToByteArray() as object ); var rawBlock = new RawBlock( index: Index, timestamp: Timestamp.ToString(TimestampFormat), nonce: Nonce.ToByteArray(), miner: Miner?.ToByteArray(), difficulty: Difficulty, transactions: transactions, previousHash: PreviousHash?.ToByteArray() ); if (includeHash) { rawBlock = rawBlock.AddHash(Hash.ToByteArray()); } return(rawBlock); }
internal BlockHeader GetBlockHeader() { string timestampAsString = Timestamp.ToString( BlockHeader.TimestampFormat, CultureInfo.InvariantCulture ); ImmutableArray <byte> previousHashAsArray = PreviousHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty; ImmutableArray <byte> actionsHashAsArray = EvaluationDigest?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty; if (PreviousHash.Equals(EvaluationDigest)) { Console.WriteLine(); } // FIXME: When hash is not assigned, should throw an exception. return(new BlockHeader( index: Index, timestamp: timestampAsString, nonce: Nonce.ToByteArray().ToImmutableArray(), miner: Miner?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, difficulty: Difficulty, totalDifficulty: TotalDifficulty, previousHash: previousHashAsArray, txHash: TxHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, hash: Hash.ToByteArray().ToImmutableArray(), preEvaluationHash: PreEvaluationHash.ToByteArray().ToImmutableArray(), evaluationDigest: actionsHashAsArray )); }
internal RawBlock ToRawBlock( bool includeHash, bool includeTransactionData ) { IEnumerable <byte[]> transactions = Transactions.OrderBy(tx => tx.Id).Select( tx => includeTransactionData ? tx.Serialize(true) : tx.Id.ToByteArray() ); var rawBlock = new RawBlock( index: Index, timestamp: Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture), nonce: Nonce.ToByteArray(), miner: Miner?.ToByteArray(), difficulty: Difficulty, transactions: transactions, previousHash: PreviousHash?.ToByteArray() ); if (includeHash) { rawBlock = rawBlock.AddHash(Hash.ToByteArray()); } return(rawBlock); }
internal BlockHeader GetBlockHeader() { // FIXME: When hash is not assigned, should throw an exception. return(new BlockHeader( index: Index, timestamp: Timestamp.ToString(TimestampFormat, CultureInfo.InvariantCulture), nonce: Nonce.ToByteArray().ToImmutableArray(), miner: Miner?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, difficulty: Difficulty, #pragma warning disable MEN002 // line is too long previousHash: PreviousHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, #pragma warning restore MEN002 // line is too long txHash: TxHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, hash: Hash.ToByteArray().ToImmutableArray() )); }
internal BlockHeader GetBlockHeader() { string timestampAsString = Timestamp.ToString( BlockHeader.TimestampFormat, CultureInfo.InvariantCulture ); ImmutableArray <byte> previousHashAsArray = PreviousHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty; // FIXME: When hash is not assigned, should throw an exception. return(new BlockHeader( index: Index, timestamp: timestampAsString, nonce: Nonce.ToByteArray().ToImmutableArray(), miner: Miner?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, difficulty: Difficulty, previousHash: previousHashAsArray, txHash: TxHash?.ToByteArray().ToImmutableArray() ?? ImmutableArray <byte> .Empty, hash: Hash.ToByteArray().ToImmutableArray() )); }