5
5
* LICENSE file in the root directory of this source tree.
6
6
*/
7
7
8
- const { txApi, walletApi , WalletType, constants : hathorLibConstants , helpersUtils, errors, tokensUtils, transactionUtils, PartialTx } = require ( '@hathor/wallet-lib' ) ;
8
+ const { txApi, featuresApi , WalletType, constants : hathorLibConstants , helpersUtils, errors, tokensUtils, transactionUtils, PartialTx } = require ( '@hathor/wallet-lib' ) ;
9
9
const { matchedData } = require ( 'express-validator' ) ;
10
10
// import is used because there is an issue with winston logger when using require ref: #262
11
11
const { JSONBigInt } = require ( '@hathor/wallet-lib/lib/utils/bigint' ) ;
@@ -226,7 +226,6 @@ async function getTxConfirmationBlocks(req, res) {
226
226
// Disabling this eslint rule because of the way API call is done in the lib
227
227
// otherwise the code would need to be more complex
228
228
// We should change this when we refactor the way we call APIs in the lib
229
- // (this comment also applies for the getMiningInfo call)
230
229
// eslint-disable-next-line no-promise-executor-return
231
230
const txDataResponse = await new Promise ( resolve => txApi . getTransaction ( id , resolve ) ) ;
232
231
@@ -236,10 +235,11 @@ async function getTxConfirmationBlocks(req, res) {
236
235
}
237
236
238
237
// Now we get the current height of the network
239
- // eslint-disable-next-line no-promise-executor-return
240
- const networkHeightResponse = await new Promise ( resolve => walletApi . getMiningInfo ( resolve ) ) ;
241
-
242
- if ( ! networkHeightResponse . success ) {
238
+ let bestChainHeight ;
239
+ try {
240
+ const featuresResponse = await featuresApi . getFeatures ( ) ;
241
+ bestChainHeight = featuresResponse . block_height ;
242
+ } catch ( err ) {
243
243
res . send ( { success : false , error : 'Failed to get network heigth from the full node.' } ) ;
244
244
return ;
245
245
}
@@ -248,7 +248,7 @@ async function getTxConfirmationBlocks(req, res) {
248
248
249
249
// first_block_height will be null until a block confirms this transaction
250
250
if ( txDataResponse . meta && txDataResponse . meta . first_block_height ) {
251
- confirmationNumber = networkHeightResponse . blocks - txDataResponse . meta . first_block_height ;
251
+ confirmationNumber = bestChainHeight - txDataResponse . meta . first_block_height ;
252
252
}
253
253
254
254
res . send ( { success : true , confirmationNumber } ) ;
0 commit comments