From 279743d6ddf554eaeaea93019477a22605642c10 Mon Sep 17 00:00:00 2001 From: Jeremy Rand Date: Sun, 8 Aug 2021 14:28:59 +0000 Subject: [PATCH] Namecoin / Qt: Move name operation into Type column --- src/qt/transactionrecord.cpp | 31 +++++++++++++++++++++++-------- src/qt/transactionrecord.h | 16 +++++++++++++--- src/qt/transactiontablemodel.cpp | 16 +++++++++++++++- 3 files changed, 51 insertions(+), 12 deletions(-) diff --git a/src/qt/transactionrecord.cpp b/src/qt/transactionrecord.cpp index d72f053d0d..3fa8d45d4e 100644 --- a/src/qt/transactionrecord.cpp +++ b/src/qt/transactionrecord.cpp @@ -107,23 +107,38 @@ QList TransactionRecord::decomposeTransaction(const interface if(nNameCredit) { - // TODO: Use "Pre-Registration" / "Registration" / "Update" strings - std::string opName = GetOpName(nNameCredit.value().getNameOp()); - std::string description = opName.substr(3); + TransactionRecord sub(hash, nTime, TransactionRecord::NameOp, "", -(nDebit - nChange), nCredit - nChange); // TODO: Use friendly names based on namespaces if(nNameCredit.value().isAnyUpdate()) { - // Check if renewal (previous value is unchanged) - if(nNameDebit && nNameDebit.value().isAnyUpdate() && nNameDebit.value().getOpValue() == nNameCredit.value().getOpValue()) + if(nNameCredit.value().getNameOp() == OP_NAME_FIRSTUPDATE) { - description = "NAME_RENEW"; + sub.nameOpType = TransactionRecord::NameOpType::FirstUpdate; + } + else + { + // OP_NAME_UPDATE + + // Check if renewal (previous value is unchanged) + if(nNameDebit && nNameDebit.value().isAnyUpdate() && nNameDebit.value().getOpValue() == nNameCredit.value().getOpValue()) + { + sub.nameOpType = TransactionRecord::NameOpType::Renew; + } + else + { + sub.nameOpType = TransactionRecord::NameOpType::Update; + } } - description += " " + EncodeNameForMessage(nNameCredit.value().getOpName()); + sub.address = EncodeNameForMessage(nNameCredit.value().getOpName()); + } + else + { + sub.nameOpType = TransactionRecord::NameOpType::New; } - parts.append(TransactionRecord(hash, nTime, TransactionRecord::NameOp, description, -(nDebit - nChange), nCredit - nChange)); + parts.append(sub); } else { diff --git a/src/qt/transactionrecord.h b/src/qt/transactionrecord.h index caa29cc2a0..932a122878 100644 --- a/src/qt/transactionrecord.h +++ b/src/qt/transactionrecord.h @@ -84,17 +84,26 @@ class TransactionRecord NameOp, }; + enum class NameOpType + { + Other, + New, + FirstUpdate, + Update, + Renew, + }; + /** Number of confirmation recommended for accepting a transaction */ static const int RecommendedNumConfirmations = 6; TransactionRecord(): - hash(), time(0), type(Other), address(""), debit(0), credit(0), idx(0) + hash(), time(0), type(Other), address(""), debit(0), credit(0), nameOpType(NameOpType::Other), idx(0) { } TransactionRecord(uint256 _hash, qint64 _time): hash(_hash), time(_time), type(Other), address(""), debit(0), - credit(0), idx(0) + credit(0), nameOpType(NameOpType::Other), idx(0) { } @@ -102,7 +111,7 @@ class TransactionRecord Type _type, const std::string &_address, const CAmount& _debit, const CAmount& _credit): hash(_hash), time(_time), type(_type), address(_address), debit(_debit), credit(_credit), - idx(0) + nameOpType(NameOpType::Other), idx(0) { } @@ -119,6 +128,7 @@ class TransactionRecord std::string address; CAmount debit; CAmount credit; + NameOpType nameOpType; /**@}*/ /** Subtransaction index, for sort key */ diff --git a/src/qt/transactiontablemodel.cpp b/src/qt/transactiontablemodel.cpp index b7ba3bd998..ce18327f2b 100644 --- a/src/qt/transactiontablemodel.cpp +++ b/src/qt/transactiontablemodel.cpp @@ -391,7 +391,20 @@ QString TransactionTableModel::formatTxType(const TransactionRecord *wtx) const case TransactionRecord::Generated: return tr("Mined"); case TransactionRecord::NameOp: - return tr("Name operation"); + switch(wtx->nameOpType) + { + case TransactionRecord::NameOpType::New: + return tr("Name pre-registration"); + case TransactionRecord::NameOpType::FirstUpdate: + return tr("Name registration"); + case TransactionRecord::NameOpType::Update: + return tr("Name update"); + case TransactionRecord::NameOpType::Renew: + return tr("Name renewal"); + case TransactionRecord::NameOpType::Other: + return tr("Unknown name operation"); + } // no default case, so the compiler can warn about missing cases + assert(false); default: return QString(); } @@ -410,6 +423,7 @@ QVariant TransactionTableModel::txAddressDecoration(const TransactionRecord *wtx case TransactionRecord::SendToOther: return QIcon(":/icons/tx_output"); case TransactionRecord::NameOp: + // TODO: Use nameOpType here return QIcon(":/icons/bitcoin_transparent_letter"); default: return QIcon(":/icons/tx_inout");