Skip to content

Commit

Permalink
Namecoin / Qt: Move name operation into Type column
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed Aug 18, 2021
1 parent 6e0d254 commit 279743d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
31 changes: 23 additions & 8 deletions src/qt/transactionrecord.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,23 +107,38 @@ QList<TransactionRecord> 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
{
Expand Down
16 changes: 13 additions & 3 deletions src/qt/transactionrecord.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,25 +84,34 @@ 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)
{
}

TransactionRecord(uint256 _hash, qint64 _time,
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)
{
}

Expand All @@ -119,6 +128,7 @@ class TransactionRecord
std::string address;
CAmount debit;
CAmount credit;
NameOpType nameOpType;
/**@}*/

/** Subtransaction index, for sort key */
Expand Down
16 changes: 15 additions & 1 deletion src/qt/transactiontablemodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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");
Expand Down

0 comments on commit 279743d

Please sign in to comment.