Skip to content

Commit 7c99226

Browse files
combine_psbt.py
1 parent 9f48e21 commit 7c99226

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

examples/combine_psbt.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
3+
"""
4+
Combine multiple PSBTs (Partially Signed Bitcoin Transactions) into a single PSBT with merged signatures and metadata.
5+
6+
This script performs the combiner role defined in BIP-174, allowing multiple signers to contribute signatures separately,
7+
and then merge their PSBTs into one unified transaction.
8+
9+
Features:
10+
- Loads multiple base64-encoded PSBTs
11+
- Merges all inputs, outputs, and partial signatures
12+
- Validates consistency across PSBTs before combining
13+
- Outputs a single combined PSBT in base64 format
14+
15+
Usage:
16+
python combine_psbt.py <psbt1_base64> <psbt2_base64> [<psbt3_base64> ...]
17+
18+
Returns:
19+
Combined PSBT with merged data from all inputs
20+
"""
21+
22+
import sys
23+
from bitcoinutils.setup import setup
24+
from bitcoinutils.psbt import PSBT
25+
26+
def main():
27+
setup('testnet')
28+
29+
if len(sys.argv) < 3:
30+
print("Usage: python combine_psbt.py <psbt1_base64> <psbt2_base64> [psbt3_base64] ...")
31+
return
32+
33+
# Load PSBTs from command line arguments
34+
psbts = [PSBT.from_base64(psbt_base64) for psbt_base64 in sys.argv[1:]]
35+
36+
# Combine all PSBTs using the first one as base
37+
combined_psbt = psbts[0].combine_psbts(psbts[1:])
38+
39+
# Output the combined PSBT
40+
print(combined_psbt.to_base64())
41+
42+
if __name__ == "__main__":
43+
main()

0 commit comments

Comments
 (0)