Ejemplo n.º 1
0
 public override void Read(ref SequenceReader <byte> reader)
 {
     Locale             = reader.ReadString();
     ViewDistance       = reader.ReadByte();
     ChatMode           = reader.ReadVarInt();
     ChatColors         = reader.ReadBoolean();
     DisplayedSkinParts = reader.ReadByte();
     MainHand           = reader.ReadVarInt();
 }
Ejemplo n.º 2
0
        public void Byte()
        {
            SequenceWriter writer = CreateSequenceWriter();

            writer.WriteByte(100);
            writer.WriteByte(200);

            SequenceReader reader = new SequenceReader(writer.BuildSequence());

            Assert.Equal(100, reader.ReadByte());
            Assert.Equal(200, reader.ReadByte());
        }
        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);
        }