Skip to content

Commit 694fce7

Browse files
committed
use direct command for status
1 parent 9342402 commit 694fce7

3 files changed

Lines changed: 59 additions & 10 deletions

File tree

src/@types/Provider.ts

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,46 @@ export interface ServiceEndpoint {
4343
urlPath: string
4444
}
4545

46+
export interface NodeStatusProvider {
47+
chainId: string
48+
network: string
49+
}
50+
51+
export interface NodeStatusIndexer {
52+
chainId: string
53+
network: string
54+
block: string
55+
}
56+
4657
export interface NodeStatus {
47-
nodeId: string
48-
chainIds: string[]
49-
providerAddress: string
50-
nodePublicKey: Record<string, number>
51-
serviceEndpoints: Record<string, [string, string]>
52-
software: string
58+
id: string
59+
publicKey: string
60+
friendlyName: string
61+
address: string
5362
version: string
63+
http: boolean
64+
p2p: boolean
65+
provider: NodeStatusProvider[]
66+
indexer: NodeStatusIndexer[]
67+
escrowAddress: Record<string, string>
68+
supportedStorage: Record<string, boolean>
69+
platform: {
70+
cpus: number
71+
freemem: number
72+
totalmem: number
73+
loadavg: number[]
74+
arch: string
75+
machine: string
76+
platform: string
77+
osType: string
78+
node: string
79+
}
80+
codeHash: string
81+
allowedAdmins: {
82+
addresses: string[]
83+
accessLists: string[] | null
84+
}
85+
uptime: number
5486
}
5587
export interface UserCustomParameters {
5688
[key: string]: any

src/services/providers/HttpProvider.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,23 @@ export class HttpProvider {
5757
}
5858

5959
public async getNodeStatus(nodeUri: string, signal?: AbortSignal): Promise<NodeStatus> {
60-
return this.getEndpoints(nodeUri)
60+
const providerEndpoints = await this.getEndpoints(nodeUri)
61+
const serviceEndpoints = await this.getServiceEndpoints(nodeUri, providerEndpoints)
62+
const endpoint = this.getEndpointURL(serviceEndpoints, 'directCommand')
63+
if (!endpoint?.urlPath) return null
64+
try {
65+
const response = await fetch(endpoint.urlPath, {
66+
method: 'POST',
67+
headers: { 'Content-Type': 'application/json' },
68+
body: JSON.stringify({ command: PROTOCOL_COMMANDS.STATUS }),
69+
signal
70+
})
71+
if (response?.ok) return response.json()
72+
return null
73+
} catch (e) {
74+
LoggerInstance.error('getNodeStatus failed:', e)
75+
return null
76+
}
6177
}
6278

6379
public async getNodeJobs(

test/integration/Provider.test.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ describe('Provider tests', async () => {
5858
it('Alice tests getNodeStatus', async () => {
5959
const status = await ProviderInstance.getNodeStatus(config.oceanNodeUri)
6060
assert(status, 'No status returned')
61-
assert(status.providerAddress, 'Status missing provider address')
62-
assert(status.nodeId, 'Status missing nodeId')
63-
assert(Array.isArray(status.chainIds), 'Status missing chainIds')
61+
assert(status.id, 'Status missing id')
62+
assert(status.address, 'Status missing address')
63+
assert(status.version, 'Status missing version')
64+
assert(Array.isArray(status.provider), 'Status missing provider array')
6465
})
6566

6667
it('Alice tests getNodeJobs', async () => {

0 commit comments

Comments
 (0)