Skip to content

Commit 7d7bef5

Browse files
committed
feat: make a support of Qt app to show withdrawal transaction as a new type of transaction
1 parent 47e3197 commit 7d7bef5

10 files changed

+37
-6
lines changed

src/interfaces/wallet.h

+2
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,7 @@ struct WalletTx
408408
int64_t time;
409409
std::map<std::string, std::string> value_map;
410410
bool is_coinbase;
411+
bool is_withdrawal;
411412
bool is_denominate;
412413
};
413414

@@ -423,6 +424,7 @@ struct WalletTxStatus
423424
bool is_trusted;
424425
bool is_abandoned;
425426
bool is_coinbase;
427+
bool is_withdrawal;
426428
bool is_in_main_chain;
427429
bool is_chainlocked;
428430
bool is_islocked;

src/primitives/transaction.h

+5
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,11 @@ class CTransaction
264264
return nVersion >= SPECIAL_VERSION;
265265
}
266266

267+
bool IsWithdrawal() const noexcept
268+
{
269+
return IsSpecialTxVersion() && nType == TRANSACTION_ASSET_UNLOCK;
270+
}
271+
267272
bool HasExtraPayloadField() const noexcept
268273
{
269274
return IsSpecialTxVersion() && nType != TRANSACTION_NORMAL;

src/qt/transactiondesc.cpp

+4
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
9393
{
9494
strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>";
9595
}
96+
else if (wtx.is_withdrawal)
97+
{
98+
strHTML += "<b>" + tr("Source") + ":</b> " + tr("Withdrawal") + "<br>";
99+
}
96100
else if (wtx.value_map.count("from") && !wtx.value_map["from"].empty())
97101
{
98102
// Online transaction

src/qt/transactionrecord.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(interfaces::Wal
3939
auto node = interfaces::MakeNode();
4040
auto& coinJoinOptions = node->coinJoinOptions();
4141

42-
if (nNet > 0 || wtx.is_coinbase)
42+
if (nNet > 0 || wtx.is_coinbase || wtx.is_withdrawal)
4343
{
4444
//
4545
// Credit
@@ -74,6 +74,11 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(interfaces::Wal
7474
// Generated
7575
sub.type = TransactionRecord::Generated;
7676
}
77+
if (wtx.is_withdrawal)
78+
{
79+
// Withdrawal from platform
80+
sub.type = TransactionRecord::Withdrawal;
81+
}
7782

7883
parts.append(sub);
7984
}
@@ -287,7 +292,7 @@ void TransactionRecord::updateStatus(const interfaces::WalletTxStatus& wtx, cons
287292
}
288293
}
289294
// For generated transactions, determine maturity
290-
else if(type == TransactionRecord::Generated)
295+
else if(type == TransactionRecord::Generated || type == TransactionRecord::Withdrawal)
291296
{
292297
if (wtx.blocks_to_maturity > 0)
293298
{

src/qt/transactionrecord.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class TransactionRecord
9696
CoinJoinCollateralPayment,
9797
CoinJoinMakeCollaterals,
9898
CoinJoinCreateDenominations,
99-
CoinJoinSend
99+
CoinJoinSend,
100+
Withdrawal,
100101
};
101102

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

src/qt/transactiontablemodel.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,7 @@ QVariant TransactionTableModel::amountColor(const TransactionRecord *rec) const
530530
case TransactionRecord::RecvWithCoinJoin:
531531
case TransactionRecord::RecvWithAddress:
532532
case TransactionRecord::RecvFromOther:
533+
case TransactionRecord::Withdrawal:
533534
return GUIUtil::getThemedQColor(GUIUtil::ThemedColor::GREEN);
534535
case TransactionRecord::CoinJoinSend:
535536
case TransactionRecord::SendToAddress:

src/qt/transactionview.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ TransactionView::TransactionView(QWidget* parent) :
9090
typeWidget->addItem(tr("%1 Collateral Payment").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinCollateralPayment));
9191
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
9292
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
93+
typeWidget->addItem(tr("Withdrawal"), TransactionFilterProxy::TYPE(TransactionRecord::Withdrawal));
9394
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));
9495
typeWidget->setCurrentIndex(settings.value("transactionType").toInt());
9596

src/wallet/interfaces.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
8181
result.time = wtx.GetTxTime();
8282
result.value_map = wtx.mapValue;
8383
result.is_coinbase = wtx.IsCoinBase();
84+
result.is_withdrawal = wtx.IsWithdrawal();
8485
// The determination of is_denominate is based on simplified checks here because in this part of the code
8586
// we only want to know about mixing transactions belonging to this specific wallet.
8687
result.is_denominate = wtx.tx->vin.size() == wtx.tx->vout.size() && // Number of inputs is same as number of outputs
@@ -102,6 +103,7 @@ WalletTxStatus MakeWalletTxStatus(const CWallet& wallet, const CWalletTx& wtx)
102103
result.is_trusted = wtx.IsTrusted();
103104
result.is_abandoned = wtx.isAbandoned();
104105
result.is_coinbase = wtx.IsCoinBase();
106+
result.is_withdrawal = wtx.IsWithdrawal();
105107
result.is_in_main_chain = wtx.IsInMainChain();
106108
result.is_chainlocked = wtx.IsChainLocked();
107109
result.is_islocked = wtx.IsLockedByInstantSend();

src/wallet/rpcwallet.cpp

+12-3
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,8 @@ static void WalletTxToJSON(interfaces::Chain& chain, const CWalletTx& wtx, UniVa
167167
entry.pushKV("chainlock", chainlock);
168168
if (wtx.IsCoinBase())
169169
entry.pushKV("generated", true);
170+
if (wtx.IsWithdrawal())
171+
entry.pushKV("withdrawal", true);
170172
if (confirms > 0)
171173
{
172174
entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex());
@@ -1419,6 +1421,10 @@ static void ListTransactions(const CWallet* const pwallet, const CWalletTx& wtx,
14191421
else
14201422
entry.pushKV("category", "generate");
14211423
}
1424+
else if (wtx.IsWithdrawal())
1425+
{
1426+
entry.pushKV("category", "withdrawal");
1427+
}
14221428
else
14231429
{
14241430
entry.pushKV("category", "receive");
@@ -1483,7 +1489,8 @@ static RPCHelpMan listtransactions()
14831489
"\"receive\" Non-coinbase transactions received.\n"
14841490
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
14851491
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
1486-
"\"orphan\" Orphaned coinbase transactions received.\n"},
1492+
"\"orphan\" Orphaned coinbase transactions received.\n"
1493+
"\"withdrawal\" Withdrawal transactions received.\n"},
14871494
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
14881495
"for all other categories"},
14891496
{RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"},
@@ -1599,7 +1606,8 @@ static RPCHelpMan listsinceblock()
15991606
"\"receive\" Non-coinbase transactions received.\n"
16001607
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
16011608
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
1602-
"\"orphan\" Orphaned coinbase transactions received.\n"},
1609+
"\"orphan\" Orphaned coinbase transactions received.\n"
1610+
"\"withdrawal\" Withdrawal transactions received.\n"},
16031611
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
16041612
"for all other categories"},
16051613
{RPCResult::Type::NUM, "vout", "the vout value"},
@@ -1740,7 +1748,8 @@ static RPCHelpMan gettransaction()
17401748
"\"receive\" Non-coinbase transactions received.\n"
17411749
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
17421750
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
1743-
"\"orphan\" Orphaned coinbase transactions received.\n"},
1751+
"\"orphan\" Orphaned coinbase transactions received.\n"
1752+
"\"withdrawal\" Withdrawal transactions received.\n"},
17441753
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT},
17451754
{RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"},
17461755
{RPCResult::Type::NUM, "vout", "the vout value"},

src/wallet/wallet.h

+1
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,7 @@ class CWalletTx
591591
void setConfirmed() { m_confirm.status = CWalletTx::CONFIRMED; }
592592
const uint256& GetHash() const { return tx->GetHash(); }
593593
bool IsCoinBase() const { return tx->IsCoinBase(); }
594+
bool IsWithdrawal() const { return tx->IsWithdrawal(); }
594595
bool IsImmatureCoinBase() const;
595596

596597
// Disable copying of CWalletTx objects to prevent bugs where instances get

0 commit comments

Comments
 (0)