@@ -80,7 +80,7 @@ export class BitcoinService {
80
80
logger . error ( { error } , "Failed to generate key" ) ;
81
81
throw new BitcoinError (
82
82
"Failed to generate key pair" ,
83
- BitcoinErrorCode . KEY_GENERATION_ERROR ,
83
+ BitcoinErrorCode . KEY_GENERATION_ERROR
84
84
) ;
85
85
}
86
86
}
@@ -140,7 +140,7 @@ export class BitcoinService {
140
140
logger . error ( { error, rawHex } , "Failed to decode transaction" ) ;
141
141
throw new BitcoinError (
142
142
"Failed to decode transaction" ,
143
- BitcoinErrorCode . DECODE_ERROR ,
143
+ BitcoinErrorCode . DECODE_ERROR
144
144
) ;
145
145
}
146
146
}
@@ -155,11 +155,18 @@ export class BitcoinService {
155
155
*/
156
156
async getLatestBlock ( ) : Promise < BlockInfo > {
157
157
try {
158
- const response = await fetch ( `${ this . apiBase } /blocks/tip` ) ;
159
- if ( ! response . ok ) {
160
- throw new Error ( `HTTP error! status: ${ response . status } ` ) ;
158
+ const hashRes = await fetch ( `${ this . apiBase } /blocks/tip/hash ` ) ;
159
+ if ( ! hashRes . ok ) {
160
+ throw new Error ( "Failed to fetch latest block hash" ) ;
161
161
}
162
- const block = ( await response . json ( ) ) as any ;
162
+ const hash = await hashRes . text ( ) ;
163
+
164
+ const blockRes = await fetch ( `${ this . apiBase } /block/${ hash } ` ) ;
165
+ if ( ! blockRes . ok ) {
166
+ throw new Error ( "Failed to fetch block data" ) ;
167
+ }
168
+ const block = ( await blockRes . json ( ) ) as BlockstreamBlock ;
169
+
163
170
return {
164
171
hash : block . id ,
165
172
height : block . height ,
@@ -169,10 +176,10 @@ export class BitcoinService {
169
176
weight : block . weight ,
170
177
} ;
171
178
} catch ( error ) {
172
- logger . error ( { error } , "Failed to get latest block" ) ;
179
+ logger . error ( { error } , "Failed to fetch latest block" ) ;
173
180
throw new BitcoinError (
174
- "Failed to get latest block" ,
175
- BitcoinErrorCode . BLOCKCHAIN_ERROR ,
181
+ "Failed to fetch latest block" ,
182
+ BitcoinErrorCode . BLOCKCHAIN_ERROR
176
183
) ;
177
184
}
178
185
}
@@ -227,7 +234,7 @@ export class BitcoinService {
227
234
logger . error ( { error, txid } , "Failed to get transaction" ) ;
228
235
throw new BitcoinError (
229
236
"Failed to get transaction" ,
230
- BitcoinErrorCode . BLOCKCHAIN_ERROR ,
237
+ BitcoinErrorCode . BLOCKCHAIN_ERROR
231
238
) ;
232
239
}
233
240
}
0 commit comments