added SendChangeToBack feature
SendChangeToBack feature sends the change back to the address of the sender's coin. To enable SendChangeToBack feature, add SendChangeToBack=1 in flo.conf To enable FIFO CoinControl feature, add CoinControlFIFO=1 in flo.conf
This commit is contained in:
parent
0e8fdac19e
commit
af07c526d3
@ -2744,10 +2744,11 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
|
||||
// TODO: pass in scriptChange instead of reservekey so
|
||||
// change transaction isn't always pay-to-bitcoin-address
|
||||
CScript scriptChange;
|
||||
|
||||
bool coinControlDestChange=false;
|
||||
// coin control: send change to custom address
|
||||
if (!boost::get<CNoDestination>(&coin_control.destChange)) {
|
||||
scriptChange = GetScriptForDestination(coin_control.destChange);
|
||||
coinControlDestChange=true;
|
||||
} else { // no coin control: send change to newly generated address
|
||||
// Note: We use a new key here to keep it from being obvious which side is the change.
|
||||
// The drawback is that by not reusing a previous key, the change may be lost if a
|
||||
@ -2818,7 +2819,6 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
|
||||
}
|
||||
txNew.vout.push_back(txout);
|
||||
}
|
||||
|
||||
// Choose coins to use
|
||||
if (pick_new_inputs) {
|
||||
nValueIn = 0;
|
||||
@ -2829,6 +2829,23 @@ bool CWallet::CreateTransaction(const std::vector<CRecipient>& vecSend, CWalletT
|
||||
return false;
|
||||
}
|
||||
}
|
||||
// Send Change Back to Same (sending) Address
|
||||
if(!coinControlDestChange && gArgs.GetBoolArg("-SendChangeToBack", false)){
|
||||
CTxDestination destChange;
|
||||
CAmount maxVal=0;
|
||||
bool avail = false;
|
||||
for (const CInputCoin &coin : setCoins ){
|
||||
if(!avail || coin.txout.nValue > maxVal){
|
||||
avail = (ExtractDestination(coin.txout.scriptPubKey, destChange) || avail);
|
||||
maxVal = coin.txout.nValue;
|
||||
}
|
||||
}
|
||||
if(avail){
|
||||
scriptChange = GetScriptForDestination(destChange);
|
||||
CTxOut change_prototype_txout(0, scriptChange);
|
||||
size_t change_prototype_size = GetSerializeSize(change_prototype_txout, SER_DISK, 0);
|
||||
}
|
||||
}
|
||||
|
||||
const CAmount nChange = nValueIn - nValueToSelect;
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user