Пример #1
0
            private void DeserializeTxn(BitcoinStream stream)
            {
                UInt32 nVersionTemp = 0;

                stream.ReadWrite(ref nVersionTemp);

                // POS time stamp
                UInt32 nTimeTemp = 0;

                stream.ReadWrite(ref nTimeTemp);

                TxInList  vinTemp  = null;
                TxOutList voutTemp = null;

                // Try to read the vin.
                stream.ReadWrite(ref vinTemp);
                vinTemp.Transaction = this;
                // Assume a normal vout follows.
                stream.ReadWrite(ref voutTemp);
                voutTemp.Transaction = this;

                LockTime lockTimeTemp = LockTime.Zero;

                stream.ReadWriteStruct(ref lockTimeTemp);

                this.Version = nVersionTemp;
                this.Time    = nTimeTemp;              // POS Timestamp
                vinTemp.ForEach(i => this.Inputs.Add(i));
                voutTemp.ForEach(i => this.Outputs.Add(i));
                this.LockTime = lockTimeTemp;
            }
Пример #2
0
            private void DeserializeTxn(BitcoinStream stream, bool witSupported)
            {
                byte flags = 0;

                UInt32 nVersionTemp = 0;

                stream.ReadWrite(ref nVersionTemp);

                // POS time stamp
                uint nTimeTemp = 0;

                stream.ReadWrite(ref nTimeTemp);

                TxInList  vinTemp  = new TxInList();
                TxOutList voutTemp = new TxOutList();

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

                var hasNoDummy = (nVersionTemp & NoDummyInput) != 0 && vinTemp.Count == 0;

                if (witSupported && hasNoDummy)
                {
                    nVersionTemp = nVersionTemp & ~NoDummyInput;
                }

                if (vinTemp.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 vinTemp);
                        vinTemp.Transaction = this;
                        stream.ReadWrite <TxOutList, TxOut>(ref voutTemp);
                        voutTemp.Transaction = this;
                    }
                    else
                    {
                        // Assume read a transaction without output.
                        voutTemp             = new TxOutList();
                        voutTemp.Transaction = this;
                    }
                }
                else
                {
                    // We read a non-empty vin. Assume a normal vout follows.
                    stream.ReadWrite <TxOutList, TxOut>(ref voutTemp);
                    voutTemp.Transaction = this;
                }
                if (((flags & 1) != 0) && witSupported)
                {
                    // The witness flag is present, and we support witnesses.
                    flags ^= 1;
                    StratisWitness wit = new StratisWitness(vinTemp);
                    wit.ReadWrite(stream);
                }
                if (flags != 0)
                {
                    // Unknown flag in the serialization
                    throw new FormatException("Unknown transaction optional data");
                }
                LockTime lockTimeTemp = LockTime.Zero;

                stream.ReadWriteStruct(ref lockTimeTemp);

                this.Version = nVersionTemp;
                this.Time    = nTimeTemp; // POS Timestamp
                vinTemp.ForEach(i => this.AddInput(i));
                voutTemp.ForEach(i => this.AddOutput(i));
                this.LockTime = lockTimeTemp;
            }