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
Show file tree
Hide file tree
Changes from all commits
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
5 changes: 5 additions & 0 deletions __tests__/__fixtures__/http-fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,11 @@ export default {
success: true,
blocks: 1242,
},
'/feature': {
block_hash: '00000008707722cde59ac9e7f4d44efbd3a5bd5f244223816ee676d328943b1b',
block_height: 1242,
features: [],
},
'/nano_contract/state': {
success: true,
nc_id: '3cb032600bdf7db784800e4ea911b10676fa2f67591f82bb62628c234e771595',
Expand Down
1 change: 1 addition & 0 deletions __tests__/test-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ class TestUtils {
return [200, httpFixtures['/transaction']];
});
httpMock.onGet('/getmininginfo').reply(200, httpFixtures['/getmininginfo']);
httpMock.onGet('/feature').reply(200, httpFixtures['/feature']);
httpMock.onGet('http://fake.txmining:8084/health').reply(200, httpFixtures['http://fake.txmining:8084/health']);
httpMock.onGet('/nano_contract/state').reply(200, httpFixtures['/nano_contract/state']);
httpMock.onGet('/nano_contract/history').reply(200, httpFixtures['/nano_contract/history']);
Expand Down
153 changes: 10 additions & 143 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"dependencies": {
"@dinamonetworks/hsm-dinamo": "4.9.1",
"@hathor/healthcheck-lib": "0.1.0",
"@hathor/wallet-lib": "2.1.1",
"@hathor/wallet-lib": "2.3.0",
"axios": "1.7.7",
"express": "4.18.2",
"express-validator": "6.10.0",
Expand Down
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, WalletType, constants: hathorLibConstants, helpersUtils, errors, tokensUtils, transactionUtils, PartialTx } = require('@hathor/wallet-lib');
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 @@ async function getTxConfirmationBlocks(req, res) {
// 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 @@ async function getTxConfirmationBlocks(req, res) {
}

// 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 @@ async function getTxConfirmationBlocks(req, res) {

// 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