public byte[] GetBytes() { using (MemoryStream stream = new MemoryStream()) { using (BinaryWriter writer = new BinaryWriter(stream)) { writer.Write(Version); writer.Write(Timestamp); if (PreviousBlock != null) { writer.Write(PreviousBlock.ToByteArray()); } else { writer.Write(new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }); } writer.Write(NumberOfTransactions); writer.Write(TotalAmount); writer.Write(TotalFee); writer.Write(PayloadLength); writer.Write(PayloadHash.FromHex()); writer.Write(GeneratorPublicKey.FromHex()); if (!string.IsNullOrWhiteSpace(BlockSignature)) { writer.Write(BlockSignature.FromHex()); } } return(stream.ToArray()); } }
public override void WriteToBitcoinBuffer(byte[] buffer, int offset) { Version.WriteBytes(buffer, offset); PreviousBlock.WriteToBitcoinBuffer(buffer, PreviousBlock_Offset(ref offset)); MerkleRoot.WriteToBitcoinBuffer(buffer, MerkleRoot_Offset(ref offset)); Timestamp.WriteBytes(buffer, Timestamp_Offset(ref offset)); Bits.WriteBytes(buffer, Bits_Offset(ref offset)); Nonce.WriteBytes(buffer, Nonce_Offset(ref offset)); Transactions.WriteToBitcoinBuffer(buffer, Transactions_Offset(ref offset)); }
public void verifyIfChainIsValid() { if (PreviousBlock == null) { throw new InvalidOperationException("Genesis block is not set."); } bool isValid = PreviousBlock.isValidChain(null, true); if (isValid) { Console.WriteLine("Blockchain is NOT tampered.\n\n\n"); } else { Console.WriteLine("Blockchain is tampered.\n\n\n"); } }
public override int GetHashCode() { return(DataGraphIri.GetHashCode() + DataHash.GetHashCode() + Hash.GetHashCode() + Index.GetHashCode() + PreviousBlock.GetHashCode() + PreviousHash.GetHashCode() + Timestamp.GetHashCode()); }
/// <summary> /// Remove the front block (or this block if the list contains only one element) /// </summary> /// <returns>Removed block</returns> public Block RemoveFront(bool fullIsolation = false) => PreviousBlock.Isolate(fullIsolation);
public void WriteDescendants(StringBuilder builder) { builder.AppendLine(JsonConvert.SerializeObject(this, Formatting.Indented)); PreviousBlock?.WriteDescendants(builder); }