-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
59 lines (46 loc) · 1.35 KB
/
main.go
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main
import (
"context"
"encoding/json"
"fmt"
"time"
"log"
substrate "github.com/threefoldtech/tfchain/clients/tfchain-client-go"
"github.com/threefoldtech/tfgrid-sdk-go/farmerbot/internal"
"github.com/threefoldtech/tfgrid-sdk-go/rmb-sdk-go/peer"
)
func nodesReport() error {
mnemonics := "<mnemonics goes here>"
subManager := substrate.NewManager("wss://tfchain.dev.grid.tf/ws")
client, err := peer.NewRpcClient(
context.Background(),
mnemonics,
subManager,
peer.WithRelay("wss://relay.dev.grid.tf"),
peer.WithSession("test-report"),
)
if err != nil {
return fmt.Errorf("failed to create rpc client: %w", err)
}
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
farmID := 53 // <- replace this with the farm id of the farmerbot
service := fmt.Sprintf("farmerbot-%d", farmID)
const farmerbotTwinID = 164 // <- replace this with the twin id of where the farmerbot is running
var nodeID uint32
var nodesReport []internal.NodeReport
if err := client.CallWithSession(ctx, farmerbotTwinID, &service, "farmerbot.farmmanager.report", nodeID, &nodesReport); err != nil {
return err
}
report, err := json.MarshalIndent(nodesReport, "", " ")
if err != nil {
return err
}
fmt.Print(string(report))
return nil
}
func main() {
if err := nodesReport(); err != nil {
log.Fatal(err)
}
}