diff --git a/.changeset/smooth-hornets-fetch.md b/.changeset/smooth-hornets-fetch.md new file mode 100644 index 000000000..66403e825 --- /dev/null +++ b/.changeset/smooth-hornets-fetch.md @@ -0,0 +1,7 @@ +--- +'@siafoundation/explored-js': minor +'@siafoundation/explored-react': minor +'@siafoundation/explored-types': minor +--- + +Add hostMetrics API. diff --git a/libs/explored-js/src/api.ts b/libs/explored-js/src/api.ts index b88f61c92..e36c2f5f2 100644 --- a/libs/explored-js/src/api.ts +++ b/libs/explored-js/src/api.ts @@ -52,6 +52,10 @@ import { ContractByPubkeyParams, ContractByPubkeyPayload, ContractByPubkeyResponse, + hostMetricsRoute, + HostMetricsParams, + HostMetricsPayload, + HostMetricsResponse, hostByPubkeyRoute, HostByPubkeyParams, HostByPubkeyPayload, @@ -263,6 +267,11 @@ export function Explored({ BlockMetricsByIDPayload, BlockMetricsByIDResponse >(axios, 'get', blockMetricsByIDRoute), + hostMetrics: buildRequestHandler< + HostMetricsParams, + HostMetricsPayload, + HostMetricsResponse + >(axios, 'get', hostMetricsRoute), // Search searchResultType: buildRequestHandler< SearchResultTypeParams, diff --git a/libs/explored-react/src/hooks.ts b/libs/explored-react/src/hooks.ts index 1861f1313..a43476f0f 100644 --- a/libs/explored-react/src/hooks.ts +++ b/libs/explored-react/src/hooks.ts @@ -39,6 +39,9 @@ import { HostByPubkeyParams, HostByPubkeyResponse, hostByPubkeyRoute, + HostMetricsParams, + HostMetricsResponse, + hostMetricsRoute, OutputSiacoinParams, OutputSiacoinResponse, outputSiacoinRoute, @@ -345,6 +348,15 @@ export function useBlockMetricsByID( }) } +export function useHostMetrics( + args: HookArgsSwr +) { + return useGetSwr({ + ...args, + route: hostMetricsRoute, + }) +} + // Search export function useSearchResultType( diff --git a/libs/explored-types/src/api.ts b/libs/explored-types/src/api.ts index 5c9b1bb10..d90d8e5f2 100644 --- a/libs/explored-types/src/api.ts +++ b/libs/explored-types/src/api.ts @@ -16,6 +16,7 @@ import { ExplorerTransaction, FileContractID, Hash256, + HostMetrics, Peer, PublicKey, SearchResultType, @@ -216,6 +217,11 @@ export type BlockMetricsByIDParams = { id: BlockID } export type BlockMetricsByIDPayload = void export type BlockMetricsByIDResponse = BlockMetrics +export const hostMetricsRoute = '/metrics/host' +export type HostMetricsParams = void +export type HostMetricsPayload = void +export type HostMetricsResponse = HostMetrics + // Search // Returns what type of object an ID is. diff --git a/libs/explored-types/src/types.ts b/libs/explored-types/src/types.ts index 3e9464620..cc4ae11ec 100644 --- a/libs/explored-types/src/types.ts +++ b/libs/explored-types/src/types.ts @@ -107,7 +107,19 @@ export type TxpoolTransactions = { v2transactions: V2Transaction[] } -// Novel Explored Types - There are three main differences that inform what's below: +export type HostMetrics = { + // Number of hosts that were up as of last scan. + activeHosts: number + // Total storage of all active hosts, in bytes. + totalStorage: number + // Remaining storage of all active hosts, in bytes. + remainingStorage: number + + settings: HostSettings + priceTable: HostPriceTable +} + +// Novel Explored Types /** * HostAnnouncement represents a signed announcement of a host's network address.