-
Notifications
You must be signed in to change notification settings - Fork 14
/
status.go
60 lines (55 loc) · 1.63 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
package agent
import (
"github.com/fxamacker/cbor/v2"
)
// Implementation identifies the implementation of the Internet Computer.
type Implementation struct {
// Source is the canonical location of the source code.
Source string
// Version is the version number of the implementation.
Version string
// Revision is the precise git revision of the implementation.
Revision string
}
// Status describes various status fields of the Internet Computer.
type Status struct {
// Identifies the interface version supported.
Version string
// Impl describes the implementation of the Internet Computer.
Impl *Implementation
// The public key (a DER-encoded BLS key) of the root key of this Internet Computer instance.
RootKey []byte
}
func (s *Status) MarshalCBOR() ([]byte, error) {
m := map[string]any{
"ic_api_version": s.Version,
"root_key": s.RootKey,
}
if s.Impl != nil {
m["impl_source"] = s.Impl.Source
m["impl_version"] = s.Impl.Version
m["impl_revision"] = s.Impl.Revision
}
return cbor.Marshal(m)
}
// UnmarshalCBOR implements the CBOR unmarshaler interface.
func (s *Status) UnmarshalCBOR(data []byte) error {
var status struct {
APIVersion string `cbor:"ic_api_version"`
ImplSource string `cbor:"impl_source"`
ImplVersion string `cbor:"impl_version"`
ImplRevision string `cbor:"impl_revision"`
RootKey []byte `cbor:"root_key"`
}
if err := cbor.Unmarshal(data, &status); err != nil {
return err
}
s.Version = status.APIVersion
s.Impl = &Implementation{
Source: status.ImplSource,
Version: status.ImplVersion,
Revision: status.ImplRevision,
}
s.RootKey = status.RootKey
return nil
}