From 73711eb0bb4fa2af28554ef566910ee5e29945ca Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Wed, 16 Oct 2019 13:56:30 -0400 Subject: [PATCH] Merge psbt peg-in data --- src/psbt.cpp | 5 +++++ test/functional/feature_fedpeg.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/src/psbt.cpp b/src/psbt.cpp index 1021a18a46..dd00abc43c 100644 --- a/src/psbt.cpp +++ b/src/psbt.cpp @@ -159,6 +159,11 @@ void PSBTInput::Merge(const PSBTInput& input) if (value_blinding_factor.IsNull() && !input.value_blinding_factor.IsNull()) value_blinding_factor = input.value_blinding_factor; if (asset.IsNull() && !input.asset.IsNull()) asset = input.asset; if (asset_blinding_factor.IsNull() && !input.asset_blinding_factor.IsNull()) asset_blinding_factor = input.asset_blinding_factor; + + if (peg_in_tx.which() == 0 && peg_in_tx.which() > 0) peg_in_tx = input.peg_in_tx; + if (txout_proof.which() == 0 && peg_in_tx.which() > 0) txout_proof = input.txout_proof; + if (claim_script.empty() && !input.claim_script.empty()) claim_script = input.claim_script; + if (genesis_hash.IsNull() && !input.genesis_hash.IsNull()) genesis_hash = input.genesis_hash; } bool PSBTInput::IsSane() const diff --git a/test/functional/feature_fedpeg.py b/test/functional/feature_fedpeg.py index af6ee2d8d5..9e44e9e083 100755 --- a/test/functional/feature_fedpeg.py +++ b/test/functional/feature_fedpeg.py @@ -302,6 +302,15 @@ class FedPegTest(BitcoinTestFramework): assert_equal(decoded_psbt['inputs'][0]['pegin_claim_script'], addrs["claim_script"]) assert_equal(decoded_psbt['inputs'][0]['pegin_txout_proof'], proof) assert_equal(decoded_psbt['inputs'][0]['pegin_genesis_hash'], parent.getblockhash(0)) + # Make a psbt without those peg-in data and merge them + merge_pegin_psbt = sidechain.createpsbt([{"txid":txid1, "vout": vout}], outputs) + decoded_psbt = sidechain.decodepsbt(merge_pegin_psbt) + assert 'pegin_bitcoin_tx' not in decoded_psbt['inputs'][0] + assert 'pegin_claim_script' not in decoded_psbt['inputs'][0] + assert 'pegin_txout_proof' not in decoded_psbt['inputs'][0] + assert 'pegin_genesis_hash' not in decoded_psbt['inputs'][0] + merged_pegin_psbt = sidechain.combinepsbt([pegin_psbt, merge_pegin_psbt]) + assert_equal(pegin_psbt, merged_pegin_psbt) sample_pegin_struct = FromHex(CTransaction(), signed_pegin["hex"]) # Round-trip peg-in transaction using python serialization