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); 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).ToArray()) != MerkleRoot) { throw new FormatException(); } }