public StackItem ToStackItem() { return(new VM.Types.Array ( new StackItem[] { // Computed properties new ByteArray(Hash.ToArray()), // BlockBase properties new Integer(Version), new ByteArray(PrevHash.ToArray()), new ByteArray(MerkleRoot.ToArray()), new Integer(Timestamp), new Integer(Index), new ByteArray(NextConsensus.ToArray()), // Witness // Block properties // Count // ConsensusData new Integer(Transactions.Length) } )); }
public void Deserialize(BinaryReader reader) { Reset(0); if (reader.ReadUInt32() != Version) { throw new FormatException(); } if (reader.ReadUInt32() != BlockIndex) { throw new InvalidOperationException(); } ViewNumber = reader.ReadByte(); PrimaryIndex = reader.ReadUInt32(); Timestamp = reader.ReadUInt32(); Nonce = reader.ReadUInt64(); NextConsensus = reader.ReadSerializable <UInt160>(); if (NextConsensus.Equals(UInt160.Zero)) { NextConsensus = null; } TransactionHashes = reader.ReadSerializableArray <UInt256>(); if (TransactionHashes.Length == 0) { TransactionHashes = null; } Transaction[] transactions = new Transaction[reader.ReadVarInt(Block.MaxTransactionsPerBlock)]; if (transactions.Length == 0) { Transactions = null; } else { for (int i = 0; i < transactions.Length; i++) { transactions[i] = Transaction.DeserializeFrom(reader); } Transactions = transactions.ToDictionary(p => p.Hash); } PreparationPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)]; for (int i = 0; i < PreparationPayloads.Length; i++) { PreparationPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable <ConsensusPayload>() : null; } CommitPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)]; for (int i = 0; i < CommitPayloads.Length; i++) { CommitPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable <ConsensusPayload>() : null; } ChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)]; for (int i = 0; i < ChangeViewPayloads.Length; i++) { ChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable <ConsensusPayload>() : null; } LastChangeViewPayloads = new ConsensusPayload[reader.ReadVarInt(Blockchain.MaxValidators)]; for (int i = 0; i < LastChangeViewPayloads.Length; i++) { LastChangeViewPayloads[i] = reader.ReadBoolean() ? reader.ReadSerializable <ConsensusPayload>() : null; } }
StackItem IInteroperable.ToStackItem(ReferenceCounter referenceCounter) { return(new VM.Types.Array(referenceCounter, new StackItem[] { // Computed properties Hash.ToArray(), // BlockBase properties Version, PrevHash.ToArray(), MerkleRoot.ToArray(), Timestamp, Index, NextConsensus.ToArray(), // Block properties Hashes.Length - 1 })); }
public StackItem ToStackItem(ReferenceCounter referenceCounter) { return(new Array(referenceCounter, new StackItem[] { // Computed properties Hash.ToArray(), // BlockBase properties Version, PrevHash.ToArray(), MerkleRoot.ToArray(), Timestamp, Index, NextConsensus.ToArray(), // Block properties Transactions.Length })); }