Skip to content

Commit e87aa72

Browse files
committed
[GUI] Support for proposal outputs (op_return).
1 parent 9d0923f commit e87aa72

File tree

8 files changed

+42
-7
lines changed

8 files changed

+42
-7
lines changed

src/qt/pivx/qtutils.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,8 @@ void setSortTxTypeFilter(QComboBox* filter, SortEdit* lineEditType)
164164
filter->addItem(QObject::tr("Sent"),
165165
TransactionFilterProxy::TYPE(TransactionRecord::SendToAddress) |
166166
TransactionFilterProxy::TYPE(TransactionRecord::SendToOther) |
167-
TransactionFilterProxy::TYPE(TransactionRecord::SendToShielded));
167+
TransactionFilterProxy::TYPE(TransactionRecord::SendToShielded) |
168+
TransactionFilterProxy::TYPE(TransactionRecord::SendToNobody));
168169
filter->addItem(QObject::tr("Shield"),
169170
TransactionFilterProxy::TYPE(TransactionRecord::RecvWithShieldedAddress) |
170171
TransactionFilterProxy::TYPE(TransactionRecord::SendToShielded) |

src/qt/pivx/txrow.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ void TxRow::setType(bool isLightTheme, int type, bool isConfirmed)
9494
case TransactionRecord::ZerocoinSpend_Change_zPiv:
9595
case TransactionRecord::ZerocoinSpend_FromMe:
9696
case TransactionRecord::SendToShielded:
97+
case TransactionRecord::SendToNobody:
9798
path = "://ic-transaction-sent";
9899
css = "text-list-amount-send";
99100
break;

src/qt/pivx/txviewholder.cpp

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,21 @@ void TxViewHolder::init(QWidget* holder, const QModelIndex &index, bool isHovere
3535
type != TransactionRecord::ZerocoinSpend_Change_zPiv &&
3636
type != TransactionRecord::StakeZPIV &&
3737
type != TransactionRecord::Other) {
38+
3839
QString address = rIndex.data(Qt::DisplayRole).toString();
39-
if (address.length() > 20) {
40-
address = address.left(ADDRESS_SIZE) + "..." + address.right(ADDRESS_SIZE);
40+
if (!address.isEmpty()) {
41+
if (type == TransactionRecord::SendToNobody) {
42+
// OP_RETURN record with a valid utf-8 string to show
43+
label.clear();
44+
label += address;
45+
} else {
46+
// Regular addresses
47+
if (address.length() > 20) {
48+
address = address.left(ADDRESS_SIZE) + "..." + address.right(ADDRESS_SIZE);
49+
}
50+
label += " " + address;
51+
}
4152
}
42-
label += " " + address;
4353
} else if (type == TransactionRecord::Other) {
4454
label += rIndex.data(Qt::DisplayRole).toString();
4555
}

src/qt/transactionrecord.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,15 @@ bool TransactionRecord::decomposeDebitTransaction(const CWallet* wallet, const C
329329
// Sent to IP, or other non-address transaction like OP_EVAL
330330
sub.type = TransactionRecord::SendToOther;
331331
sub.address = getValueOrReturnEmpty(wtx.mapValue, "to");
332+
if (sub.address.empty() && txout.scriptPubKey.StartsWithOpcode(OP_RETURN)) {
333+
sub.type = TransactionRecord::SendToNobody;
334+
// Burned PIVs, op_return could be for a proposal/budget fee or another sort of data stored there.
335+
std::string comment = wtx.GetComment();
336+
if (IsValidUTF8(comment)) {
337+
sub.address = comment;
338+
}
339+
// future: could expand this to support base64 or hex encoded messages
340+
}
332341
}
333342

334343
CAmount nValue = txout.nValue;

src/qt/transactionrecord.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ class TransactionRecord
9797
RecvWithShieldedAddress, // Shielded receive
9898
SendToSelfShieldedAddress, // Shielded send to self
9999
SendToSelfShieldToTransparent, // Unshield coins to self
100-
SendToSelfShieldToShieldChangeAddress // Changing coins from one shielded address to another inside the wallet.
100+
SendToSelfShieldToShieldChangeAddress, // Changing coins from one shielded address to another inside the wallet.
101+
SendToNobody // Burned PIVs, op_return output.
101102
};
102103

103104
/** Number of confirmation recommended for accepting a transaction */

src/qt/transactiontablemodel.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,8 @@ QString TransactionTableModel::formatTxType(const TransactionRecord* wtx) const
503503
return tr("Received with shielded");
504504
case TransactionRecord::SendToShielded:
505505
return tr("Shielded send to");
506+
case TransactionRecord::SendToNobody:
507+
return tr("Burned PIVs");
506508
default:
507509
return QString();
508510
}
@@ -555,6 +557,8 @@ QString TransactionTableModel::formatTxToAddress(const TransactionRecord* wtx, b
555557
return QString::fromStdString(wtx->address);
556558
case TransactionRecord::SendToOther:
557559
return QString::fromStdString(wtx->address) + watchAddress;
560+
case TransactionRecord::SendToNobody:
561+
return QString::fromStdString(wtx->address); // the address here is storing the op_return data.
558562
case TransactionRecord::ZerocoinMint:
559563
case TransactionRecord::ZerocoinSpend_Change_zPiv:
560564
case TransactionRecord::StakeZPIV:

src/rpc/budget.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,10 @@ UniValue preparebudget(const JSONRPCRequest& request)
151151
if (res.status != CWallet::CommitStatus::OK)
152152
throw JSONRPCError(RPC_WALLET_ERROR, res.ToString());
153153

154+
// Store proposal name as a comment
155+
assert(pwalletMain->mapWallet.count(wtx.GetHash()));
156+
pwalletMain->mapWallet[wtx.GetHash()].SetComment("Proposal: " + strProposalName);
157+
154158
return wtx.GetHash().ToString();
155159
}
156160

src/wallet/wallet.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ static const int DEFAULT_CUSTOMBACKUPTHRESHOLD = 1;
7474
static const CAmount DEFAULT_MIN_STAKE_SPLIT_THRESHOLD = 100 * COIN;
7575
//! Default for -spendzeroconfchange
7676
static const bool DEFAULT_SPEND_ZEROCONF_CHANGE = true;
77-
//! Default for -sendfreetransactions
78-
static const bool DEFAULT_SEND_FREE_TRANSACTIONS = false;
7977
//! Default for -staking
8078
static const bool DEFAULT_STAKING = true;
8179
//! Default for -coldstaking
@@ -1015,6 +1013,13 @@ class CWalletTx : public CMerkleTx
10151013
//! checks whether a tx has P2CS inputs or not
10161014
bool HasP2CSInputs() const;
10171015

1016+
//! Store a comment
1017+
void SetComment(const std::string& comment) { mapValue["comment"] = comment; }
1018+
std::string GetComment() const {
1019+
const auto& it = mapValue.find("comment");
1020+
return it != mapValue.end() ? it->second : "";
1021+
}
1022+
10181023
int GetDepthAndMempool(bool& fConflicted) const;
10191024

10201025
//! filter decides which addresses will count towards the debit

0 commit comments

Comments
 (0)