public static ConsensusData FromJson(JObject json) { ConsensusData block = new ConsensusData(); block.PrimaryIndex = (uint)json["primary"].AsNumber(); block.Nonce = ulong.Parse(json["nonce"].AsString(), NumberStyles.HexNumber); return(block); }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); ConsensusData = reader.ReadSerializable <ConsensusData>(); TxCount = (int)reader.ReadVarInt(int.MaxValue); Hashes = reader.ReadSerializableArray <UInt256>(); Flags = reader.ReadVarBytes(); }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); ConsensusData = reader.ReadSerializable <ConsensusData>(); Transactions = reader.ReadSerializableArray <Transaction>(MaxTransactionsPerBlock); if (Transactions.Length == 0) { throw new FormatException(); } if (Transactions.Distinct().Count() != Transactions.Length) { throw new FormatException(); } if (MerkleTree.ComputeRoot(Transactions.Select(p => p.Hash).ToArray()) != MerkleRoot) { throw new FormatException(); } }
public override void Deserialize(BinaryReader reader) { base.Deserialize(reader); int count = (int)reader.ReadVarInt(MaxContentsPerBlock); if (count == 0) { throw new FormatException(); } ConsensusData = reader.ReadSerializable <ConsensusData>(); Transactions = new Transaction[count - 1]; for (int i = 0; i < Transactions.Length; i++) { Transactions[i] = reader.ReadSerializable <Transaction>(); } if (Transactions.Distinct().Count() != Transactions.Length) { throw new FormatException(); } if (CalculateMerkleRoot(ConsensusData.Hash, Transactions.Select(p => p.Hash)) != MerkleRoot) { throw new FormatException(); } }