2019-07-02 20:52:58 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
)
|
|
|
|
|
|
|
|
type StateController struct {
|
|
|
|
State *AppState
|
|
|
|
Client *StatusGoClient
|
|
|
|
}
|
|
|
|
|
|
|
|
// For fetching current state of peers from status-go
|
|
|
|
func (s *StateController) Fetch() {
|
|
|
|
peers, err := s.Client.getPeers()
|
|
|
|
if err != nil {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
ps := s.State.GetData()
|
|
|
|
s.State.UpdatePeers(peers)
|
|
|
|
if ps.Current == -1 {
|
|
|
|
s.State.SetCurrentPeer(0)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-03 19:21:27 +00:00
|
|
|
// For removing a selected peer from connected to status-go
|
|
|
|
func (s *StateController) TrustPeer(peer *Peer) error {
|
|
|
|
success, err := s.Client.trustPeer(peer.Enode)
|
|
|
|
if err != nil || success != true {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-02 20:52:58 +00:00
|
|
|
// For removing a selected peer from connected to status-go
|
|
|
|
func (s *StateController) RemovePeer(peer *Peer) error {
|
|
|
|
success, err := s.Client.removePeer(peer.Enode)
|
|
|
|
if err != nil || success != true {
|
|
|
|
log.Panicln(err)
|
|
|
|
}
|
|
|
|
s.Fetch()
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *StateController) GetInfo() error {
|
|
|
|
info, err := s.Client.nodeInfo()
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
2019-07-03 19:25:22 +00:00
|
|
|
s.State.UpdateInfo(info)
|
2019-07-02 20:52:58 +00:00
|
|
|
return nil
|
|
|
|
}
|