2018-05-04 10:53:41 +00:00
|
|
|
package rpcfilters
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/ethereum/go-ethereum/node"
|
|
|
|
"github.com/ethereum/go-ethereum/p2p"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
2024-09-26 22:37:32 +00:00
|
|
|
"github.com/status-im/status-go/common"
|
2018-05-04 10:53:41 +00:00
|
|
|
)
|
|
|
|
|
2021-06-28 08:03:07 +00:00
|
|
|
// Make sure that Service implements node.Lifecycle interface.
|
|
|
|
var _ node.Lifecycle = (*Service)(nil)
|
2018-05-04 10:53:41 +00:00
|
|
|
|
|
|
|
// Service represents out own implementation of personal sign operations.
|
|
|
|
type Service struct {
|
2018-07-27 15:54:40 +00:00
|
|
|
latestBlockChangedEvent *latestBlockChangedEvent
|
|
|
|
transactionSentToUpstreamEvent *transactionSentToUpstreamEvent
|
2018-10-23 05:11:11 +00:00
|
|
|
rpc rpcProvider
|
|
|
|
|
|
|
|
quit chan struct{}
|
2018-05-04 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// New returns a new Service.
|
|
|
|
func New(rpc rpcProvider) *Service {
|
|
|
|
provider := &latestBlockProviderRPC{rpc}
|
2018-07-27 15:54:40 +00:00
|
|
|
latestBlockChangedEvent := newLatestBlockChangedEvent(provider)
|
|
|
|
transactionSentToUpstreamEvent := newTransactionSentToUpstreamEvent()
|
|
|
|
return &Service{
|
2018-10-23 05:11:11 +00:00
|
|
|
latestBlockChangedEvent: latestBlockChangedEvent,
|
|
|
|
transactionSentToUpstreamEvent: transactionSentToUpstreamEvent,
|
2018-10-28 16:12:16 +00:00
|
|
|
|
|
|
|
rpc: rpc,
|
2018-07-27 15:54:40 +00:00
|
|
|
}
|
2018-05-04 10:53:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// 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",
|
2018-10-23 05:11:11 +00:00
|
|
|
Service: NewPublicAPI(s),
|
|
|
|
Public: true,
|
2018-05-04 10:53:41 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Start is run when a service is started.
|
2021-06-28 08:03:07 +00:00
|
|
|
func (s *Service) Start() error {
|
2018-10-23 05:11:11 +00:00
|
|
|
s.quit = make(chan struct{})
|
2018-07-27 15:54:40 +00:00
|
|
|
err := s.transactionSentToUpstreamEvent.Start()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2018-05-04 10:53:41 +00:00
|
|
|
return s.latestBlockChangedEvent.Start()
|
|
|
|
}
|
|
|
|
|
|
|
|
// Stop is run when a service is stopped.
|
|
|
|
func (s *Service) Stop() error {
|
2018-10-23 05:11:11 +00:00
|
|
|
close(s.quit)
|
2018-07-27 15:54:40 +00:00
|
|
|
s.transactionSentToUpstreamEvent.Stop()
|
2018-05-04 10:53:41 +00:00
|
|
|
s.latestBlockChangedEvent.Stop()
|
|
|
|
return nil
|
|
|
|
}
|
2018-07-27 15:54:40 +00:00
|
|
|
|
2023-06-21 14:09:55 +00:00
|
|
|
func (s *Service) TransactionSentToUpstreamEvent() ChainEvent {
|
|
|
|
return s.transactionSentToUpstreamEvent
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Service) TriggerTransactionSentToUpstreamEvent(txInfo *PendingTxInfo) {
|
2024-09-26 22:37:32 +00:00
|
|
|
defer common.LogOnPanic()
|
2023-06-21 14:09:55 +00:00
|
|
|
s.transactionSentToUpstreamEvent.Trigger(txInfo)
|
2018-07-27 15:54:40 +00:00
|
|
|
}
|