-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ4.py
More file actions
93 lines (80 loc) · 2.92 KB
/
Q4.py
File metadata and controls
93 lines (80 loc) · 2.92 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
from bitcoin.core.script import *
from bitcoin.core import Hash160
######################################################################
# These functions will be used by Alice and Bob to send their respective
# coins to a utxo that is redeemable either of two cases:
# 1) Recipient provides x such that hash(x) = hash of secret
# and recipient signs the transaction.
# 2) Sender and recipient both sign transaction
#
# TODO: Fill these in to create scripts that are redeemable by both
# of the above conditions.
# See this page for opcode documentation: https://en.bitcoin.it/wiki/Script
# This is the ScriptPubKey for the swap transaction
def coinExchangeScript(public_key_sender, public_key_recipient, hash_of_secret):
return [
OP_IF,
# Recipient can redeem with secret
OP_SHA256,
hash_of_secret,
OP_EQUALVERIFY,
OP_DUP,
OP_HASH160,
Hash160(public_key_recipient),
OP_ELSE,
# Both parties can redeem after timelock
OP_2,
public_key_sender,
public_key_recipient,
OP_2,
OP_CHECKMULTISIG,
OP_VERIFY,
OP_DUP,
OP_HASH160,
Hash160(public_key_sender),
OP_ENDIF,
OP_EQUALVERIFY,
OP_CHECKSIG,
]
# This is the ScriptSig that the receiver will use to redeem coins
def coinExchangeScriptSig1(sig_recipient, secret):
return [
sig_recipient,
secret,
OP_TRUE,
]
# This is the ScriptSig for sending coins back to the sender if unredeemed
def coinExchangeScriptSig2(sig_sender, sig_recipient):
return [
sig_sender,
sig_recipient,
OP_FALSE,
]
######################################################################
######################################################################
#
# Configured for your addresses
#
# TODO: Fill in all of these fields
#
alice_txid_to_spend = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
alice_utxo_index = None
alice_amount_to_send = None
bob_txid_to_spend = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"
bob_utxo_index = None
bob_amount_to_send = None
# Get current block height (for locktime) in 'height' parameter for each blockchain (will be used in swap.py):
# curl https://api.blockcypher.com/v1/btc/test3
btc_test3_chain_height = 1579945
# curl https://api.blockcypher.com/v1/bcy/test
bcy_test_chain_height = 2548698
# Parameter for how long Alice/Bob should have to wait before they can take back their coins
# alice_locktime MUST be > bob_locktime
alice_locktime = 5
bob_locktime = 3
tx_fee = 0.0001
# While testing your code, you can edit these variables to see if your
# transaction can be broadcasted succesfully.
broadcast_transactions = False
alice_redeems = False
######################################################################