|
17 | 17 | #include <policy/rbf.h>
|
18 | 18 | #include <primitives/transaction.h>
|
19 | 19 | #include <psbt.h>
|
| 20 | +#include <random.h> |
20 | 21 | #include <rpc/rawtransaction_util.h>
|
21 | 22 | #include <rpc/server.h>
|
22 | 23 | #include <rpc/util.h>
|
@@ -1604,8 +1605,30 @@ UniValue joinpsbts(const JSONRPCRequest& request)
|
1604 | 1605 | merged_psbt.unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
|
1605 | 1606 | }
|
1606 | 1607 |
|
| 1608 | + // Generate list of shuffled indices for shuffling inputs and outputs of the merged PSBT |
| 1609 | + std::vector<int> input_indices(merged_psbt.inputs.size()); |
| 1610 | + std::iota(input_indices.begin(), input_indices.end(), 0); |
| 1611 | + std::vector<int> output_indices(merged_psbt.outputs.size()); |
| 1612 | + std::iota(output_indices.begin(), output_indices.end(), 0); |
| 1613 | + |
| 1614 | + // Shuffle input and output indicies lists |
| 1615 | + Shuffle(input_indices.begin(), input_indices.end(), FastRandomContext()); |
| 1616 | + Shuffle(output_indices.begin(), output_indices.end(), FastRandomContext()); |
| 1617 | + |
| 1618 | + PartiallySignedTransaction shuffled_psbt; |
| 1619 | + shuffled_psbt.tx = CMutableTransaction(); |
| 1620 | + shuffled_psbt.tx->nVersion = merged_psbt.tx->nVersion; |
| 1621 | + shuffled_psbt.tx->nLockTime = merged_psbt.tx->nLockTime; |
| 1622 | + for (int i : input_indices) { |
| 1623 | + shuffled_psbt.AddInput(merged_psbt.tx->vin[i], merged_psbt.inputs[i]); |
| 1624 | + } |
| 1625 | + for (int i : output_indices) { |
| 1626 | + shuffled_psbt.AddOutput(merged_psbt.tx->vout[i], merged_psbt.outputs[i]); |
| 1627 | + } |
| 1628 | + shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end()); |
| 1629 | + |
1607 | 1630 | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
1608 |
| - ssTx << merged_psbt; |
| 1631 | + ssTx << shuffled_psbt; |
1609 | 1632 | return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
|
1610 | 1633 | }
|
1611 | 1634 |
|
|
0 commit comments