-
Notifications
You must be signed in to change notification settings - Fork 2
/
get-client.js
39 lines (32 loc) · 1018 Bytes
/
get-client.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require('dotenv').config()
const { getClient } = require('@phala/sdk')
const argv = require('arg')({
'--ws': String,
'--clusterId': String,
'--worker': String,
'--pruntimeURL': String
})
async function main() {
const ws = argv['--ws'] || process.env.ENDPOINT
if (!ws) {
throw new Error('No ws endpoint specified')
}
const clusterId = argv['--clusterId']
const workerId = argv['--worker']
const pruntimeURL = argv['--pruntimeURL']
const connectionOptions = {}
if (clusterId) {
connectionOptions.clusterId = clusterId
}
if (workerId) {
connectionOptions.workerId = workerId
} else if (pruntimeURL) {
connectionOptions.pruntimeURL = pruntimeURL
}
const client = await getClient({ transport: ws, ...connectionOptions })
console.log('Connected via', ws)
console.log('Cluster ID:', client.clusterId)
console.log('Worker ID:', client.remotePubkey)
console.log('Worker Endpoint:', client.pruntimeURL)
}
main().catch(console.error).finally(() => process.exit())