Skip to content

Commit

Permalink
Merge pull request #25 from coinarchive/master
Browse files Browse the repository at this point in the history
fix for segfault on sendto / sendmany
  • Loading branch information
butkcore-dev authored Jan 21, 2023
2 parents 5c21736 + 5c11db9 commit 3949594
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/qt/walletmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact

CAmount nFeeRequired = 0;
CAmount nValueOut = 0;
CAmount nChangeValue = 0;
size_t nVinSize = 0;
bool fCreated;
int nChangePosRet = -1;
Expand All @@ -340,16 +341,13 @@ WalletModel::SendCoinsReturn WalletModel::prepareTransaction(WalletModelTransact

nValueOut = newTx->tx->GetValueOut();
nVinSize = newTx->tx->vin.size();
if (nChangePosRet >= 0)
nChangeValue = newTx->tx->vout[nChangePosRet].nValue;
}

CTransactionRef tx;
if(fCreated){
CWalletTx* newTx = transaction.getTransaction();
if(!Params().IsMaxCash(chainActive.Tip())){
CAmount subtotal = total;
if (nChangePosRet >= 0)
// subtotal += newTx->tx->GetValueOut();
subtotal += tx.get()->vout.at(nChangePosRet).nValue;
CAmount subtotal = total + nChangeValue;
if(!fSubtractFeeFromAmount)
subtotal += nFeeRequired;
if (subtotal > OLD_MAX_MONEY){
Expand Down
16 changes: 11 additions & 5 deletions src/wallet/rpcwallet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,10 @@ static void SendMoney(CWallet * const pwallet, const CTxDestination &address, CA
throw JSONRPCError(RPC_WALLET_ERROR, strError);
}

CTransactionRef tx;
if(!Params().IsMaxCash(chainActive.Tip())){
CAmount subtotal = nValue;
if (nChangePosRet >= 0)
subtotal += tx.get()->vout.at(nChangePosRet).nValue;
subtotal += wtxNew.tx->vout[nChangePosRet].nValue;
if(!fSubtractFeeFromAmount)
subtotal += nFeeRequired;
if (subtotal > OLD_MAX_MONEY){
Expand Down Expand Up @@ -1079,6 +1078,7 @@ UniValue sendmany(const JSONRPCRequest& request)
std::vector<CRecipient> vecSend;

CAmount totalAmount = 0;
bool fSubtractFeeFromAmountAll = false;
std::vector<std::string> keys = sendTo.getKeys();
for (const std::string& name_ : keys)
{
Expand All @@ -1102,6 +1102,7 @@ UniValue sendmany(const JSONRPCRequest& request)
if (addr.get_str() == name_)
fSubtractFeeFromAmount = true;
}
if (fSubtractFeeFromAmount) fSubtractFeeFromAmountAll = true;

CRecipient recipient = {scriptPubKey, nAmount, fSubtractFeeFromAmount};
vecSend.push_back(recipient);
Expand All @@ -1123,10 +1124,15 @@ UniValue sendmany(const JSONRPCRequest& request)
bool fCreated = pwallet->CreateTransaction(vecSend, wtx, keyChange, nFeeRequired, nChangePosRet, strFailReason,
coin_control);

CTransactionRef tx;
if(!Params().IsMaxCash(chainActive.Tip()) && fCreated){
if (tx.get()->GetValueOut() > OLD_MAX_MONEY)
if(!Params().IsMaxCash(chainActive.Tip()) && fCreated){
CAmount subtotal = totalAmount;
if (nChangePosRet >= 0)
subtotal += wtx.tx->vout[nChangePosRet].nValue;
if(!fSubtractFeeFromAmountAll)
subtotal += nFeeRequired;
if (subtotal > OLD_MAX_MONEY){
throw JSONRPCError(RPC_WALLET_ERROR, "Error: This transaction exceeds the limit of 21 million.");
}
}

if (!fCreated)
Expand Down

0 comments on commit 3949594

Please sign in to comment.