Skip to content

Commit a9d190b

Browse files
committed
[BDAP] Fixes to create bdap transaction wallet method
1 parent 327e950 commit a9d190b

File tree

1 file changed

+12
-7
lines changed

1 file changed

+12
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3690,6 +3690,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
36903690

36913691
CAmount nFeePay = fUseInstantSend ? CTxLockRequest().GetMinFee(true) : 0;
36923692
std::string strOpType;
3693+
CScript prevScriptPubKey;
36933694

36943695
CAmount nValue = 0;
36953696
int nChangePosRequest = nChangePosInOut;
@@ -3768,6 +3769,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
37683769
return false;
37693770
}
37703771
if (strOpType == "bdap_new_account") {
3772+
// Use BDAP credits first.
37713773
AvailableCoins(vAvailableCoins, true, coinControl, false, nCoinType, fUseInstantSend);
37723774
}
37733775
else if (strOpType == "bdap_update_account" || strOpType == "bdap_delete_account") {
@@ -3792,7 +3794,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
37923794
strFailReason = _("GetDomainEntryInfo failed to find previous domanin entry transaction.");
37933795
return false;
37943796
}
3795-
CScript prevScriptPubKey;
3797+
37963798
GetBDAPOpScript(prevTx, prevScriptPubKey);
37973799
GetBDAPCoins(vAvailableCoins, prevScriptPubKey);
37983800
}
@@ -3967,11 +3969,13 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
39673969
CScript scriptChange;
39683970

39693971
// coin control: send change to custom address
3970-
if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange))
3972+
if (coinControl && !boost::get<CNoDestination>(&coinControl->destChange)) {
39713973
scriptChange = GetScriptForDestination(coinControl->destChange);
3972-
3973-
// no coin control: send change to newly generated address
3974-
else {
3974+
} else if (strOpType == "bdap_update_account" || strOpType == "bdap_delete_account") {
3975+
// send deposit change back to original account.
3976+
scriptChange = prevScriptPubKey;
3977+
} else {
3978+
// no coin control: send change to newly generated address
39753979
// Note: We use a new key here to keep it from being obvious which side is the change.
39763980
// The drawback is that by not reusing a previous key, the change may be lost if a
39773981
// backup is restored, if the backup doesn't have the new private key for the change.
@@ -4118,7 +4122,8 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
41184122
// if (dPriorityNeeded > 0 && dPriority >= dPriorityNeeded)
41194123
// break;
41204124
}
4121-
CAmount nFeeNeeded = std::max(nFeePay, GetMinimumFee(nBytes, currentConfirmationTarget, mempool));
4125+
// Standard fee not needed for BDAP
4126+
CAmount nFeeNeeded = !fIsBDAP ? std::max(nFeePay, GetMinimumFee(nBytes, currentConfirmationTarget, mempool)) : 0;
41224127
if (coinControl && nFeeNeeded > 0 && coinControl->nMinimumTotalFee > nFeeNeeded) {
41234128
nFeeNeeded = coinControl->nMinimumTotalFee;
41244129
}
@@ -4132,7 +4137,7 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
41324137

41334138
// If we made it here and we aren't even able to meet the relay fee on the next pass, give up
41344139
// because we must be at the maximum allowed fee.
4135-
if (nFeeNeeded < ::minRelayTxFee.GetFee(nBytes)) {
4140+
if (!fIsBDAP && nFeeNeeded < ::minRelayTxFee.GetFee(nBytes)) {
41364141
strFailReason = _("Transaction too large for fee policy");
41374142
return false;
41384143
}

0 commit comments

Comments
 (0)