public Transaction Deserialize(ref SequenceReader <byte> reader, int protocolVersion, ProtocolTypeSerializerOptions?options = null)
        {
            bool allowWitness = options?.Get(SerializerOptions.SERIALIZE_WITNESS, false) ?? false;
            byte flags        = 0;

            var tx = new Transaction {
                Version = reader.ReadInt()
            };

            /// Try to read the inputs. In case the dummy byte is, this will be read as an empty list of transaction inputs.
            TransactionInput[] inputs = reader.ReadArray(protocolVersion, _transactionInputSerializer);

            if (inputs.Length == 0)
            {
                //we don't expect an empty transaction inputs list, so we treat this as having witness data
                flags = reader.ReadByte();
                if (flags != 0 && allowWitness)
                {
                    tx.Inputs  = reader.ReadArray(protocolVersion, _transactionInputSerializer);
                    tx.Outputs = reader.ReadArray(protocolVersion, _transactionOutputSerializer);
                }
            }
            else
            {
                // otherwise we read valid inputs, now we have to read outputs
                tx.Outputs = reader.ReadArray(protocolVersion, _transactionOutputSerializer);
            }

            if ((flags & 1) != 0 && allowWitness)
            {
                /* The witness flag is present, and we support witnesses. */
                flags ^= 1;

                for (int i = 0; i < tx.Inputs !.Length; i++)
                {
                    tx.Inputs[i].ScriptWitness = reader.ReadWithSerializer(protocolVersion, _transactionWitnessSerializer);
                }

                if (!tx.HasWitness())
                {
                    // It's illegal to encode witnesses when all witness stacks are empty.
                    ThrowHelper.ThrowNotSupportedException("Superfluous witness record");
                }
            }

            if (flags != 0)
            {
                /* Unknown flag in the serialization */
                ThrowHelper.ThrowNotSupportedException("Unknown transaction optional data");
            }

            tx.LockTime = reader.ReadUInt();

            return(tx);
        }
 public TransactionWitness Deserialize(ref SequenceReader <byte> reader, int protocolVersion, ProtocolTypeSerializerOptions?options = null)
 {
     return(new TransactionWitness
     {
         Components = reader.ReadArray(protocolVersion, _transactionWitnessComponentSerializer)
     });
 }
Esempio n. 3
0
        public Block Deserialize(ref SequenceReader <byte> reader, int protocolVersion, ProtocolTypeSerializerOptions?options = null)
        {
            options = (options ?? new ProtocolTypeSerializerOptions())
                      .Set(SerializerOptions.HEADER_IN_BLOCK, false);

            return(new Block
            {
                Header = reader.ReadWithSerializer(protocolVersion, _blockHeaderSerializer, options),
                Transactions = reader.ReadArray(protocolVersion, _transactionSerializer, options)
            });
        }
 public override GetDataMessage Deserialize(ref SequenceReader <byte> reader, int protocolVersion, BitcoinPeerContext peerContext)
 {
     return(new GetDataMessage {
         Inventory = reader.ReadArray(protocolVersion, _inventoryVectorSerializer)
     });
 }
Esempio n. 5
0
 public BlockLocator Deserialize(ref SequenceReader <byte> reader, int protocolVersion, ProtocolTypeSerializerOptions?options = null)
 {
     return(new BlockLocator {
         BlockLocatorHashes = reader.ReadArray(protocolVersion, _uInt256Serializator)
     });
 }
 public override HeadersMessage Deserialize(ref SequenceReader <byte> reader, int protocolVersion, BitcoinPeerContext peerContext)
 {
     return(new HeadersMessage {
         Headers = reader.ReadArray(protocolVersion, _blockHeaderSerializer)
     });
 }
Esempio n. 7
0
 public override AddrMessage Deserialize(ref SequenceReader <byte> reader, int protocolVersion, BitcoinPeerContext peerContext)
 {
     return(new AddrMessage {
         Addresses = reader.ReadArray(protocolVersion, _networkAddressSerializer)
     });
 }