2016-09-20 21:28:03 +02:00
|
|
|
/*
|
|
|
|
|
* 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();
|
|
|
|
|
|
2016-11-02 21:05:09 +01:00
|
|
|
/**
|
|
|
|
|
* @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)
|
|
|
|
|
*/
|
2019-03-03 15:26:54 +01:00
|
|
|
bool read(const QString &filename);
|
|
|
|
|
bool read(const QByteArray &data);
|
2016-09-20 21:28:03 +02:00
|
|
|
|
|
|
|
|
void debug() const;
|
2019-03-03 19:47:20 +01:00
|
|
|
// TODO replace textIndent with a string
|
2016-11-10 21:59:36 +01:00
|
|
|
static void debugScript(const QByteArray &script, int textIndent, QTextStream &out);
|
2019-03-03 19:47:20 +01:00
|
|
|
static void checkInScript(const QByteArray &script, int textIndent, QTextStream &out);
|
2016-09-20 21:28:03 +02:00
|
|
|
|
|
|
|
|
enum MessageTags {
|
|
|
|
|
TxEnd = 0, // BoolTrue
|
|
|
|
|
TxInPrevHash, // sha256 (Bytearray)
|
|
|
|
|
TxInPrevIndex, // PositiveNumber
|
2016-11-10 21:59:36 +01:00
|
|
|
TxInputStackItem, // bytearray
|
|
|
|
|
TxInputStackItemContinued, // bytearray
|
2016-09-20 21:28:03 +02:00
|
|
|
TxOutValue, // PositiveNumber (in satoshis)
|
|
|
|
|
TxOutScript, // bytearray
|
2016-11-10 21:59:36 +01:00
|
|
|
TxRelativeBlockLock,// PositiveNumber
|
|
|
|
|
TxRelativeTimeLock, // PositiveNumber
|
|
|
|
|
CoinbaseMessage // Bytearray. Max 100 bytes.
|
2016-09-20 21:28:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private:
|
2024-10-06 19:31:08 +02:00
|
|
|
bool parseTransaction(const QByteArray &bytes);
|
2016-09-20 21:28:03 +02:00
|
|
|
|
|
|
|
|
int m_version;
|
|
|
|
|
|
|
|
|
|
struct TxIn {
|
2016-11-02 20:41:05 +01:00
|
|
|
TxIn() : prevIndex(0), sequence(0) {}
|
|
|
|
|
TxIn(const QByteArray &prevHash) : transaction(prevHash), prevIndex(0), sequence(0) {}
|
2016-09-20 21:28:03 +02:00
|
|
|
QByteArray transaction;
|
|
|
|
|
int prevIndex;
|
2019-03-03 15:26:54 +01:00
|
|
|
QByteArray inputScript;
|
2016-11-10 21:59:36 +01:00
|
|
|
unsigned int sequence;
|
2016-09-20 21:28:03 +02:00
|
|
|
};
|
|
|
|
|
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;
|
2024-10-06 19:42:04 +02:00
|
|
|
QByteArray m_txid;
|
2016-09-20 21:28:03 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|