This repository has been archived by the owner on Oct 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 35
/
status.go
120 lines (108 loc) · 3.1 KB
/
status.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//go:generate ./scripts/contract-gen.sh
//go:generate ./scripts/build.sh
package killcord
import (
"fmt"
)
func (s *Session) GetStatus() error {
if err := s.getProjectStatus(); err != nil {
return err
}
if err := s.getContractStatus(); err != nil {
return err
}
if err := s.getPayloadStatus(); err != nil {
return err
}
if err := s.getPublisherStatus(); err != nil {
return err
}
return nil
}
func (s *Session) getProjectStatus() error {
fmt.Println("")
fmt.Printf("Project Status:\t\t\t%v\n", s.Config.Status)
fmt.Println("--------------")
return nil
}
func (s *Session) getContractStatus() error {
fmt.Println("")
fmt.Printf("Contract Status:\t\t%v\n", s.Config.Contract.Status)
fmt.Println("---------------")
var registeredOwnerAddress, registeredPublisherAddress string
if s.Config.Contract.ID != "" {
fmt.Printf("\tContract ID:\t\t0x%v\n", s.Config.Contract.ID)
// get last checkin
checkin, err := GetLastCheckIn(s.Config.Contract.ID)
if err != nil {
return err
}
fmt.Printf("\tLast Checkin:\t\t%v\n", checkin)
// get endpoint info
endpoint, err := GetPayloadEndpoint(s.Config.Contract.ID)
if err != nil {
return err
}
if endpoint == "" {
endpoint = "not configured"
}
fmt.Printf("\tRegistered Endpoint:\t%v\n", endpoint)
// get Key info
key, err := GetKey(s.Config.Contract.ID)
if err != nil {
return err
}
// if key is written to the contract and it does not
// exist in the config, write it to the config
if key != "" && s.Config.Payload.Secret == "" {
s.Config.Payload.Secret = key
fmt.Println("payload secret discovered, writing to config")
fmt.Println("to decrypt the payload run: killcord decrypt")
}
if key == "" {
key = "not published"
}
fmt.Printf("\tDecryption Key:\t\t%v\n", key)
registeredOwnerAddress, err = GetOwner(s.Config.Contract.ID)
if err != nil {
return err
}
registeredPublisherAddress, err = GetPublisher(s.Config.Contract.ID)
if err != nil {
return err
}
}
if s.Config.Contract.Owner.Address != "" {
OwnBal := getBalance(s.Config.Contract.Owner.Address)
fmt.Printf("\tOwner Balance:\t\t%v\n", OwnBal)
}
if s.Config.Contract.Owner.Address != "" {
fmt.Printf("\tOwner (local):\t\t%v\n", "0x"+s.Config.Contract.Owner.Address)
}
if registeredOwnerAddress != "" {
fmt.Printf("\tOwner (contract):\t%v\n", registeredOwnerAddress)
}
if s.Config.Contract.Publisher.Address != "" {
pubBal := getBalance(s.Config.Contract.Publisher.Address)
fmt.Printf("\tPublisher Balance:\t%v\n", pubBal)
}
if s.Config.Contract.Publisher.Address != "" {
fmt.Printf("\tPublisher (local):\t%v\n", "0x"+s.Config.Contract.Publisher.Address)
}
if registeredPublisherAddress != "" {
fmt.Printf("\tPublisher (contract):\t%v\n", registeredPublisherAddress)
}
return nil
}
func (s *Session) getPayloadStatus() error {
fmt.Println("")
fmt.Printf("Payload Status:\t\t\t%v\n", s.Config.Payload.Status)
fmt.Println("--------------")
return nil
}
func (s *Session) getPublisherStatus() error {
fmt.Println("")
fmt.Printf("Publisher Status:\t\t%v\n", s.Config.Publisher.Status)
fmt.Println("----------------")
return nil
}