55 * LICENSE file in the root directory of this source tree.
66 */
77
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' ) ;
99const { matchedData } = require ( 'express-validator' ) ;
1010// import is used because there is an issue with winston logger when using require ref: #262
1111const { JSONBigInt } = require ( '@hathor/wallet-lib/lib/utils/bigint' ) ;
@@ -226,7 +226,6 @@ async function getTxConfirmationBlocks(req, res) {
226226 // Disabling this eslint rule because of the way API call is done in the lib
227227 // otherwise the code would need to be more complex
228228 // We should change this when we refactor the way we call APIs in the lib
229- // (this comment also applies for the getMiningInfo call)
230229 // eslint-disable-next-line no-promise-executor-return
231230 const txDataResponse = await new Promise ( resolve => txApi . getTransaction ( id , resolve ) ) ;
232231
@@ -236,10 +235,11 @@ async function getTxConfirmationBlocks(req, res) {
236235 }
237236
238237 // 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 ) {
243243 res . send ( { success : false , error : 'Failed to get network heigth from the full node.' } ) ;
244244 return ;
245245 }
@@ -248,7 +248,7 @@ async function getTxConfirmationBlocks(req, res) {
248248
249249 // first_block_height will be null until a block confirms this transaction
250250 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 ;
252252 }
253253
254254 res . send ( { success : true , confirmationNumber } ) ;
0 commit comments