|
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>
|
@@ -1615,8 +1616,30 @@ UniValue joinpsbts(const JSONRPCRequest& request)
|
1615 | 1616 | merged_psbt.unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
|
1616 | 1617 | }
|
1617 | 1618 |
|
| 1619 | + // Generate list of shuffled indices for shuffling inputs and outputs of the merged PSBT |
| 1620 | + std::vector<int> input_indices(merged_psbt.inputs.size()); |
| 1621 | + std::iota(input_indices.begin(), input_indices.end(), 0); |
| 1622 | + std::vector<int> output_indices(merged_psbt.outputs.size()); |
| 1623 | + std::iota(output_indices.begin(), output_indices.end(), 0); |
| 1624 | + |
| 1625 | + // Shuffle input and output indicies lists |
| 1626 | + Shuffle(input_indices.begin(), input_indices.end(), FastRandomContext()); |
| 1627 | + Shuffle(output_indices.begin(), output_indices.end(), FastRandomContext()); |
| 1628 | + |
| 1629 | + PartiallySignedTransaction shuffled_psbt; |
| 1630 | + shuffled_psbt.tx = CMutableTransaction(); |
| 1631 | + shuffled_psbt.tx->nVersion = merged_psbt.tx->nVersion; |
| 1632 | + shuffled_psbt.tx->nLockTime = merged_psbt.tx->nLockTime; |
| 1633 | + for (int i : input_indices) { |
| 1634 | + shuffled_psbt.AddInput(merged_psbt.tx->vin[i], merged_psbt.inputs[i]); |
| 1635 | + } |
| 1636 | + for (int i : output_indices) { |
| 1637 | + shuffled_psbt.AddOutput(merged_psbt.tx->vout[i], merged_psbt.outputs[i]); |
| 1638 | + } |
| 1639 | + shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end()); |
| 1640 | + |
1618 | 1641 | CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
1619 |
| - ssTx << merged_psbt; |
| 1642 | + ssTx << shuffled_psbt; |
1620 | 1643 | return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
|
1621 | 1644 | }
|
1622 | 1645 |
|
|
0 commit comments