feat: make a support of Qt app to show Platform Transfer transaction as a new type of transaction

This commit is contained in:
Konstantin Akimov 2024-07-17 12:41:51 +07:00 committed by pasta
parent 28e20b31eb
commit 1fb67ece0e
No known key found for this signature in database
GPG Key ID: 52527BEDABE87984
10 changed files with 34 additions and 5 deletions

View File

@ -411,6 +411,7 @@ struct WalletTx
int64_t time; int64_t time;
std::map<std::string, std::string> value_map; std::map<std::string, std::string> value_map;
bool is_coinbase; bool is_coinbase;
bool is_platform_transfer{false};
bool is_denominate; bool is_denominate;
}; };

View File

@ -264,6 +264,11 @@ public:
return nVersion >= SPECIAL_VERSION; return nVersion >= SPECIAL_VERSION;
} }
bool IsPlatformTransfer() const noexcept
{
return IsSpecialTxVersion() && nType == TRANSACTION_ASSET_UNLOCK;
}
bool HasExtraPayloadField() const noexcept bool HasExtraPayloadField() const noexcept
{ {
return IsSpecialTxVersion() && nType != TRANSACTION_NORMAL; return IsSpecialTxVersion() && nType != TRANSACTION_NORMAL;

View File

@ -93,6 +93,10 @@ QString TransactionDesc::toHTML(interfaces::Node& node, interfaces::Wallet& wall
{ {
strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>"; strHTML += "<b>" + tr("Source") + ":</b> " + tr("Generated") + "<br>";
} }
else if (wtx.is_platform_transfer)
{
strHTML += "<b>" + tr("Source") + ":</b> " + tr("Platform Transfer") + "<br>";
}
else if (wtx.value_map.count("from") && !wtx.value_map["from"].empty()) else if (wtx.value_map.count("from") && !wtx.value_map["from"].empty())
{ {
// Online transaction // Online transaction

View File

@ -39,7 +39,7 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(interfaces::Wal
auto node = interfaces::MakeNode(); auto node = interfaces::MakeNode();
auto& coinJoinOptions = node->coinJoinOptions(); auto& coinJoinOptions = node->coinJoinOptions();
if (nNet > 0 || wtx.is_coinbase) if (nNet > 0 || wtx.is_coinbase || wtx.is_platform_transfer)
{ {
// //
// Credit // Credit
@ -74,6 +74,11 @@ QList<TransactionRecord> TransactionRecord::decomposeTransaction(interfaces::Wal
// Generated // Generated
sub.type = TransactionRecord::Generated; sub.type = TransactionRecord::Generated;
} }
if (wtx.is_platform_transfer)
{
// Withdrawal from platform
sub.type = TransactionRecord::PlatformTransfer;
}
parts.append(sub); parts.append(sub);
} }

View File

@ -96,7 +96,8 @@ public:
CoinJoinCollateralPayment, CoinJoinCollateralPayment,
CoinJoinMakeCollaterals, CoinJoinMakeCollaterals,
CoinJoinCreateDenominations, CoinJoinCreateDenominations,
CoinJoinSend CoinJoinSend,
PlatformTransfer,
}; };
/** Number of confirmation recommended for accepting a transaction */ /** Number of confirmation recommended for accepting a transaction */

View File

@ -530,6 +530,7 @@ QVariant TransactionTableModel::amountColor(const TransactionRecord *rec) const
case TransactionRecord::RecvWithCoinJoin: case TransactionRecord::RecvWithCoinJoin:
case TransactionRecord::RecvWithAddress: case TransactionRecord::RecvWithAddress:
case TransactionRecord::RecvFromOther: case TransactionRecord::RecvFromOther:
case TransactionRecord::PlatformTransfer:
return GUIUtil::getThemedQColor(GUIUtil::ThemedColor::GREEN); return GUIUtil::getThemedQColor(GUIUtil::ThemedColor::GREEN);
case TransactionRecord::CoinJoinSend: case TransactionRecord::CoinJoinSend:
case TransactionRecord::SendToAddress: case TransactionRecord::SendToAddress:

View File

@ -90,6 +90,7 @@ TransactionView::TransactionView(QWidget* parent) :
typeWidget->addItem(tr("%1 Collateral Payment").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinCollateralPayment)); typeWidget->addItem(tr("%1 Collateral Payment").arg(strCoinJoinName), TransactionFilterProxy::TYPE(TransactionRecord::CoinJoinCollateralPayment));
typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf)); typeWidget->addItem(tr("To yourself"), TransactionFilterProxy::TYPE(TransactionRecord::SendToSelf));
typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated)); typeWidget->addItem(tr("Mined"), TransactionFilterProxy::TYPE(TransactionRecord::Generated));
typeWidget->addItem(tr("Platform Transfer"), TransactionFilterProxy::TYPE(TransactionRecord::PlatformTransfer));
typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other)); typeWidget->addItem(tr("Other"), TransactionFilterProxy::TYPE(TransactionRecord::Other));
typeWidget->setCurrentIndex(settings.value("transactionType").toInt()); typeWidget->setCurrentIndex(settings.value("transactionType").toInt());

View File

@ -81,6 +81,7 @@ WalletTx MakeWalletTx(CWallet& wallet, const CWalletTx& wtx)
result.time = wtx.GetTxTime(); result.time = wtx.GetTxTime();
result.value_map = wtx.mapValue; result.value_map = wtx.mapValue;
result.is_coinbase = wtx.IsCoinBase(); result.is_coinbase = wtx.IsCoinBase();
result.is_platform_transfer = wtx.IsPlatformTransfer();
// The determination of is_denominate is based on simplified checks here because in this part of the code // The determination of is_denominate is based on simplified checks here because in this part of the code
// we only want to know about mixing transactions belonging to this specific wallet. // we only want to know about mixing transactions belonging to this specific wallet.
result.is_denominate = wtx.tx->vin.size() == wtx.tx->vout.size() && // Number of inputs is same as number of outputs result.is_denominate = wtx.tx->vin.size() == wtx.tx->vout.size() && // Number of inputs is same as number of outputs

View File

@ -167,6 +167,8 @@ static void WalletTxToJSON(interfaces::Chain& chain, const CWalletTx& wtx, UniVa
entry.pushKV("chainlock", chainlock); entry.pushKV("chainlock", chainlock);
if (wtx.IsCoinBase()) if (wtx.IsCoinBase())
entry.pushKV("generated", true); entry.pushKV("generated", true);
if (wtx.IsPlatformTransfer())
entry.pushKV("platform-transfer", true);
if (confirms > 0) if (confirms > 0)
{ {
entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex()); entry.pushKV("blockhash", wtx.m_confirm.hashBlock.GetHex());
@ -1403,6 +1405,10 @@ static void ListTransactions(const CWallet& wallet, const CWalletTx& wtx, int nM
else else
entry.pushKV("category", "generate"); entry.pushKV("category", "generate");
} }
else if (wtx.IsPlatformTransfer())
{
entry.pushKV("category", "platform-transfer");
}
else else
{ {
entry.pushKV("category", "receive"); entry.pushKV("category", "receive");
@ -1467,7 +1473,8 @@ static RPCHelpMan listtransactions()
"\"receive\" Non-coinbase transactions received.\n" "\"receive\" Non-coinbase transactions received.\n"
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n" "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
"\"orphan\" Orphaned coinbase transactions received.\n"}, "\"orphan\" Orphaned coinbase transactions received.\n"
"\"platform-transfer\" Platform Transfer transactions received.\n"},
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n" {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
"for all other categories"}, "for all other categories"},
{RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"}, {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"},
@ -1582,7 +1589,8 @@ static RPCHelpMan listsinceblock()
"\"receive\" Non-coinbase transactions received.\n" "\"receive\" Non-coinbase transactions received.\n"
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n" "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
"\"orphan\" Orphaned coinbase transactions received.\n"}, "\"orphan\" Orphaned coinbase transactions received.\n"
"\"platform-transfer\" Platform Transfer transactions received.\n"},
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n" {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT + ". This is negative for the 'send' category, and is positive\n"
"for all other categories"}, "for all other categories"},
{RPCResult::Type::NUM, "vout", "the vout value"}, {RPCResult::Type::NUM, "vout", "the vout value"},
@ -1723,7 +1731,8 @@ static RPCHelpMan gettransaction()
"\"receive\" Non-coinbase transactions received.\n" "\"receive\" Non-coinbase transactions received.\n"
"\"generate\" Coinbase transactions received with more than 100 confirmations.\n" "\"generate\" Coinbase transactions received with more than 100 confirmations.\n"
"\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n" "\"immature\" Coinbase transactions received with 100 or fewer confirmations.\n"
"\"orphan\" Orphaned coinbase transactions received.\n"}, "\"orphan\" Orphaned coinbase transactions received.\n"
"\"platform-transfer\" Platform Transfer transactions received.\n"},
{RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT}, {RPCResult::Type::STR_AMOUNT, "amount", "The amount in " + CURRENCY_UNIT},
{RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"}, {RPCResult::Type::STR, "label", "A comment for the address/transaction, if any"},
{RPCResult::Type::NUM, "vout", "the vout value"}, {RPCResult::Type::NUM, "vout", "the vout value"},

View File

@ -592,6 +592,7 @@ public:
void setConfirmed() { m_confirm.status = CWalletTx::CONFIRMED; } void setConfirmed() { m_confirm.status = CWalletTx::CONFIRMED; }
const uint256& GetHash() const { return tx->GetHash(); } const uint256& GetHash() const { return tx->GetHash(); }
bool IsCoinBase() const { return tx->IsCoinBase(); } bool IsCoinBase() const { return tx->IsCoinBase(); }
bool IsPlatformTransfer() const { return tx->IsPlatformTransfer(); }
bool IsImmatureCoinBase() const; bool IsImmatureCoinBase() const;
// Disable copying of CWalletTx objects to prevent bugs where instances get // Disable copying of CWalletTx objects to prevent bugs where instances get