-
Notifications
You must be signed in to change notification settings - Fork 244
/
service.go
75 lines (63 loc) · 1.9 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
package rpcfilters
import (
"github.com/ethereum/go-ethereum/node"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/rpc"
)
// Make sure that Service implements node.Lifecycle interface.
var _ node.Lifecycle = (*Service)(nil)
// Service represents out own implementation of personal sign operations.
type Service struct {
latestBlockChangedEvent *latestBlockChangedEvent
transactionSentToUpstreamEvent *transactionSentToUpstreamEvent
rpc rpcProvider
quit chan struct{}
}
// New returns a new Service.
func New(rpc rpcProvider) *Service {
provider := &latestBlockProviderRPC{rpc}
latestBlockChangedEvent := newLatestBlockChangedEvent(provider)
transactionSentToUpstreamEvent := newTransactionSentToUpstreamEvent()
return &Service{
latestBlockChangedEvent: latestBlockChangedEvent,
transactionSentToUpstreamEvent: transactionSentToUpstreamEvent,
rpc: rpc,
}
}
// 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: "eth",
Version: "1.0",
Service: NewPublicAPI(s),
Public: true,
},
}
}
// Start is run when a service is started.
func (s *Service) Start() error {
s.quit = make(chan struct{})
err := s.transactionSentToUpstreamEvent.Start()
if err != nil {
return err
}
return s.latestBlockChangedEvent.Start()
}
// Stop is run when a service is stopped.
func (s *Service) Stop() error {
close(s.quit)
s.transactionSentToUpstreamEvent.Stop()
s.latestBlockChangedEvent.Stop()
return nil
}
func (s *Service) TransactionSentToUpstreamEvent() ChainEvent {
return s.transactionSentToUpstreamEvent
}
func (s *Service) TriggerTransactionSentToUpstreamEvent(txInfo *PendingTxInfo) {
s.transactionSentToUpstreamEvent.Trigger(txInfo)
}