Skip to content

Commit

Permalink
feat(renterd): add consensus network API
Browse files Browse the repository at this point in the history
  • Loading branch information
alexfreska committed Oct 22, 2024
1 parent 76c523b commit ae5aeec
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .changeset/mean-numbers-train.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@siafoundation/renterd-js': minor
'@siafoundation/renterd-react': minor
'@siafoundation/renterd-types': minor
---

Added consensus network API.
9 changes: 9 additions & 0 deletions libs/renterd-js/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,10 @@ import {
busSettingsS3Route,
busSettingsUploadRoute,
busObjectsRemoveRoute,
ConsensusNetworkParams,
ConsensusNetworkPayload,
ConsensusNetworkResponse,
busConsensusNetworkRoute,
} from '@siafoundation/renterd-types'
import { buildRequestHandler, initAxios } from '@siafoundation/request'

Expand All @@ -282,6 +286,11 @@ export function Bus({ api, password }: { api: string; password?: string }) {
ConsensusStatePayload,
ConsensusStateResponse
>(axios, 'get', busConsensusStateRoute),
consensusNetwork: buildRequestHandler<
ConsensusNetworkParams,
ConsensusNetworkPayload,
ConsensusNetworkResponse
>(axios, 'get', busConsensusNetworkRoute),
consensusAcceptBlock: buildRequestHandler<
ConsensusAcceptBlockParams,
ConsensusAcceptBlockPayload,
Expand Down
12 changes: 12 additions & 0 deletions libs/renterd-react/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ import {
SettingsUploadUpdateResponse,
SettingsPinnedResponse,
busObjectsRemoveRoute,
ConsensusNetworkParams,
ConsensusNetworkResponse,
busConsensusNetworkRoute,
} from '@siafoundation/renterd-types'

// state
Expand Down Expand Up @@ -283,6 +286,15 @@ export function useConsensusState(
})
}

export function useConsensusNetwork(
args?: HookArgsSwr<ConsensusNetworkParams, ConsensusNetworkResponse>
) {
return useGetSwr({
...args,
route: busConsensusNetworkRoute,
})
}

export function useEstimatedNetworkBlockHeight(): number {
const state = useBusState({
config: {
Expand Down
5 changes: 5 additions & 0 deletions libs/renterd-types/src/bus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {

export const busStateRoute = '/bus/state'
export const busAutopilotsRoute = '/bus/autopilots'
export const busConsensusNetworkRoute = '/bus/consensus/network'
export const busConsensusStateRoute = '/bus/consensus/state'
export const busConsensusAcceptblockRoute = '/bus/consensus/acceptblock'
export const busSyncerPeersRoute = '/bus/syncer/peers'
Expand Down Expand Up @@ -121,6 +122,10 @@ export type ConsensusStateParams = void
export type ConsensusStatePayload = void
export type ConsensusStateResponse = ConsensusState

export type ConsensusNetworkParams = void
export type ConsensusNetworkPayload = void
export type ConsensusNetworkResponse = string

export type ConsensusAcceptBlockParams = void
export type ConsensusAcceptBlockPayload = Block
export type ConsensusAcceptBlockResponse = void
Expand Down

0 comments on commit ae5aeec

Please sign in to comment.