Changing Client Interface

pull/853/head
ak 6 years ago
parent 71378dca06
commit 1ecabf2db9
  1. 6
      api/client/client.go
  2. 7
      api/client/client_test.go
  3. 4
      cmd/client/txgen/main.go
  4. 6
      cmd/client/wallet/main.go

@ -8,7 +8,7 @@ import (
// Client represents a node (e.g. a wallet) which sends transactions and receives responses from the harmony network
type Client struct {
ShardIDs []uint32 // list of ShardID
ShardID uint32 // ShardID
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
log log.Logger // Log utility
@ -18,10 +18,10 @@ type Client struct {
}
// NewClient creates a new Client
func NewClient(host p2p.Host, shardIDs []uint32) *Client {
func NewClient(host p2p.Host, shardID uint32) *Client {
client := Client{}
client.host = host
client.ShardIDs = shardIDs
client.ShardID = shardID
// Logger
client.log = log.New()
return &client

@ -5,10 +5,9 @@ import (
)
func TestClient(t *testing.T) {
shardIDs := []uint32{0}
client := NewClient(nil, shardIDs)
if len(client.ShardIDs) != 1 || client.ShardIDs[0] != 0 {
shardID := uint32(0)
client := NewClient(nil, shardID)
if client.ShardID != uint32(0) {
t.Errorf("client initiate incorrect")
}
}

@ -81,8 +81,6 @@ func setUpTXGen() *node.Node {
panic(fmt.Errorf("generate key error"))
}
shardID := *shardIDFlag
var shardIDs []uint32
shardIDs = append(shardIDs, uint32(shardID))
selfPeer := p2p.Peer{IP: *ip, Port: *port, ConsensusPubKey: peerPubKey}
gsif, err := consensus.NewGenesisStakeInfoFinder()
@ -98,7 +96,7 @@ func setUpTXGen() *node.Node {
}
consensusObj, err := consensus.New(myhost, uint32(shardID), p2p.Peer{}, nil)
txGen := node.New(myhost, consensusObj, nil, false) //Changed it : no longer archival node.
txGen.Client = client.NewClient(txGen.GetHost(), shardIDs)
txGen.Client = client.NewClient(txGen.GetHost(), uint32(shardID))
consensusObj.SetStakeInfoFinder(gsif)
consensusObj.ChainReader = txGen.Blockchain()
consensusObj.PublicKeys = nil

@ -226,9 +226,7 @@ func createWalletNode() *node.Node {
panic(err)
}
utils.BootNodes = bootNodeAddrs
shardIDs := []uint32{0}
shardID := 0
// dummy host for wallet
// TODO: potentially, too many dummy IP may flush out good IP address from our bootnode DHT
// we need to understand the impact to bootnode DHT with this dummy host ip added
@ -239,7 +237,7 @@ func createWalletNode() *node.Node {
panic(err)
}
w := node.New(host, nil, nil, false)
w.Client = client.NewClient(w.GetHost(), shardIDs)
w.Client = client.NewClient(w.GetHost(), uint32(shardID))
w.NodeConfig.SetRole(nodeconfig.ClientNode)
w.ServiceManagerSetup()

Loading…
Cancel
Save