@@ -1304,11 +1304,20 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1304
1304
sp_dests[i] = *sp;
1305
1305
}
1306
1306
}
1307
+ if (const auto * change_sp = std::get_if<V0SilentPaymentDestination>(&change_dest)) {
1308
+ // Generate output for change too
1309
+ sp_dests[mutableVecSend.size ()] = *change_sp;
1310
+ }
1307
1311
const auto & silent_payment_tr_spks = CreateSilentPaymentOutputs (wallet, sp_dests, result.GetInputSet (), error);
1308
1312
if (!silent_payment_tr_spks.has_value ()) {
1309
1313
return util::Error{error};
1310
1314
}
1311
1315
for (const auto & [out_idx, tr_dest] : *silent_payment_tr_spks) {
1316
+ if (out_idx == mutableVecSend.size ()) {
1317
+ change_dest = tr_dest;
1318
+ continue ;
1319
+ }
1320
+
1312
1321
assert (out_idx < mutableVecSend.size ());
1313
1322
mutableVecSend[out_idx].dest = tr_dest;
1314
1323
}
@@ -1324,16 +1333,6 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1324
1333
if (!IsValidDestination (change_dest)) {
1325
1334
return util::Error{error};
1326
1335
}
1327
- if (const auto * sp = std::get_if<V0SilentPaymentDestination>(&change_dest)) {
1328
- // Since we will be getting the final destination
1329
- // for only the change output, the index doesn't matter.
1330
- std::map<size_t , V0SilentPaymentDestination> change_sp_dest;
1331
- change_sp_dest[0 ] = *sp;
1332
- auto taproot_change = CreateSilentPaymentOutputs (wallet, change_sp_dest, result.GetInputSet (), error);
1333
- if (taproot_change.has_value ()) {
1334
- change_dest = taproot_change->at (0 );
1335
- }
1336
- }
1337
1336
1338
1337
CScript change_script = GetScriptForDestination (change_dest);
1339
1338
Assert (!change_script.empty ());
@@ -1537,7 +1536,8 @@ static util::Result<CreatedTransactionResult> CreateTransactionInternal(
1537
1536
if (wallet.IsMine (*tx, spent_coins))
1538
1537
wallet.WalletLogPrintf (" Detected Silent Payments self-transfer: %s" , tx->GetHash ().ToString ());
1539
1538
}
1540
- return CreatedTransactionResult (tx, current_fee, change_pos, feeCalc);
1539
+ LogPrintf (" change_type: %s" , FormatOutputType (change_type));
1540
+ return CreatedTransactionResult (tx, current_fee, change_pos, change_type, feeCalc);
1541
1541
}
1542
1542
1543
1543
util::Result<CreatedTransactionResult> CreateTransaction (
@@ -1572,7 +1572,9 @@ util::Result<CreatedTransactionResult> CreateTransaction(
1572
1572
tmp_cc.m_avoid_partial_spends = true ;
1573
1573
1574
1574
// Reuse the change destination from the first creation attempt to avoid skipping BIP44 indexes
1575
- if (txr_ungrouped.change_pos ) {
1575
+ // Do not reuse the change dest if it came from a silent payments destination
1576
+ // silent payments change dest must be generated with the other silent payment outputs
1577
+ if (txr_ungrouped.change_pos && txr_ungrouped.change_type != OutputType::SILENT_PAYMENTS) {
1576
1578
ExtractDestination (txr_ungrouped.tx ->vout [*txr_ungrouped.change_pos ].scriptPubKey , tmp_cc.destChange );
1577
1579
}
1578
1580
0 commit comments