Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/privatesend/privatesend-util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,6 @@ bool CTransactionBuilder::IsDust(CAmount nAmount) const

bool CTransactionBuilder::Commit(std::string& strResult)
{
CWalletTx wtx;
CAmount nFeeRet = 0;
int nChangePosRet = -1;

Expand All @@ -265,15 +264,16 @@ bool CTransactionBuilder::Commit(std::string& strResult)
}
}

if (!pwallet->CreateTransaction(vecSend, wtx, dummyReserveKey, nFeeRet, nChangePosRet, strResult, coinControl)) {
CTransactionRef tx;
if (!pwallet->CreateTransaction(vecSend, tx, dummyReserveKey, nFeeRet, nChangePosRet, strResult, coinControl)) {
return false;
}

CAmount nAmountLeft = GetAmountLeft();
bool fDust = IsDust(nAmountLeft);
// If there is a either remainder which is considered to be dust (will be added to fee in this case) or no amount left there should be no change output, return if there is a change output.
if (nChangePosRet != -1 && fDust) {
strResult = strprintf("Unexpected change output %s at position %d", wtx.tx->vout[nChangePosRet].ToString(), nChangePosRet);
strResult = strprintf("Unexpected change output %s at position %d", tx->vout[nChangePosRet].ToString(), nChangePosRet);
return false;
}

Expand Down Expand Up @@ -301,14 +301,14 @@ bool CTransactionBuilder::Commit(std::string& strResult)
}

CValidationState state;
if (!pwallet->CommitTransaction(wtx, dummyReserveKey, g_connman.get(), state)) {
if (!pwallet->CommitTransaction(tx, {}, {}, {}, dummyReserveKey, g_connman.get(), state)) {
strResult = state.GetRejectReason();
return false;
}

fKeepKeys = true;

strResult = wtx.GetHash().ToString();
strResult = tx->GetHash().ToString();

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/qt/sendcoinsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients)
if (ctrl.IsUsingPrivateSend()) {
// append number of inputs
questionString.append("<hr />");
int nInputs = currentTransaction.getTransaction()->tx->vin.size();
int nInputs = currentTransaction.getTransaction()->vin.size();
questionString.append(tr("This transaction will consume %n input(s)", "", nInputs));

// warn about potential privacy issues when spending too many inputs at once
Expand Down Expand Up @@ -461,7 +461,7 @@ void SendCoinsDialog::send(QList<SendCoinsRecipient> recipients)
}

// now send the prepared transaction
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction);
WalletModel::SendCoinsReturn sendStatus = model->sendCoins(currentTransaction, ctrl.IsUsingPrivateSend());
// process sendStatus and on error generate message shown to user
processSendCoinsReturn(sendStatus);

Expand Down
34 changes: 17 additions & 17 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,16 +344,15 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact

int nChangePosRet = -1;

CWalletTx* newTx = transaction.getTransaction();
CTransactionRef& newTx = transaction.getTransaction();
CReserveKey *keyChange = transaction.getPossibleKeyChange();

fCreated = wallet->CreateTransaction(vecSend, *newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
fCreated = wallet->CreateTransaction(vecSend, newTx, *keyChange, nFeeRequired, nChangePosRet, strFailReason, coinControl);
transaction.setTransactionFee(nFeeRequired);
if (fSubtractFeeFromAmount && fCreated)
transaction.reassignAmounts();

nValueOut = newTx->tx->GetValueOut();
nVinSize = newTx->tx->vin.size();
nValueOut = newTx->GetValueOut();
nVinSize = newTx->vin.size();
}

if(!fCreated)
Expand All @@ -376,18 +375,16 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact
return SendCoinsReturn(OK);
}

WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &transaction)
WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &transaction, bool fIsPrivateSend)
{
QByteArray transaction_array; /* store serialized transaction */

{
LOCK2(cs_main, mempool.cs);
LOCK(wallet->cs_wallet);

CWalletTx *newTx = transaction.getTransaction();
QList<SendCoinsRecipient> recipients = transaction.getRecipients();

for (const SendCoinsRecipient &rcp : recipients)
std::vector<std::pair<std::string, std::string>> vOrderForm;
for (const SendCoinsRecipient &rcp : transaction.getRecipients())
{
if (rcp.paymentRequest.IsInitialized())
{
Expand All @@ -397,24 +394,27 @@ WalletModel::SendCoinsReturn WalletModel::sendCoins(WalletModelTransaction &tran
}

// Store PaymentRequests in wtx.vOrderForm in wallet.
std::string key("PaymentRequest");
std::string value;
rcp.paymentRequest.SerializeToString(&value);
newTx->vOrderForm.push_back(make_pair(key, value));
vOrderForm.emplace_back("PaymentRequest", std::move(value));
}
else if (!rcp.message.isEmpty()) // Message from normal dash:URI (dash:XyZ...?message=example)
{
newTx->vOrderForm.push_back(make_pair("Message", rcp.message.toStdString()));
}
vOrderForm.emplace_back("Message", rcp.message.toStdString());
}

mapValue_t mapValue;
if (fIsPrivateSend) {
mapValue["DS"] = "1";
}

CTransactionRef& newTx = transaction.getTransaction();
CReserveKey *keyChange = transaction.getPossibleKeyChange();
CValidationState state;
if(!wallet->CommitTransaction(*newTx, *keyChange, g_connman.get(), state))
if (!wallet->CommitTransaction(newTx, std::move(mapValue), std::move(vOrderForm), {} /* fromAccount */, *keyChange, g_connman.get(), state))
return SendCoinsReturn(TransactionCommitFailed, QString::fromStdString(state.GetRejectReason()));

CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
ssTx << *newTx->tx;
ssTx << newTx;
transaction_array.append(ssTx.data(), ssTx.size());
}

Expand Down
2 changes: 1 addition & 1 deletion src/qt/walletmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class WalletModel : public QObject
SendCoinsReturn prepareTransaction(WalletModelTransaction &transaction, const CCoinControl& coinControl);

// Send coins to a list of recipients
SendCoinsReturn sendCoins(WalletModelTransaction &transaction);
SendCoinsReturn sendCoins(WalletModelTransaction &transaction, bool fIsPrivateSend);

// Wallet encryption
bool setWalletEncrypted(bool encrypted, const SecureString &passphrase);
Expand Down
14 changes: 4 additions & 10 deletions src/qt/walletmodeltransaction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,21 @@ WalletModelTransaction::WalletModelTransaction(const QList<SendCoinsRecipient> &
walletTransaction(0),
fee(0)
{
walletTransaction = new CWalletTx();
}

WalletModelTransaction::~WalletModelTransaction()
{
delete walletTransaction;
}

QList<SendCoinsRecipient> WalletModelTransaction::getRecipients() const
{
return recipients;
}

CWalletTx *WalletModelTransaction::getTransaction() const
CTransactionRef& WalletModelTransaction::getTransaction()
{
return walletTransaction;
}

unsigned int WalletModelTransaction::getTransactionSize()
{
return (!walletTransaction ? 0 : (::GetSerializeSize(*walletTransaction->tx, SER_NETWORK, PROTOCOL_VERSION)));
return (!walletTransaction ? 0 : (::GetSerializeSize(*walletTransaction, SER_NETWORK, PROTOCOL_VERSION)));
}

CAmount WalletModelTransaction::getTransactionFee() const
Expand Down Expand Up @@ -61,7 +55,7 @@ void WalletModelTransaction::reassignAmounts()
if (out.amount() <= 0) continue;
const unsigned char* scriptStr = (const unsigned char*)out.script().data();
CScript scriptPubKey(scriptStr, scriptStr+out.script().size());
for (const auto& txout : walletTransaction->tx->vout) {
for (const auto& txout : walletTransaction->vout) {
if (txout.scriptPubKey == scriptPubKey) {
subtotal += txout.nValue;
break;
Expand All @@ -72,7 +66,7 @@ void WalletModelTransaction::reassignAmounts()
}
else // normal recipient (no payment request)
{
for (const auto& txout : walletTransaction->tx->vout) {
for (const auto& txout : walletTransaction->vout) {
CScript scriptPubKey = GetScriptForDestination(DecodeDestination(rcp.address.toStdString()));
if (txout.scriptPubKey == scriptPubKey) {
rcp.amount = txout.nValue;
Expand Down
5 changes: 2 additions & 3 deletions src/qt/walletmodeltransaction.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@ class WalletModelTransaction
{
public:
explicit WalletModelTransaction(const QList<SendCoinsRecipient> &recipients);
~WalletModelTransaction();

QList<SendCoinsRecipient> getRecipients() const;

CWalletTx *getTransaction() const;
CTransactionRef& getTransaction();
unsigned int getTransactionSize();

void setTransactionFee(const CAmount& newFee);
Expand All @@ -41,7 +40,7 @@ class WalletModelTransaction

private:
QList<SendCoinsRecipient> recipients;
CWalletTx *walletTransaction;
CTransactionRef walletTransaction;
std::unique_ptr<CReserveKey> keyChange;
CAmount fee;
};
Expand Down
10 changes: 5 additions & 5 deletions src/rpc/governance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ UniValue gobject_prepare(const JSONRPCRequest& request)
outpoint = COutPoint(collateralHash, (uint32_t)collateralIndex);
}

CWalletTx wtx;
if (!pwallet->GetBudgetSystemCollateralTX(wtx, govobj.GetHash(), govobj.GetMinCollateralFee(), outpoint)) {
CTransactionRef tx;
if (!pwallet->GetBudgetSystemCollateralTX(tx, govobj.GetHash(), govobj.GetMinCollateralFee(), outpoint)) {
std::string err = "Error making collateral transaction for governance object. Please check your wallet balance and make sure your wallet is unlocked.";
if (!request.params[6].isNull() && !request.params[7].isNull()) {
err += "Please verify your specified output is valid and is enough for the combined proposal fee and transaction fee.";
Expand All @@ -219,14 +219,14 @@ UniValue gobject_prepare(const JSONRPCRequest& request)
CReserveKey reservekey(pwallet);
// -- send the tx to the network
CValidationState state;
if (!pwallet->CommitTransaction(wtx, reservekey, g_connman.get(), state)) {
if (!pwallet->CommitTransaction(tx, {}, {}, {}, reservekey, g_connman.get(), state)) {
throw JSONRPCError(RPC_INTERNAL_ERROR, "CommitTransaction failed! Reason given: " + state.GetRejectReason());
}

LogPrint(BCLog::GOBJECT, "gobject_prepare -- GetDataAsPlainString = %s, hash = %s, txid = %s\n",
govobj.GetDataAsPlainString(), govobj.GetHash().ToString(), wtx.GetHash().ToString());
govobj.GetDataAsPlainString(), govobj.GetHash().ToString(), tx->GetHash().ToString());

return wtx.GetHash().ToString();
return tx->GetHash().ToString();
}
#endif // ENABLE_WALLET

Expand Down
8 changes: 4 additions & 4 deletions src/rpc/rpcevo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,18 +229,18 @@ static void FundSpecialTx(CWallet* pwallet, CMutableTransaction& tx, const Speci
throw JSONRPCError(RPC_INTERNAL_ERROR, strprintf("No funds at specified address %s", EncodeDestination(fundDest)));
}

CWalletTx wtx;
CTransactionRef newTx;
CReserveKey reservekey(pwallet);
CAmount nFee;
int nChangePos = -1;
std::string strFailReason;

if (!pwallet->CreateTransaction(vecSend, wtx, reservekey, nFee, nChangePos, strFailReason, coinControl, false, tx.vExtraPayload.size())) {
if (!pwallet->CreateTransaction(vecSend, newTx, reservekey, nFee, nChangePos, strFailReason, coinControl, false, tx.vExtraPayload.size())) {
throw JSONRPCError(RPC_INTERNAL_ERROR, strFailReason);
}

tx.vin = wtx.tx->vin;
tx.vout = wtx.tx->vout;
tx.vin = newTx->vin;
tx.vout = newTx->vout;

if (dummyTxOutAdded && tx.vout.size() > 1) {
// CreateTransaction added a change output, so we don't need the dummy txout anymore.
Expand Down
Loading