@@ -34,18 +34,46 @@ def add_options(self, parser):
3434 parser .add_option ("--parent_binpath" , dest = "parent_binpath" , default = "" ,
3535 help = "Use a different binary for launching nodes" )
3636 parser .add_option ("--parent_type" , dest = "parent_type" , default = "elements" ,
37- help = "Type of parent nodes {elements, bitcoin}" )
37+ help = "Type of parent nodes {elements, bitcoin, signet }" )
3838
3939 def setup_network (self , split = False ):
4040 self .nodes = []
4141 self .extra_args = []
4242
43- if self .options .parent_type not in ['elements' , 'bitcoin' ]:
44- raise Exception ("Invalid option --parent_type=%s, valid options: elements, bitcoin" % self .options .parent_type )
43+ if self .options .parent_type not in ['elements' , 'bitcoin' , 'signet' ]:
44+ raise Exception ("Invalid option --parent_type=%s, valid values: { elements, bitcoin, signet} " % self .options .parent_type )
4545
4646 if self .options .parent_type == 'bitcoin' and self .options .parent_binpath == "" :
4747 raise Exception ("Can't run with --parent_type=bitcoin without specifying --parent_binpath" )
4848
49+ self .binary = self .options .parent_binpath if self .options .parent_binpath != "" else None
50+
51+ if self .options .parent_type == 'signet' :
52+ from binascii import hexlify
53+ from test_framework import script , key
54+ from test_framework .util import hex_str_to_bytes
55+ import shutil
56+ temp_args = [
57+ "-port=" + str (p2p_port (0 )),
58+ "-rpcport=" + str (rpc_port (0 )),
59+ "-addresstype=legacy" ,
60+ "-deprecatedrpc=validateaddress"
61+ ]
62+ temp_node = start_node (0 , self .options .tmpdir , temp_args , binary = self .binary , chain = 'signet' , cookie_auth = True )
63+ addr = temp_node .getnewaddress ()
64+ k = key .CECKey ()
65+ pub = temp_node .validateaddress (addr )["pubkey" ]
66+ k .set_pubkey (hex_str_to_bytes (pub ))
67+ pubkey = key .CPubKey (k .get_pubkey ())
68+ wif = temp_node .dumpprivkey (addr )
69+ stop_node (temp_node , 0 )
70+ shutil .rmtree (os .path .join (self .options .tmpdir , 'node0' , 'signet' ))
71+ script = script .CScript ([pubkey , script .OP_CHECKSIG ])
72+ blockscript = hexlify (script ).decode ('ascii' )
73+
74+ print ('blockscript' , blockscript )
75+ print ('wif' , wif )
76+
4977 # Parent chain args
5078 for n in range (2 ):
5179 # We want to test the rpc cookie method so we force the use of a
@@ -62,7 +90,21 @@ def setup_network(self, split=False):
6290 "-port=" + str (p2p_port (n )),
6391 "-rpcport=" + str (rpc_port (n ))
6492 ])
65- else :
93+ elif self .options .parent_type == 'signet' :
94+ self .parent_chain = 'signet'
95+ rpc_u , rpc_p = rpc_auth_pair (n )
96+ self .extra_args .append ([
97+ "-printtoconsole=0" ,
98+ "-signet_blockscript=%s" % blockscript ,
99+ "-signet_siglen=77" ,
100+ "-signet_seednode=178.128.221.177" ,
101+ "-port=" + str (p2p_port (n )),
102+ "-rpcport=" + str (rpc_port (n )),
103+ "-addresstype=legacy" , # To make sure bitcoind gives back p2pkh no matter version
104+ "-deprecatedrpc=validateaddress" ,
105+ "-fallbackfee=0.00001" ,
106+ ])
107+ elif self .options .parent_type == 'elements' :
66108 self .parent_chain = 'parent'
67109 self .extra_args .append ([
68110 "-conf=dummy" ,
@@ -77,8 +119,9 @@ def setup_network(self, split=False):
77119 if not use_cookie_auth :
78120 self .extra_args [n ].extend (["-rpcuser=" + rpc_u , "-rpcpassword=" + rpc_p ])
79121
80- self .binary = self .options .parent_binpath if self .options .parent_binpath != "" else None
81122 self .nodes .append (start_node (n , self .options .tmpdir , self .extra_args [n ], binary = self .binary , chain = self .parent_chain , cookie_auth = use_cookie_auth ))
123+ if self .options .parent_type == 'signet' :
124+ self .nodes [n ].importprivkey (wif )
82125
83126 connect_nodes_bi (self .nodes , 0 , 1 )
84127 self .parentgenesisblockhash = self .nodes [0 ].getblockhash (0 )
@@ -111,6 +154,14 @@ def setup_network(self, split=False):
111154 '-con_parent_chain_signblockscript=%s' % parent_chain_signblockscript ,
112155 '-con_parent_pegged_asset=%s' % parent_pegged_asset ,
113156 ])
157+ elif self .options .parent_type == 'signet' :
158+ args .extend ([
159+ '-con_parent_is_signet=1' ,
160+ '-con_parent_signet_siglen=77' ,
161+ '-parentpubkeyprefix=125' ,
162+ '-parentscriptprefix=87' ,
163+ '-con_parent_chain_signblockscript=%s' % blockscript ,
164+ ])
114165
115166 if used_cookie_auth :
116167 # Need to specify where to find parent cookie file
0 commit comments