Skip to content

Commit 5f92143

Browse files
committed
[BDAP] Fix SendBDAPTransaction function for update account txs
1 parent b131512 commit 5f92143

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/bdap/rpcdomainentry.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
#include <univalue.h>
2020

21-
extern void SendBDAPTransaction(const CScript& bdapDataScript, const CScript& bdapOPScript, CWalletTx& wtxNew, const CAmount& nRegFee, const CAmount& nDepositFee, const bool fUseInstantSend);
21+
extern void SendBDAPTransaction(const CScript& bdapDataScript, const CScript& bdapOPScript, CWalletTx& wtxNew, const CAmount& nDataAmount, const CAmount& nOpAmount, const bool fUseInstantSend);
2222
extern void SendColorTransaction(const CScript& scriptColorCoins, CWalletTx& wtxNew, const CAmount& nColorAmount, const CCoinControl* coinControl, const bool fUseInstantSend, const bool fUsePrivateSend);
2323

2424
static constexpr bool fPrintDebug = true;
@@ -113,7 +113,7 @@ static UniValue AddDomainEntry(const JSONRPCRequest& request, BDAP::ObjectType b
113113

114114
// Send the transaction
115115
CWalletTx wtx;
116-
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee + oneTimeFee, depositFee, fUseInstantSend);
116+
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee, oneTimeFee + depositFee, fUseInstantSend);
117117
txDomainEntry.txHash = wtx.GetHash();
118118

119119
UniValue oName(UniValue::VOBJ);
@@ -484,7 +484,7 @@ static UniValue UpdateDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp
484484

485485
// Send the transaction
486486
CWalletTx wtx;
487-
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee + oneTimeFee, depositFee, fUseInstantSend);
487+
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee, oneTimeFee + depositFee, fUseInstantSend);
488488
txUpdatedEntry.txHash = wtx.GetHash();
489489

490490
UniValue oName(UniValue::VOBJ);
@@ -652,7 +652,7 @@ static UniValue DeleteDomainEntry(const JSONRPCRequest& request, BDAP::ObjectTyp
652652
// Send the transaction
653653
CWalletTx wtx;
654654
bool fUseInstantSend = false;
655-
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee + oneTimeFee, depositFee, fUseInstantSend);
655+
SendBDAPTransaction(scriptData, scriptPubKey, wtx, monthlyFee, oneTimeFee + depositFee, fUseInstantSend);
656656
txDeletedEntry.txHash = wtx.GetHash();
657657

658658
UniValue oName(UniValue::VOBJ);

src/wallet/rpcwallet.cpp

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -457,15 +457,20 @@ static void SendMoney(const CTxDestination& address, CAmount nValue, bool fSubtr
457457
}
458458
}
459459

460-
void SendBDAPTransaction(const CScript& bdapDataScript, const CScript& bdapOPScript, CWalletTx& wtxNew, const CAmount& nRegFee, const CAmount& nDepositFee, const bool fUseInstantSend)
460+
/*
461+
For BDAP transactions,
462+
- nDataAmount is burned in the OP_RUTRN transaction.
463+
- nOpAmount turns to BDAP credits and can only be used to fund BDAP fees
464+
*/
465+
void SendBDAPTransaction(const CScript& bdapDataScript, const CScript& bdapOPScript, CWalletTx& wtxNew, const CAmount& nDataAmount, const CAmount& nOpAmount, const bool fUseInstantSend)
461466
{
462467
CAmount curBalance = pwalletMain->GetBalance();
463468

464-
// Check amount
465-
if (nRegFee <= 0)
466-
throw JSONRPCError(RPC_INVALID_PARAMETER, "SendBDAPTransaction invalid amount");
469+
// Check amounts
470+
if (nDataAmount <= 0 || nOpAmount <= 0)
471+
throw JSONRPCError(RPC_INVALID_PARAMETER, "SendBDAPTransaction invalid amount. Data and operation amounts must be greater than zero.");
467472

468-
if (nRegFee + nDepositFee > curBalance)
473+
if (nDataAmount + nOpAmount > curBalance)
469474
throw JSONRPCError(RPC_WALLET_INSUFFICIENT_FUNDS, "SendBDAPTransaction insufficient funds");
470475

471476
// Create and send the transaction
@@ -475,14 +480,14 @@ void SendBDAPTransaction(const CScript& bdapDataScript, const CScript& bdapOPScr
475480
std::vector<CRecipient> vecSend;
476481
int nChangePosInOut = 0;
477482

478-
LogPrintf("Sending BDAP Data Script: %s\n", ScriptToAsmStr(bdapDataScript));
479-
LogPrintf("Sending BDAP OP Script: %s\n", ScriptToAsmStr(bdapOPScript));
483+
LogPrint("bdap", "Sending BDAP Data Script: %s\n", ScriptToAsmStr(bdapDataScript));
484+
LogPrint("bdap", "Sending BDAP OP Script: %s\n", ScriptToAsmStr(bdapOPScript));
480485

481-
if (nRegFee > 0) {
482-
CRecipient recDataScript = {bdapDataScript, nRegFee, false};
486+
if (nDataAmount > 0) {
487+
CRecipient recDataScript = {bdapDataScript, nDataAmount, false};
483488
vecSend.push_back(recDataScript);
484489
}
485-
CRecipient recOPScript = {bdapOPScript, nDepositFee, false};
490+
CRecipient recOPScript = {bdapOPScript, nOpAmount, false};
486491
vecSend.push_back(recOPScript);
487492

488493
if (!pwalletMain->CreateTransaction(vecSend, wtxNew, reservekey, nFeeRequired, nChangePosInOut,

0 commit comments

Comments
 (0)