-
Notifications
You must be signed in to change notification settings - Fork 249
/
Copy pathservice.go
83 lines (67 loc) · 1.76 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
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
package status
import (
"encoding/json"
"errors"
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/protocol"
)
// Make sure that Service implements node.Lifecycle interface.
var _ node.Lifecycle = (*Service)(nil)
var ErrNotInitialized = errors.New("status public api not initialized")
// Service represents out own implementation of personal sign operations.
type Service struct {
messenger *protocol.Messenger
}
// New returns a new Service.
func New() *Service {
return &Service{}
}
func (s *Service) Init(messenger *protocol.Messenger) {
s.messenger = messenger
}
// Protocols returns a new protocols list. In this case, there are none.
func (s *Service) Protocols() []p2p.Protocol {
return []p2p.Protocol{}
}
// APIs returns a list of new APIs.
func (s *Service) APIs() []rpc.API {
return []rpc.API{
{
Namespace: "status",
Version: "1.0",
Service: NewPublicAPI(s),
Public: true,
},
}
}
// NewPublicAPI returns a reference to the PublicAPI object
func NewPublicAPI(s *Service) *PublicAPI {
api := &PublicAPI{
service: s,
}
return api
}
// Start is run when a service is started.
func (s *Service) Start() error {
return nil
}
// Stop is run when a service is stopped.
func (s *Service) Stop() error {
return nil
}
type PublicAPI struct {
service *Service
}
func (p *PublicAPI) CommunityInfo(communityID types.HexBytes) (json.RawMessage, error) {
if p.service.messenger == nil {
return nil, ErrNotInitialized
}
community, err := p.service.messenger.RequestCommunityInfoFromMailserver(communityID.String(), true)
if err != nil {
return nil, err
}
return community.MarshalPublicAPIJSON()
}