You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
1.2 KiB
39 lines
1.2 KiB
6 years ago
|
package client
|
||
|
|
||
|
import (
|
||
6 years ago
|
"github.com/harmony-one/harmony/core/types"
|
||
6 years ago
|
"github.com/harmony-one/harmony/log"
|
||
|
"github.com/harmony-one/harmony/p2p"
|
||
6 years ago
|
"github.com/harmony-one/harmony/p2p/host"
|
||
6 years ago
|
)
|
||
|
|
||
6 years ago
|
// Client represents a node (e.g. a wallet) which sends transactions and receives responses from the harmony network
|
||
6 years ago
|
type Client struct {
|
||
6 years ago
|
Leaders *map[uint32]p2p.Peer // Map of shard Id and corresponding leader
|
||
|
UpdateBlocks func([]*types.Block) // Closure function used to sync new block with the leader. Once the leader finishes the consensus on a new block, it will send it to the clients. Clients use this method to update their blockchain
|
||
6 years ago
|
|
||
6 years ago
|
log log.Logger // Log utility
|
||
6 years ago
|
|
||
|
// The p2p host used to send/receive p2p messages
|
||
|
host host.Host
|
||
6 years ago
|
}
|
||
|
|
||
6 years ago
|
// NewClient creates a new Client
|
||
6 years ago
|
func NewClient(host host.Host, leaders *map[uint32]p2p.Peer) *Client {
|
||
6 years ago
|
client := Client{}
|
||
6 years ago
|
client.Leaders = leaders
|
||
6 years ago
|
client.host = host
|
||
6 years ago
|
// Logger
|
||
|
client.log = log.New()
|
||
|
return &client
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
6 years ago
|
// GetLeaders returns leader peers.
|
||
6 years ago
|
func (client *Client) GetLeaders() []p2p.Peer {
|
||
|
leaders := []p2p.Peer{}
|
||
|
for _, leader := range *client.Leaders {
|
||
|
leaders = append(leaders, leader)
|
||
|
}
|
||
|
return leaders
|
||
|
}
|