Skip to content

Commit

Permalink
feat(explored-types): add hostMetrics API
Browse files Browse the repository at this point in the history
  • Loading branch information
telestrial committed Dec 16, 2024
1 parent 292e6e2 commit 7a93acf
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changeset/smooth-hornets-fetch.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/explored-js': minor
'@siafoundation/explored-react': minor
'@siafoundation/explored-types': minor
---

Add hostMetrics API.
9 changes: 9 additions & 0 deletions libs/explored-js/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ import {
ContractByPubkeyParams,
ContractByPubkeyPayload,
ContractByPubkeyResponse,
hostMetricsRoute,
HostMetricsParams,
HostMetricsPayload,
HostMetricsResponse,
hostByPubkeyRoute,
HostByPubkeyParams,
HostByPubkeyPayload,
Expand Down Expand Up @@ -263,6 +267,11 @@ export function Explored({
BlockMetricsByIDPayload,
BlockMetricsByIDResponse
>(axios, 'get', blockMetricsByIDRoute),
hostMetrics: buildRequestHandler<
HostMetricsParams,
HostMetricsPayload,
HostMetricsResponse
>(axios, 'get', hostMetricsRoute),
// Search
searchResultType: buildRequestHandler<
SearchResultTypeParams,
Expand Down
12 changes: 12 additions & 0 deletions libs/explored-react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ import {
HostByPubkeyParams,
HostByPubkeyResponse,
hostByPubkeyRoute,
HostMetricsParams,
HostMetricsResponse,
hostMetricsRoute,
OutputSiacoinParams,
OutputSiacoinResponse,
outputSiacoinRoute,
Expand Down Expand Up @@ -345,6 +348,15 @@ export function useBlockMetricsByID(
})
}

export function useHostMetrics(
args: HookArgsSwr<HostMetricsParams, HostMetricsResponse>
) {
return useGetSwr({
...args,
route: hostMetricsRoute,
})
}

// Search

export function useSearchResultType(
Expand Down
6 changes: 6 additions & 0 deletions libs/explored-types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
ExplorerTransaction,
FileContractID,
Hash256,
HostMetrics,
Peer,
PublicKey,
SearchResultType,
Expand Down Expand Up @@ -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.
Expand Down
14 changes: 13 additions & 1 deletion libs/explored-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 7a93acf

Please sign in to comment.