/
service.go
58 lines (52 loc) · 2.21 KB
/
service.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
package rocketpool
import (
"fmt"
"github.com/goccy/go-json"
"github.com/rocket-pool/smartnode/shared/types/api"
)
// Deletes the data folder including the wallet file, password file, and all validator keys.
// Don't use this unless you have a very good reason to do it (such as switching from a Testnet to Mainnet).
func (c *Client) TerminateDataFolder() (api.TerminateDataFolderResponse, error) {
responseBytes, err := c.callAPI("service terminate-data-folder")
if err != nil {
return api.TerminateDataFolderResponse{}, fmt.Errorf("Could not delete data folder: %w", err)
}
var response api.TerminateDataFolderResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.TerminateDataFolderResponse{}, fmt.Errorf("Could not decode terminate-data-folder response: %w", err)
}
if response.Error != "" {
return api.TerminateDataFolderResponse{}, fmt.Errorf("Could not delete data folder: %s", response.Error)
}
return response, nil
}
// Gets the status of the configured Execution and Beacon clients
func (c *Client) GetClientStatus() (api.ClientStatusResponse, error) {
responseBytes, err := c.callAPI("service get-client-status")
if err != nil {
return api.ClientStatusResponse{}, fmt.Errorf("Could not get client status: %w", err)
}
var response api.ClientStatusResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.ClientStatusResponse{}, fmt.Errorf("Could not decode client status response: %w", err)
}
if response.Error != "" {
return api.ClientStatusResponse{}, fmt.Errorf("Could not get client status: %s", response.Error)
}
return response, nil
}
// Restarts the Validator client
func (c *Client) RestartVc() (api.RestartVcResponse, error) {
responseBytes, err := c.callAPI("service restart-vc")
if err != nil {
return api.RestartVcResponse{}, fmt.Errorf("Could not get restart-vc status: %w", err)
}
var response api.RestartVcResponse
if err := json.Unmarshal(responseBytes, &response); err != nil {
return api.RestartVcResponse{}, fmt.Errorf("Could not decode restart-vc response: %w", err)
}
if response.Error != "" {
return api.RestartVcResponse{}, fmt.Errorf("Could not get restart-vc status: %s", response.Error)
}
return response, nil
}