Skip to content

Commit b4f3e9c

Browse files
committed
ui: Add "Copy raw transaction data" to transaction list context menu
Add a way to quickly copy transaction hex. Primarily useful when manually submitting transactions, e.g. `-walletbroadcast=0` is set.
1 parent eac53ec commit b4f3e9c

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

src/qt/transactiontablemodel.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "transactionrecord.h"
1414
#include "walletmodel.h"
1515

16+
#include "core_io.h"
1617
#include "main.h"
1718
#include "sync.h"
1819
#include "uint256.h"
@@ -220,6 +221,18 @@ class TransactionTablePriv
220221
}
221222
return QString();
222223
}
224+
225+
QString getTxHex(TransactionRecord *rec)
226+
{
227+
LOCK2(cs_main, wallet->cs_wallet);
228+
std::map<uint256, CWalletTx>::iterator mi = wallet->mapWallet.find(rec->hash);
229+
if(mi != wallet->mapWallet.end())
230+
{
231+
std::string strHex = EncodeHexTx(static_cast<CTransaction>(mi->second));
232+
return QString::fromStdString(strHex);
233+
}
234+
return QString();
235+
}
223236
};
224237

225238
TransactionTableModel::TransactionTableModel(const PlatformStyle *platformStyle, CWallet* wallet, WalletModel *parent):
@@ -594,6 +607,8 @@ QVariant TransactionTableModel::data(const QModelIndex &index, int role) const
594607
return rec->getTxID();
595608
case TxHashRole:
596609
return QString::fromStdString(rec->hash.ToString());
610+
case TxHexRole:
611+
return priv->getTxHex(rec);
597612
case ConfirmedRole:
598613
return rec->status.countsForBalance;
599614
case FormattedAmountRole:

src/qt/transactiontablemodel.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ class TransactionTableModel : public QAbstractTableModel
6060
TxIDRole,
6161
/** Transaction hash */
6262
TxHashRole,
63+
/** Transaction data, hex-encoded */
64+
TxHexRole,
6365
/** Is transaction confirmed? */
6466
ConfirmedRole,
6567
/** Formatted amount, without brackets when unconfirmed */

src/qt/transactionview.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
141141
QAction *copyLabelAction = new QAction(tr("Copy label"), this);
142142
QAction *copyAmountAction = new QAction(tr("Copy amount"), this);
143143
QAction *copyTxIDAction = new QAction(tr("Copy transaction ID"), this);
144+
QAction *copyTxHexAction = new QAction(tr("Copy raw transaction"), this);
144145
QAction *editLabelAction = new QAction(tr("Edit label"), this);
145146
QAction *showDetailsAction = new QAction(tr("Show transaction details"), this);
146147

@@ -149,6 +150,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
149150
contextMenu->addAction(copyLabelAction);
150151
contextMenu->addAction(copyAmountAction);
151152
contextMenu->addAction(copyTxIDAction);
153+
contextMenu->addAction(copyTxHexAction);
152154
contextMenu->addAction(editLabelAction);
153155
contextMenu->addAction(showDetailsAction);
154156

@@ -170,6 +172,7 @@ TransactionView::TransactionView(const PlatformStyle *platformStyle, QWidget *pa
170172
connect(copyLabelAction, SIGNAL(triggered()), this, SLOT(copyLabel()));
171173
connect(copyAmountAction, SIGNAL(triggered()), this, SLOT(copyAmount()));
172174
connect(copyTxIDAction, SIGNAL(triggered()), this, SLOT(copyTxID()));
175+
connect(copyTxHexAction, SIGNAL(triggered()), this, SLOT(copyTxHex()));
173176
connect(editLabelAction, SIGNAL(triggered()), this, SLOT(editLabel()));
174177
connect(showDetailsAction, SIGNAL(triggered()), this, SLOT(showDetails()));
175178
}
@@ -380,6 +383,11 @@ void TransactionView::copyTxID()
380383
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxIDRole);
381384
}
382385

386+
void TransactionView::copyTxHex()
387+
{
388+
GUIUtil::copyEntryData(transactionView, 0, TransactionTableModel::TxHexRole);
389+
}
390+
383391
void TransactionView::editLabel()
384392
{
385393
if(!transactionView->selectionModel() ||!model)

src/qt/transactionview.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ private Q_SLOTS:
9393
void copyLabel();
9494
void copyAmount();
9595
void copyTxID();
96+
void copyTxHex();
9697
void openThirdPartyTxUrl(QString url);
9798
void updateWatchOnlyColumn(bool fHaveWatchOnly);
9899

0 commit comments

Comments
 (0)