コード例 #1
0
        private TransactionInput ReadTransactionInput(LoggedBinaryReader binaryReader)
        {
            var transactionHash = binaryReader.ReadBytes(InputTransactionHashLength);
            var outputIndex     = binaryReader.ReadUInt32();
            var scriptSig       = _hexReader.ReadVarString(binaryReader);
            var sequence        = binaryReader.ReadUInt32();

            return(new TransactionInput(transactionHash, outputIndex, scriptSig, sequence));
        }
コード例 #2
0
        public Transaction ReadTransaction(LoggedBinaryReader binaryReader)
        {
            var version = binaryReader.ReadUInt32();

            var countTransactionInputs = _hexReader.ReadVarInt(binaryReader, Endian.Little, out _);
            var hasWitness             = countTransactionInputs == 0;

            if (hasWitness)
            {
                // todo: use SegWit
                var __ = binaryReader.ReadByte();

                countTransactionInputs = _hexReader.ReadVarInt(binaryReader, Endian.Little, out _);
            }

            // todo: use transaction input pool here
            var transactionInputs = new TransactionInput[countTransactionInputs];

            for (var i = 0; i < countTransactionInputs; i++)
            {
                transactionInputs[i] = ReadTransactionInput(binaryReader);
            }

            var countTransactionOutputs = _hexReader.ReadVarInt(binaryReader, Endian.Little, out _);

            // todo: use transaction output pool here
            var transactionOutputs = new TransactionOutput[countTransactionOutputs];

            for (var i = 0; i < countTransactionOutputs; i++)
            {
                transactionOutputs[i] = ReadTransactionOutput(binaryReader);
            }

            var witnessAsciiStrings = new List <AsciiString>();

            if (hasWitness)
            {
                for (var i = 0; i < countTransactionInputs; i++)
                {
                    var countWitnessStackItems = _hexReader.ReadVarInt(binaryReader, Endian.Little, out _);
                    for (var j = 0; j < countWitnessStackItems; j++)
                    {
                        witnessAsciiStrings.Add(_hexReader.ReadVarString(binaryReader));
                    }
                }
            }

            var lockTime = binaryReader.ReadUInt32();

            var txId = GetTrxId(binaryReader.AsSpan());

            return(new Transaction(txId, version, transactionInputs, transactionOutputs, lockTime, hasWitness, witnessAsciiStrings));
        }