Skip to content

feat: get best block height from features API #541

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
May 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/controllers/wallet/wallet.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* LICENSE file in the root directory of this source tree.
*/

const { txApi, walletApi, WalletType, constants: hathorLibConstants, helpersUtils, errors, tokensUtils, transactionUtils, PartialTx } = require('@hathor/wallet-lib');
const { txApi, featuresApi, walletApi, WalletType, constants: hathorLibConstants, helpersUtils, errors, tokensUtils, transactionUtils, PartialTx } = require('@hathor/wallet-lib');

Check warning on line 8 in src/controllers/wallet/wallet.controller.js

View workflow job for this annotation

GitHub Actions / test (22.x)

'walletApi' is assigned a value but never used
const { matchedData } = require('express-validator');
// import is used because there is an issue with winston logger when using require ref: #262
const { JSONBigInt } = require('@hathor/wallet-lib/lib/utils/bigint');
Expand Down Expand Up @@ -226,7 +226,6 @@
// Disabling this eslint rule because of the way API call is done in the lib
// otherwise the code would need to be more complex
// We should change this when we refactor the way we call APIs in the lib
// (this comment also applies for the getMiningInfo call)
// eslint-disable-next-line no-promise-executor-return
const txDataResponse = await new Promise(resolve => txApi.getTransaction(id, resolve));

Expand All @@ -236,10 +235,11 @@
}

// Now we get the current height of the network
// eslint-disable-next-line no-promise-executor-return
const networkHeightResponse = await new Promise(resolve => walletApi.getMiningInfo(resolve));

if (!networkHeightResponse.success) {
let bestChainHeight;
try {
const featuresResponse = await featuresApi.getFeatures();
bestChainHeight = featuresResponse.block_height;
} catch (err) {
res.send({ success: false, error: 'Failed to get network heigth from the full node.' });
return;
}
Expand All @@ -248,7 +248,7 @@

// first_block_height will be null until a block confirms this transaction
if (txDataResponse.meta && txDataResponse.meta.first_block_height) {
confirmationNumber = networkHeightResponse.blocks - txDataResponse.meta.first_block_height;
confirmationNumber = bestChainHeight - txDataResponse.meta.first_block_height;
}

res.send({ success: true, confirmationNumber });
Expand Down
Loading