Skip to content

Commit

Permalink
refactor(explored-types): rename block metrics APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
telestrial committed Dec 16, 2024
1 parent 95f51d3 commit 0d6b8d0
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 39 deletions.
7 changes: 7 additions & 0 deletions .changeset/shiny-pugs-punch.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
---

Rename block metrics APIs.
36 changes: 18 additions & 18 deletions libs/explored-js/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,14 +56,14 @@ import {
HostByPubkeyParams,
HostByPubkeyPayload,
HostByPubkeyResponse,
metricsRoute,
MetricsParams,
MetricsPayload,
MetricsResponse,
metricsByIDRoute,
MetricsByIDParams,
MetricsByIDPayload,
MetricsByIDResponse,
blockMetricsRoute,
BlockMetricsParams,
BlockMetricsPayload,
BlockMetricsResponse,
blockMetricsByIDRoute,
BlockMetricsByIDParams,
BlockMetricsByIDPayload,
BlockMetricsByIDResponse,
OutputSiacoinParams,
OutputSiacoinPayload,
OutputSiacoinResponse,
Expand Down Expand Up @@ -253,16 +253,16 @@ export function Explored({
ContractRevisionsResponse
>(axios, 'get', contractRevisionsRoute),
// Metrics
metrics: buildRequestHandler<
MetricsParams,
MetricsPayload,
MetricsResponse
>(axios, 'get', metricsRoute),
metricsByID: buildRequestHandler<
MetricsByIDParams,
MetricsByIDPayload,
MetricsByIDResponse
>(axios, 'get', metricsByIDRoute),
blockMetrics: buildRequestHandler<
BlockMetricsParams,
BlockMetricsPayload,
BlockMetricsResponse
>(axios, 'get', blockMetricsRoute),
blockMetricsByID: buildRequestHandler<
BlockMetricsByIDParams,
BlockMetricsByIDPayload,
BlockMetricsByIDResponse
>(axios, 'get', blockMetricsByIDRoute),
// Search
searchResultType: buildRequestHandler<
SearchResultTypeParams,
Expand Down
24 changes: 13 additions & 11 deletions libs/explored-react/src/hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ import {
AddressSiafundUTXOsParams,
AddressSiafundUTXOsResponse,
addressSiafundUTXOsRoute,
BlockMetricsByIDParams,
BlockMetricsByIDResponse,
blockMetricsByIDRoute,
BlockMetricsParams,
BlockMetricsResponse,
blockMetricsRoute,
ConsensusNetworkParams,
ConsensusNetworkResponse,
consensusNetworkRoute,
Expand All @@ -33,12 +39,6 @@ import {
HostByPubkeyParams,
HostByPubkeyResponse,
hostByPubkeyRoute,
MetricsByIDParams,
MetricsByIDResponse,
metricsByIDRoute,
MetricsParams,
MetricsResponse,
metricsRoute,
OutputSiacoinParams,
OutputSiacoinResponse,
outputSiacoinRoute,
Expand Down Expand Up @@ -327,19 +327,21 @@ export function useContractRevisions(

// Metrics

export function useMetrics(args: HookArgsSwr<MetricsParams, MetricsResponse>) {
export function useBlockMetrics(
args: HookArgsSwr<BlockMetricsParams, BlockMetricsResponse>
) {
return useGetSwr({
...args,
route: metricsRoute,
route: blockMetricsRoute,
})
}

export function useMetricsByID(
args: HookArgsSwr<MetricsByIDParams, MetricsByIDResponse>
export function useBlockMetricsByID(
args: HookArgsSwr<BlockMetricsByIDParams, BlockMetricsByIDResponse>
) {
return useGetSwr({
...args,
route: metricsByIDRoute,
route: blockMetricsByIDRoute,
})
}

Expand Down
18 changes: 9 additions & 9 deletions libs/explored-types/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
AddressBalance,
Block,
BlockID,
BlockMetrics,
ChainIndex,
ConsensusNetwork,
ConsensusState,
Expand All @@ -15,7 +16,6 @@ import {
ExplorerTransaction,
FileContractID,
Hash256,
Metrics,
Peer,
PublicKey,
SearchResultType,
Expand Down Expand Up @@ -205,16 +205,16 @@ export type ContractRevisionsResponse = ExplorerFileContract[]
// Metrics

// Returns the most recent metrics about Sia.
export const metricsRoute = '/metrics/block'
export type MetricsParams = void
export type MetricsPayload = void
export type MetricsResponse = Metrics
export const blockMetricsRoute = '/metrics/block'
export type BlockMetricsParams = void
export type BlockMetricsPayload = void
export type BlockMetricsResponse = BlockMetrics

// Returns various metrics about Sia at the time of the given block ID.
export const metricsByIDRoute = '/metrics/block/:id'
export type MetricsByIDParams = { id: BlockID }
export type MetricsByIDPayload = void
export type MetricsByIDResponse = Metrics
export const blockMetricsByIDRoute = '/metrics/block/:id'
export type BlockMetricsByIDParams = { id: BlockID }
export type BlockMetricsByIDPayload = void
export type BlockMetricsByIDResponse = BlockMetrics

// Search

Expand Down
2 changes: 1 addition & 1 deletion libs/explored-types/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export type Event = {
data: string
}

export type Metrics = {
export type BlockMetrics = {
index: ChainIndex
difficulty: string
totalHosts: number
Expand Down

0 comments on commit 0d6b8d0

Please sign in to comment.