Skip to content
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

feat(explored-types): add hostMetrics API #859

Merged
merged 1 commit into from
Dec 16, 2024
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
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
Loading