-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ3b.py
More file actions
61 lines (50 loc) · 2.68 KB
/
Q3b.py
File metadata and controls
61 lines (50 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from sys import exit
from bitcoin.core.script import *
from lib.utils import *
from lib.config import (my_private_key, my_public_key, my_address,
faucet_address, network_type)
from Q1 import P2PKH_scriptPubKey
from Q3a import (Q3a_txout_scriptPubKey, cust1_private_key, cust2_private_key,
cust3_private_key)
def multisig_scriptSig(txin, txout, txin_scriptPubKey):
bank_sig = create_OP_CHECKSIG_signature(txin, txout, txin_scriptPubKey,
my_private_key)
cust1_sig = create_OP_CHECKSIG_signature(txin, txout, txin_scriptPubKey,
cust1_private_key)
cust2_sig = create_OP_CHECKSIG_signature(txin, txout, txin_scriptPubKey,
cust2_private_key)
cust3_sig = create_OP_CHECKSIG_signature(txin, txout, txin_scriptPubKey,
cust3_private_key)
######################################################################
# TODO: Complete this script to unlock the BTC that was locked in the
# multisig transaction created in Exercise 3a.
# For 2-of-3 multisig, we need OP_0 (due to CHECKMULTISIG bug) and 2 signatures
return [
OP_0,
cust1_sig,
cust2_sig,
]
######################################################################
def send_from_multisig_transaction(amount_to_send, txid_to_spend, utxo_index,
txin_scriptPubKey, txout_scriptPubKey, network):
txout = create_txout(amount_to_send, txout_scriptPubKey)
txin = create_txin(txid_to_spend, utxo_index)
txin_scriptSig = multisig_scriptSig(txin, txout, txin_scriptPubKey)
new_tx = create_signed_transaction(txin, txout, txin_scriptPubKey,
txin_scriptSig)
return broadcast_transaction(new_tx, network)
if __name__ == '__main__':
######################################################################
# TODO: set these parameters correctly
amount_to_send = None # amount of BTC in the output you're sending minus fee
txid_to_spend = (
'XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX')
utxo_index = None # index of the output you are spending, indices start at 0
######################################################################
txin_scriptPubKey = Q3a_txout_scriptPubKey
txout_scriptPubKey = P2PKH_scriptPubKey(faucet_address)
response = send_from_multisig_transaction(
amount_to_send, txid_to_spend, utxo_index,
txin_scriptPubKey, txout_scriptPubKey, network_type)
print(response.status_code, response.reason)
print(response.text)