Skip to content

Commit b2d5790

Browse files
committed
feat(explored-types): add hostMetrics API
1 parent 292e6e2 commit b2d5790

File tree

5 files changed

+47
-1
lines changed

5 files changed

+47
-1
lines changed

.changeset/smooth-hornets-fetch.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@siafoundation/explored-js': minor
3+
'@siafoundation/explored-react': minor
4+
'@siafoundation/explored-types': minor
5+
---
6+
7+
Add hostMetrics API.

libs/explored-js/src/api.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ import {
5252
ContractByPubkeyParams,
5353
ContractByPubkeyPayload,
5454
ContractByPubkeyResponse,
55+
hostMetricsRoute,
56+
HostMetricsParams,
57+
HostMetricsPayload,
58+
HostMetricsResponse,
5559
hostByPubkeyRoute,
5660
HostByPubkeyParams,
5761
HostByPubkeyPayload,
@@ -263,6 +267,11 @@ export function Explored({
263267
BlockMetricsByIDPayload,
264268
BlockMetricsByIDResponse
265269
>(axios, 'get', blockMetricsByIDRoute),
270+
hostMetrics: buildRequestHandler<
271+
HostMetricsParams,
272+
HostMetricsPayload,
273+
HostMetricsResponse
274+
>(axios, 'get', hostMetricsRoute),
266275
// Search
267276
searchResultType: buildRequestHandler<
268277
SearchResultTypeParams,

libs/explored-react/src/hooks.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ import {
3939
HostByPubkeyParams,
4040
HostByPubkeyResponse,
4141
hostByPubkeyRoute,
42+
HostMetricsParams,
43+
HostMetricsResponse,
44+
hostMetricsRoute,
4245
OutputSiacoinParams,
4346
OutputSiacoinResponse,
4447
outputSiacoinRoute,
@@ -345,6 +348,15 @@ export function useBlockMetricsByID(
345348
})
346349
}
347350

351+
export function useHostMetrics(
352+
args: HookArgsSwr<HostMetricsParams, HostMetricsResponse>
353+
) {
354+
return useGetSwr({
355+
...args,
356+
route: hostMetricsRoute,
357+
})
358+
}
359+
348360
// Search
349361

350362
export function useSearchResultType(

libs/explored-types/src/api.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
ExplorerTransaction,
1717
FileContractID,
1818
Hash256,
19+
HostMetrics,
1920
Peer,
2021
PublicKey,
2122
SearchResultType,
@@ -216,6 +217,11 @@ export type BlockMetricsByIDParams = { id: BlockID }
216217
export type BlockMetricsByIDPayload = void
217218
export type BlockMetricsByIDResponse = BlockMetrics
218219

220+
export const hostMetricsRoute = '/metrics/host'
221+
export type HostMetricsParams = void
222+
export type HostMetricsPayload = void
223+
export type HostMetricsResponse = HostMetrics
224+
219225
// Search
220226

221227
// Returns what type of object an ID is.

libs/explored-types/src/types.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,19 @@ export type TxpoolTransactions = {
107107
v2transactions: V2Transaction[]
108108
}
109109

110-
// Novel Explored Types - There are three main differences that inform what's below:
110+
export type HostMetrics = {
111+
// Number of hosts that were up as of last scan.
112+
activeHosts: number
113+
// Total storage of all active hosts, in bytes.
114+
totalStorage: number
115+
// Remaining storage of all active hosts, in bytes.
116+
remainingStorage: number
117+
118+
settings: HostSettings
119+
priceTable: HostPriceTable
120+
}
121+
122+
// Novel Explored Types
111123

112124
/**
113125
* HostAnnouncement represents a signed announcement of a host's network address.

0 commit comments

Comments
 (0)