示例#1
0
 public static IEnumerable <TxoRef> ToTxoRefs(this TxInList me)
 {
     foreach (var input in me)
     {
         yield return(input.PrevOut.ToTxoRef());
     }
 }
        public void ReadWrite(ref TxInList list)
        {
            int listLen = 0;

            if (Serializing)
            {
                var len = list == null ? 0 : (ulong)list.Count;
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                VarInt.StaticWrite(this, len);
                if (len == 0)
                {
                    return;
                }
                listLen = (int)len;
                foreach (var obj in list)
                {
                    ReadWrite(obj);
                }
            }
            else
            {
                var len = VarInt.StaticRead(this);
                if (len > (uint)MaxArraySize)
                {
                    throw new ArgumentOutOfRangeException("Array size too big");
                }
                listLen = (int)len;
                list    = new TxInList(listLen);
                for (int i = 0; i < listLen; i++)
                {
                    TxIn obj = default;
                    ReadWrite(ref obj);
                    list.Add(obj);
                }
            }
        }
示例#3
0
 public Transaction()
 {
     vin  = new TxInList(this);
     vout = new TxOutList(this);
 }
示例#4
0
 private void Init()
 {
     vin  = new TxInList(this);
     vout = new TxOutList(this);
 }
示例#5
0
        public virtual void ReadWrite(BitcoinStream stream)
        {
            var witSupported = (((uint)stream.TransactionOptions & (uint)TransactionOptions.Witness) != 0) &&
                               stream.ProtocolVersion >= ProtocolVersion.WITNESS_VERSION;

            byte flags = 0;

            if (!stream.Serializing)
            {
                stream.ReadWrite(ref nVersion);
                /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
                stream.ReadWrite <TxInList, TxIn>(ref vin);

                var hasNoDummy = (nVersion & NoDummyInput) != 0 && vin.Count == 0;
                if (hasNoDummy)
                {
                    nVersion = nVersion & ~NoDummyInput;
                }

                if (vin.Count == 0 && witSupported && !hasNoDummy)
                {
                    /* We read a dummy or an empty vin. */
                    stream.ReadWrite(ref flags);
                    if (flags != 0)
                    {
                        /* Assume we read a dummy and a flag. */
                        stream.ReadWrite <TxInList, TxIn>(ref vin);
                        vin.Transaction = this;
                        stream.ReadWrite <TxOutList, TxOut>(ref vout);
                        vout.Transaction = this;
                    }
                }
                else
                {
                    /* We read a non-empty vin. Assume a normal vout follows. */
                    stream.ReadWrite <TxOutList, TxOut>(ref vout);
                    vout.Transaction = this;
                }
                wit.SetNull();
                if (((flags & 1) != 0) && witSupported)
                {
                    /* The witness flag is present, and we support witnesses. */
                    flags ^= 1;
                    //const_cast<CTxWitness*>(&tx.wit)->vtxinwit.resize(tx.vin.size());
                    wit.Size(vin.Count);
                    wit.ReadWrite(stream);
                }
                if (flags != 0)
                {
                    /* Unknown flag in the serialization */
                    throw new FormatException("Unknown transaction optional data");
                }
            }
            else
            {
                var version = vin.Count == 0 && vout.Count > 0 ? nVersion | NoDummyInput : nVersion;
                stream.ReadWrite(ref version);

                if (witSupported)
                {
                    /* Check whether witnesses need to be serialized. */
                    if (!wit.IsNull())
                    {
                        flags |= 1;
                    }
                }
                if (flags != 0)
                {
                    /* Use extended format in case witnesses are to be serialized. */
                    TxInList vinDummy = new TxInList();
                    stream.ReadWrite <TxInList, TxIn>(ref vinDummy);
                    stream.ReadWrite(ref flags);
                }
                stream.ReadWrite <TxInList, TxIn>(ref vin);
                vin.Transaction = this;
                stream.ReadWrite <TxOutList, TxOut>(ref vout);
                vout.Transaction = this;
                if ((flags & 1) != 0)
                {
                    wit.Size(vin.Count);
                    wit.ReadWrite(stream);
                }
            }
            stream.ReadWriteStruct(ref nLockTime);
        }
示例#6
0
        public override void ReadWrite(BitcoinStream stream)
        {
            bool witSupported = (((uint)stream.TransactionOptions & (uint)TransactionOptions.Witness) != 0) &&
                                stream.ProtocolVersion >= ProtocolVersion.WITNESS_VERSION;

            byte flags = 0;

            if (!stream.Serializing)
            {
                stream.ReadWrite(ref this.nVersion);

                // POS time stamp
                stream.ReadWrite(ref this.nTime);

                /* Try to read the vin. In case the dummy is there, this will be read as an empty vector. */
                stream.ReadWrite <TxInList, TxIn>(ref this.vin);

                bool hasNoDummy = (this.nVersion & NoDummyInput) != 0 && this.vin.Count == 0;
                if (witSupported && hasNoDummy)
                {
                    this.nVersion = this.nVersion & ~NoDummyInput;
                }

                if (this.vin.Count == 0 && witSupported && !hasNoDummy)
                {
                    /* We read a dummy or an empty vin. */
                    stream.ReadWrite(ref flags);
                    if (flags != 0)
                    {
                        /* Assume we read a dummy and a flag. */
                        stream.ReadWrite <TxInList, TxIn>(ref this.vin);
                        this.vin.Transaction = this;
                        stream.ReadWrite <TxOutList, TxOut>(ref this.vout);
                        this.vout.Transaction = this;
                    }
                    else
                    {
                        /* Assume read a transaction without output. */
                        this.vout             = new TxOutList();
                        this.vout.Transaction = this;
                    }
                }
                else
                {
                    /* We read a non-empty vin. Assume a normal vout follows. */
                    stream.ReadWrite <TxOutList, TxOut>(ref this.vout);
                    this.vout.Transaction = this;
                }
                if (((flags & 1) != 0) && witSupported)
                {
                    /* The witness flag is present, and we support witnesses. */
                    flags ^= 1;
                    var wit = new Witness(this.Inputs);
                    wit.ReadWrite(stream);
                }
                if (flags != 0)
                {
                    /* Unknown flag in the serialization */
                    throw new FormatException("Unknown transaction optional data");
                }
            }
            else
            {
                uint version = (witSupported && (this.vin.Count == 0 && this.vout.Count > 0)) ? this.nVersion | NoDummyInput : this.nVersion;
                stream.ReadWrite(ref version);

                // the POS time stamp
                stream.ReadWrite(ref this.nTime);

                if (witSupported)
                {
                    /* Check whether witnesses need to be serialized. */
                    if (this.HasWitness)
                    {
                        flags |= 1;
                    }
                }
                if (flags != 0)
                {
                    /* Use extended format in case witnesses are to be serialized. */
                    var vinDummy = new TxInList();
                    stream.ReadWrite <TxInList, TxIn>(ref vinDummy);
                    stream.ReadWrite(ref flags);
                }
                stream.ReadWrite <TxInList, TxIn>(ref this.vin);
                this.vin.Transaction = this;
                stream.ReadWrite <TxOutList, TxOut>(ref this.vout);
                this.vout.Transaction = this;
                if ((flags & 1) != 0)
                {
                    var wit = new Witness(this.Inputs);
                    wit.ReadWrite(stream);
                }
            }
            stream.ReadWriteStruct(ref this.nLockTime);
        }