diff options
author | Andrew Chow <achow101-github@achow101.com> | 2019-07-31 18:02:24 -0400 |
---|---|---|
committer | fanquake <fanquake@gmail.com> | 2019-09-24 07:53:29 +0800 |
commit | eb07d22b2d3ec70203412a7746b0ec73217cc974 (patch) | |
tree | ba26e3261fbc8689038ab1f8d214eaed529e3943 /src | |
parent | 1175410be5959f783f0a5276451b775dc340e420 (diff) | |
download | bitcoin-eb07d22b2d3ec70203412a7746b0ec73217cc974.tar.xz |
Shuffle inputs and outputs after joining psbts
Github-Pull: #16512
Rebased-From: 6f405a1d3b38395e35571b68aae55cae50e0762a
Diffstat (limited to 'src')
-rw-r--r-- | src/rpc/rawtransaction.cpp | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/src/rpc/rawtransaction.cpp b/src/rpc/rawtransaction.cpp index b0af7e09d4..c4b7bec052 100644 --- a/src/rpc/rawtransaction.cpp +++ b/src/rpc/rawtransaction.cpp @@ -19,6 +19,7 @@ #include <policy/rbf.h> #include <primitives/transaction.h> #include <psbt.h> +#include <random.h> #include <rpc/rawtransaction.h> #include <rpc/server.h> #include <rpc/util.h> @@ -1861,8 +1862,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()); } |