Files

92 lines
3.1 KiB
C++
Raw Permalink Normal View History

2016-09-20 21:28:03 +02:00
/*
* This file is part of the Bitcoin project
* Copyright (C) 2014-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/>.
*/
#include "Transaction.h"
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QFileInfo>
#include <QDebug>
int main(int x, char **y) {
QCoreApplication app(x, y);
QCoreApplication::setApplicationName("Transactions");
2024-01-09 21:14:16 +01:00
QCoreApplication::setApplicationVersion("1.1");
2016-09-20 21:28:03 +02:00
QCommandLineParser parser;
parser.setApplicationDescription("Transactions investigations");
parser.addHelpOption();
parser.addPositionalArgument("transaction", "Source transaction");
2016-11-01 20:23:53 +01:00
QCommandLineOption rawtx(QStringList() << "rawtx", "pass a raw hexformatted transaction instead of a filename" );
parser.addOption(rawtx);
2024-09-05 13:27:46 +02:00
QCommandLineOption printRaw(QStringList() << "p" << "printRaw", "Print raw hex version");
2020-06-11 10:04:44 +02:00
parser.addOption(printRaw);
2024-09-17 10:32:02 +02:00
QCommandLineOption script(QStringList() << "rawscript", "pass raw hexformatted script");
parser.addOption(script);
2016-09-20 21:28:03 +02:00
parser.process(app);
const QStringList args = parser.positionalArguments();
if (args.isEmpty())
parser.showHelp(1);
2020-06-11 10:04:44 +02:00
QTextStream out(stdout);
2024-09-17 10:32:02 +02:00
if (parser.isSet(script)) {
if (parser.isSet(rawtx)) {
out << "ERROR: pass only one, either input script or rawtx.\n";
out << "Bailing out" << Qt::endl;
return 1;
}
QByteArray data = QByteArray::fromHex(args.at(0).toLatin1());
Transaction::debugScript(data, 0, out);
return 0;
}
2016-09-20 21:28:03 +02:00
Transaction t;
2016-11-10 21:59:36 +01:00
bool success;
2016-11-01 20:23:53 +01:00
if (parser.isSet(rawtx)) {
QByteArray data = QByteArray::fromHex(args.at(0).toLatin1());
2019-03-03 15:26:54 +01:00
success = t.read(data);
2016-11-01 20:23:53 +01:00
} else {
2019-03-03 15:26:54 +01:00
success = t.read(args.at(0));
2016-11-01 20:23:53 +01:00
}
2020-06-11 10:04:44 +02:00
if (parser.isSet(printRaw)) {
2024-09-17 10:32:02 +02:00
if (parser.isSet(rawtx) || parser.isSet(script)) {
2024-09-05 13:27:46 +02:00
out << "ERROR: printraw and rawtx both as arguments makes no sense.\n";
out << "Sorry, not doing it" << Qt::endl;
return 1;
}
2020-06-11 10:04:44 +02:00
QFile in(args.at(0));
if (in.open(QIODevice::ReadOnly)) {
QByteArray all = in.readAll();
out << "Serialized: " << QString::fromLatin1(all.toHex()) << Qt::endl;
}
}
2016-09-20 21:28:03 +02:00
2016-11-10 21:59:36 +01:00
if (!success)
return 1;
2024-09-05 13:27:46 +02:00
QByteArray data = QByteArray::fromHex(args.at(0).toLatin1());
t.debug();
if (parser.isSet(rawtx))
out << "size: " << data.length() << Qt::endl;
out << "\n\n";
2020-06-11 10:04:44 +02:00
out.flush();
2016-09-20 21:28:03 +02:00
return 0;
}