Skip to content

Commit 73711eb

Browse files
committed
Merge psbt peg-in data
1 parent 4ad849f commit 73711eb

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

src/psbt.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ void PSBTInput::Merge(const PSBTInput& input)
159159
if (value_blinding_factor.IsNull() && !input.value_blinding_factor.IsNull()) value_blinding_factor = input.value_blinding_factor;
160160
if (asset.IsNull() && !input.asset.IsNull()) asset = input.asset;
161161
if (asset_blinding_factor.IsNull() && !input.asset_blinding_factor.IsNull()) asset_blinding_factor = input.asset_blinding_factor;
162+
163+
if (peg_in_tx.which() == 0 && peg_in_tx.which() > 0) peg_in_tx = input.peg_in_tx;
164+
if (txout_proof.which() == 0 && peg_in_tx.which() > 0) txout_proof = input.txout_proof;
165+
if (claim_script.empty() && !input.claim_script.empty()) claim_script = input.claim_script;
166+
if (genesis_hash.IsNull() && !input.genesis_hash.IsNull()) genesis_hash = input.genesis_hash;
162167
}
163168

164169
bool PSBTInput::IsSane() const

test/functional/feature_fedpeg.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,15 @@ def run_test(self):
302302
assert_equal(decoded_psbt['inputs'][0]['pegin_claim_script'], addrs["claim_script"])
303303
assert_equal(decoded_psbt['inputs'][0]['pegin_txout_proof'], proof)
304304
assert_equal(decoded_psbt['inputs'][0]['pegin_genesis_hash'], parent.getblockhash(0))
305+
# Make a psbt without those peg-in data and merge them
306+
merge_pegin_psbt = sidechain.createpsbt([{"txid":txid1, "vout": vout}], outputs)
307+
decoded_psbt = sidechain.decodepsbt(merge_pegin_psbt)
308+
assert 'pegin_bitcoin_tx' not in decoded_psbt['inputs'][0]
309+
assert 'pegin_claim_script' not in decoded_psbt['inputs'][0]
310+
assert 'pegin_txout_proof' not in decoded_psbt['inputs'][0]
311+
assert 'pegin_genesis_hash' not in decoded_psbt['inputs'][0]
312+
merged_pegin_psbt = sidechain.combinepsbt([pegin_psbt, merge_pegin_psbt])
313+
assert_equal(pegin_psbt, merged_pegin_psbt)
305314

306315
sample_pegin_struct = FromHex(CTransaction(), signed_pegin["hex"])
307316
# Round-trip peg-in transaction using python serialization

0 commit comments

Comments
 (0)