Files
transactions/Transaction.h
tomFlowee 2f2cb78741 Fix the txid printing for all input types.
This now prints the txid from inside the Transaction object directly.
2024-10-06 19:42:04 +02:00

85 lines
2.6 KiB
C++

/*
* This file is part of the Bitcoin project
* Copyright (C) 2016 Tom Zander <tomz@freedommail.ch>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <QList>
#include <QString>
#include <QTextStream>
class Transaction
{
public:
Transaction();
/**
* @brief read transaction from a file.
* @return the method returns true if parsing went fine. If lint is LenientParsing
* then we won't fail for simple mistakes (like an incomplete transaction)
*/
bool read(const QString &filename);
bool read(const QByteArray &data);
void debug() const;
// TODO replace textIndent with a string
static void debugScript(const QByteArray &script, int textIndent, QTextStream &out);
static void checkInScript(const QByteArray &script, int textIndent, QTextStream &out);
enum MessageTags {
TxEnd = 0, // BoolTrue
TxInPrevHash, // sha256 (Bytearray)
TxInPrevIndex, // PositiveNumber
TxInputStackItem, // bytearray
TxInputStackItemContinued, // bytearray
TxOutValue, // PositiveNumber (in satoshis)
TxOutScript, // bytearray
TxRelativeBlockLock,// PositiveNumber
TxRelativeTimeLock, // PositiveNumber
CoinbaseMessage // Bytearray. Max 100 bytes.
};
private:
bool parseTransaction(const QByteArray &bytes);
int m_version;
struct TxIn {
TxIn() : prevIndex(0), sequence(0) {}
TxIn(const QByteArray &prevHash) : transaction(prevHash), prevIndex(0), sequence(0) {}
QByteArray transaction;
int prevIndex;
QByteArray inputScript;
unsigned int sequence;
};
struct TxOut {
TxOut(){}
TxOut(const QByteArray &bytes, quint64 val) : script(bytes), value(val) {}
QByteArray script;
quint64 value; // aka amount of satoshis
};
QList<TxIn> m_inputs;
QList<TxOut> m_outputs;
quint32 m_nLockTime;
QByteArray m_txid;
};
#endif