@@ -21,6 +21,16 @@ def pack_block_index(index):
2121 else :
2222 raise ValueError ("Unknown index type" )
2323
24+ def binary_str_to_bytes (str ):
25+ split = lambda str : [str [x :x + 8 ] for x in range (0 , len (str ), 8 )]
26+ add_padding = lambda str : str + ((8 - len (str )) * "0" )
27+ result = []
28+ for bin_byte in split (str ):
29+ bin_byte = add_padding (bin_byte )
30+ value = int (bin_byte , 2 )
31+ assert value < 256
32+ result .append (value )
33+ return tuple (result )
2434
2535class ObeliskOfLightClient (ClientBase ):
2636 valid_messages = [
@@ -135,9 +145,9 @@ def fetch_transaction_index(self, tx_hash, cb):
135145 'blockchain.fetch_transaction_index' , data , cb
136146 )
137147
138- def fetch_block_transaction_hashes (self , index , cb ):
148+ def fetch_block_transaction_hashes (self , tx_hash , cb ):
139149 """Fetches list of transaction hashes in a block by block hash."""
140- data = pack_block_index ( index )
150+ data = serialize . ser_hash ( tx_hash )
141151 self .send_command (
142152 'blockchain.fetch_block_transaction_hashes' , data , cb
143153 )
@@ -159,9 +169,12 @@ def fetch_stealth(self, prefix, cb, from_height=0):
159169 height, and may also include results from earlier blocks.
160170 It is provided as an optimisation. All results at and after
161171 from_height are guaranteed to be returned however."""
162- number_bits , bitfield = prefix
163- data = struct .pack ('<BII' , number_bits , bitfield , from_height )
164- assert len (data ) == 9
172+ values = binary_str_to_bytes (prefix )
173+ number_bits = len (prefix )
174+ data = struct .pack ('<B' , number_bits )
175+ for value in values :
176+ data += struct .pack ('<B' , value )
177+ data += struct .pack ('<I' , from_height )
165178 self .send_command ('blockchain.fetch_stealth' , data , cb )
166179
167180 # receive handlers
@@ -174,18 +187,15 @@ def _on_fetch_block_header(self, data):
174187 def _on_fetch_history (self , data ):
175188 error = unpack_error (data )
176189 # parse results
177- rows = self .unpack_table ("<32sIIQ32sII " , data , 4 )
190+ rows = self .unpack_table ("<B32sIIQ " , data , 4 )
178191 history = []
179- for row in rows :
180- o_hash , o_index , o_height , value , s_hash , s_index , s_height = row
181- o_hash = o_hash [::- 1 ]
182- s_hash = s_hash [::- 1 ]
183- if s_index == 4294967295 :
184- s_hash = None
185- s_index = None
186- s_height = None
187- history .append (
188- (o_hash , o_index , o_height , value , s_hash , s_index , s_height ))
192+ for id , hash , index , height , value in rows :
193+ if id == 0 :
194+ id = False
195+ else :
196+ id = True
197+ hash = hash [::- 1 ]
198+ history .append ((id , hash , index , height , value ))
189199 return (error , history )
190200
191201 def _on_fetch_last_height (self , data ):
@@ -221,11 +231,11 @@ def _on_fetch_block_height(self, data):
221231
222232 def _on_fetch_stealth (self , data ):
223233 error = unpack_error (data )
224- raw_rows = self .unpack_table ("<33sB20s32s " , data , 4 )
234+ raw_rows = self .unpack_table ("<32s20s32s " , data , 4 )
225235 rows = []
226- for ephemkey , address_version , address_hash , tx_hash in raw_rows :
227- address = bitcoin . hash_160_to_bc_address (
228- address_hash [::- 1 ], address_version )
236+ for ephemkey , address , tx_hash in raw_rows :
237+ ephemkey = ephemkey [:: - 1 ]
238+ address = address [::- 1 ]
229239 tx_hash = tx_hash [::- 1 ]
230240 rows .append ((ephemkey , address , tx_hash ))
231241 return (error , rows )
0 commit comments