public static Block Unserialize(BinaryReader reader) { var block = new Block(); block.Version = reader.ReadUInt32(); block.PreviousHash = new UInt256(reader.ReadBytes(32)); block.MerkleRoot = reader.ReadBytes(32); block.Timestamp = reader.ReadUInt32(); block.Height = reader.ReadUInt32(); block.ConsensusData = reader.ReadUInt64(); var nextConsensus = reader.ReadBytes(20); block.Validator = new UInt160(nextConsensus); var pad = reader.ReadByte(); // should be 1 block.witness = Witness.Unserialize(reader); var txCount = (int)reader.ReadVarInt(); block.transactions = new Transaction[txCount]; for (int i = 0; i < txCount; i++) { block.transactions[i] = Transaction.Unserialize(reader); } var lastPos = reader.BaseStream.Position; return(block); }
public static SignedTransaction Unserialize(BinaryReader reader) { var tx = new SignedTransaction { Type = (TransactionType)reader.ReadByte(), Version = reader.ReadByte() }; switch (tx.Type) { case TransactionType.InvocationTransaction: { //todo break; } case TransactionType.MinerTransaction: { //todo break; } case TransactionType.ClaimTransaction: { var len = (int)reader.ReadVarInt(0x10000000); tx.References = new SignedTransaction.Input[len]; for (var i = 0; i < len; i++) { tx.References[i] = UnserializeTransactionInput(reader); } break; } case TransactionType.ContractTransaction: { break; } case TransactionType.PublishTransaction: { //todo break; } case TransactionType.EnrollmentTransaction: { //todo break; } case TransactionType.RegisterTransaction: { //todo break; } case TransactionType.IssueTransaction: { break; } case TransactionType.StateTransaction: break; default: { throw new NotImplementedException(); } } var attrCount = (int)reader.ReadVarInt(16); if (attrCount != 0) { tx.Attributes = new TransactionAttribute[attrCount]; for (var i = 0; i < attrCount; i++) { tx.Attributes[i] = TransactionAttribute.Unserialize(reader); } } var inputCount = (int)reader.ReadVarInt(); tx.Inputs = new SignedTransaction.Input[inputCount]; for (var i = 0; i < inputCount; i++) { tx.Inputs[i] = UnserializeTransactionInput(reader); } var outputCount = (int)reader.ReadVarInt(); tx.Outputs = new SignedTransaction.Output[outputCount]; for (var i = 0; i < outputCount; i++) { tx.Outputs[i] = UnserializeTransactionOutput(reader); } var witnessCount = (int)reader.ReadVarInt(); tx.Witnesses = new Witness[witnessCount]; for (var i = 0; i < witnessCount; i++) { tx.Witnesses[i] = Witness.Unserialize(reader); } return(tx); }