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

Make rpc get network power request optional #5151

Merged
merged 1 commit into from
Jul 18, 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
2 changes: 1 addition & 1 deletion ironfish/src/rpc/clients/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ export abstract class RpcClient {
},

getNetworkHashPower: (
params: GetNetworkHashPowerRequest,
params: GetNetworkHashPowerRequest = undefined,
): Promise<RpcResponseEnded<GetNetworkHashPowerResponse>> => {
return this.request<GetNetworkHashPowerResponse>(
`${ApiNamespace.chain}/getNetworkHashPower`,
Expand Down
3 changes: 2 additions & 1 deletion ironfish/src/rpc/routes/chain/getNetworkHashPower.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ describe('Route chain/getNetworkHashPower', () => {
await Promise.all([expect(routeTest.node.chain).toAddBlock(block)])
await Promise.all([routeTest.node.wallet.scan()])
}
const response = await routeTest.client.chain.getNetworkHashPower({})
const response = await routeTest.client.chain.getNetworkHashPower()

expect(response.content).toEqual(
expect.objectContaining({
hashesPerSecond: expect.any(Number),
Expand Down
12 changes: 7 additions & 5 deletions ironfish/src/rpc/routes/chain/getNetworkHashPower.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ import { RpcValidationError } from '../../adapters'
import { ApiNamespace } from '../namespaces'
import { routes } from '../router'

export type GetNetworkHashPowerRequest = {
blocks?: number | null // number of blocks to look back
sequence?: number | null // the sequence of the latest block from when to estimate the network speed
}
export type GetNetworkHashPowerRequest =
| {
blocks?: number | null // number of blocks to look back
sequence?: number | null // the sequence of the latest block from when to estimate the network speed
}
| undefined

export type GetNetworkHashPowerResponse = {
hashesPerSecond: number
Expand All @@ -26,7 +28,7 @@ export const GetNetworkHashPowerRequestSchema: yup.ObjectSchema<GetNetworkHashPo
blocks: yup.number().nullable().optional(),
sequence: yup.number().nullable().optional(),
})
.defined()
.optional()

export const GetNetworkHashPowerResponseSchema: yup.ObjectSchema<GetNetworkHashPowerResponse> =
yup
Expand Down