From 8b7766de6ff1217b1e18dd336ca3a0097fccac1e Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Thu, 24 Jan 2019 23:35:15 +0000 Subject: [PATCH] encode PeerID using IDB58 This is to fix error of "Invalid UTF-8 in peerID field". Signed-off-by: Leo Chen --- cmd/client/wallet/main.go | 6 +++++- internal/beaconchain/rpc/server.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index f7c8f621a..6b6975022 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -296,7 +296,11 @@ func CreateWalletNode() *node.Node { response := bcClient.GetLeaders() for _, leader := range response.Leaders { - shardIDLeaderMap[leader.ShardId] = p2p.Peer{IP: leader.Ip, Port: leader.Port, PeerID: peer.ID(leader.PeerID)} + peerID, err := peer.IDB58Decode(leader.PeerID) + if err != nil { + panic(err) + } + shardIDLeaderMap[leader.ShardId] = p2p.Peer{IP: leader.Ip, Port: leader.Port, PeerID: peerID} } // dummy host for wallet diff --git a/internal/beaconchain/rpc/server.go b/internal/beaconchain/rpc/server.go index 38cf13c4f..4542918f8 100644 --- a/internal/beaconchain/rpc/server.go +++ b/internal/beaconchain/rpc/server.go @@ -23,7 +23,7 @@ func (s *Server) FetchLeaders(ctx context.Context, request *proto.FetchLeadersRe leaders := []*proto.FetchLeadersResponse_Leader{} for shardID, leader := range s.shardLeaderMap() { - leaders = append(leaders, &proto.FetchLeadersResponse_Leader{Ip: leader.IP, Port: leader.Port, ShardId: uint32(shardID), PeerID: string(leader.PeerID)}) + leaders = append(leaders, &proto.FetchLeadersResponse_Leader{Ip: leader.IP, Port: leader.Port, ShardId: uint32(shardID), PeerID: leader.PeerID.Pretty()}) } log.Println(leaders) return &proto.FetchLeadersResponse{Leaders: leaders}, nil