mirror of
https://github.com/ElementsProject/elements.git
synced 2026-08-20 13:37:28 +02:00
Merge 72d30d668a into merged_master (Bitcoin PR #16512)
This commit is contained in:
commit
df8fcece9d
3 changed files with 38 additions and 1 deletions
|
|
@ -20,6 +20,7 @@
|
|||
#include <policy/rbf.h>
|
||||
#include <primitives/transaction.h>
|
||||
#include <psbt.h>
|
||||
#include <random.h>
|
||||
#include <rpc/rawtransaction_util.h>
|
||||
#include <rpc/server.h>
|
||||
#include <rpc/util.h>
|
||||
|
|
@ -1864,8 +1865,30 @@ UniValue joinpsbts(const JSONRPCRequest& request)
|
|||
merged_psbt.unknown.insert(psbt.unknown.begin(), psbt.unknown.end());
|
||||
}
|
||||
|
||||
// Generate list of shuffled indices for shuffling inputs and outputs of the merged PSBT
|
||||
std::vector<int> input_indices(merged_psbt.inputs.size());
|
||||
std::iota(input_indices.begin(), input_indices.end(), 0);
|
||||
std::vector<int> output_indices(merged_psbt.outputs.size());
|
||||
std::iota(output_indices.begin(), output_indices.end(), 0);
|
||||
|
||||
// Shuffle input and output indicies lists
|
||||
Shuffle(input_indices.begin(), input_indices.end(), FastRandomContext());
|
||||
Shuffle(output_indices.begin(), output_indices.end(), FastRandomContext());
|
||||
|
||||
PartiallySignedTransaction shuffled_psbt;
|
||||
shuffled_psbt.tx = CMutableTransaction();
|
||||
shuffled_psbt.tx->nVersion = merged_psbt.tx->nVersion;
|
||||
shuffled_psbt.tx->nLockTime = merged_psbt.tx->nLockTime;
|
||||
for (int i : input_indices) {
|
||||
shuffled_psbt.AddInput(merged_psbt.tx->vin[i], merged_psbt.inputs[i]);
|
||||
}
|
||||
for (int i : output_indices) {
|
||||
shuffled_psbt.AddOutput(merged_psbt.tx->vout[i], merged_psbt.outputs[i]);
|
||||
}
|
||||
shuffled_psbt.unknown.insert(merged_psbt.unknown.begin(), merged_psbt.unknown.end());
|
||||
|
||||
CDataStream ssTx(SER_NETWORK, PROTOCOL_VERSION);
|
||||
ssTx << merged_psbt;
|
||||
ssTx << shuffled_psbt;
|
||||
return EncodeBase64((unsigned char*)ssTx.data(), ssTx.size());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue