Skip to content

Commit acd031f

Browse files
committed
feat(API): add chia version to /diagnostics response
Query the wallet RPC get_version endpoint and surface the installed Chia version in chia.version (null when the wallet is unreachable).
1 parent 56e22b3 commit acd031f

4 files changed

Lines changed: 41 additions & 0 deletions

File tree

src/datalayer/wallet.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,28 @@ const getActiveNetwork = async () => {
329329
}
330330
};
331331

332+
const getChiaVersion = async () => {
333+
const url = `${rpcUrl}/get_version`;
334+
const { cert, key, timeout } = getBaseOptions();
335+
336+
try {
337+
const response = await superagent
338+
.post(url)
339+
.key(key)
340+
.cert(cert)
341+
.timeout(timeout)
342+
.send(JSON.stringify({}));
343+
344+
const data = response.body;
345+
if (data.success) {
346+
return data.version || null;
347+
}
348+
return null;
349+
} catch {
350+
return null;
351+
}
352+
};
353+
332354
/**
333355
* Return the wallet's peer connections (used by /diagnostics to cross-reference
334356
* connected full-node peers against the trusted_peers map in the chia config).
@@ -927,6 +949,7 @@ export default {
927949
waitForAllTransactionsToConfirm,
928950
waitForSpendableCoins,
929951
getActiveNetwork,
952+
getChiaVersion,
930953
getWalletConnections,
931954
getLastWalletSyncError,
932955
getWalletBlockchainSyncStatus,

src/routes/diagnostics.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ export const getDiagnosticsResponse = async ({ readOnly = false } = {}) => {
273273
// ECONNREFUSED, wasting wall-clock for no diagnostic value.
274274
const rpcSettles = [
275275
settle('wallet.getActiveNetwork', () => wallet.getActiveNetwork(), DEFAULT_TIMEOUT_MS),
276+
settle('wallet.getChiaVersion', () => wallet.getChiaVersion(), DEFAULT_TIMEOUT_MS),
276277
settle('wallet.walletIsSynced', () => wallet.walletIsSynced(), DEFAULT_TIMEOUT_MS),
277278
settle('wallet.getWalletBalance', () => wallet.getWalletBalance(), DEFAULT_TIMEOUT_MS),
278279
settle('wallet.getWalletConnections', () => wallet.getWalletConnections(), DEFAULT_TIMEOUT_MS),
@@ -300,6 +301,7 @@ export const getDiagnosticsResponse = async ({ readOnly = false } = {}) => {
300301

301302
const [
302303
activeNetworkRes,
304+
chiaVersionRes,
303305
walletSyncedRes,
304306
walletBalanceRes,
305307
walletConnectionsRes,
@@ -479,6 +481,7 @@ export const getDiagnosticsResponse = async ({ readOnly = false } = {}) => {
479481
matches: networkMatches,
480482
},
481483
chia: {
484+
version: chiaVersionRes.ok ? chiaVersionRes.value : null,
482485
wallet: walletSection,
483486
fullNode: fullNodeSection,
484487
datalayer: datalayerSection,

tests/v2/integration/diagnostics.spec.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,15 @@ describe('/diagnostics endpoint', function () {
5555
}
5656
});
5757

58+
it('includes chia.version (string or null)', async function () {
59+
const response = await supertest(app).get('/diagnostics').expect(200);
60+
expect(response.body.chia).to.have.property('version');
61+
const v = response.body.chia.version;
62+
if (v !== null) {
63+
expect(v).to.be.a('string');
64+
}
65+
});
66+
5867
it('reports chia.services flags', async function () {
5968
const response = await supertest(app).get('/diagnostics').expect(200);
6069
const services = response.body.chia.services;

tests/v2/live-api/wallet-health.live.spec.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,12 @@ describe('Wallet Health - Live', function () {
137137
expect(body.system.disk.percentUsed).to.be.a('number').and.to.be.at.least(0).and.at.most(100);
138138
}
139139

140+
// Chia: version -------------------------------------------------------
141+
expect(body.chia).to.have.property('version');
142+
if (body.chia.version !== null) {
143+
expect(body.chia.version).to.be.a('string');
144+
}
145+
140146
// Chia: services flags ------------------------------------------------
141147
expect(body.chia.services).to.be.an('object');
142148
expect(body.chia.services.walletReachable).to.be.a('boolean');

0 commit comments

Comments
 (0)