From af696dfbab5b886c71fc17eef25c7750e10fd339 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 11 Mar 2019 23:40:37 +0000 Subject: [PATCH 1/2] [log] disable logging for wallet Signed-off-by: Leo Chen --- api/service/manager.go | 4 ---- cmd/client/wallet/lib/lib.go | 3 ++- cmd/client/wallet/main.go | 8 +++++--- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/api/service/manager.go b/api/service/manager.go index e2fcad4d9..9bb26ef53 100644 --- a/api/service/manager.go +++ b/api/service/manager.go @@ -1,7 +1,6 @@ package service import ( - "fmt" "time" msg_pb "github.com/harmony-one/harmony/api/proto/message" @@ -142,13 +141,10 @@ func (m *Manager) TakeAction(action *Action) { if service, ok := m.services[action.ServiceType]; ok { switch action.Action { case Start: - fmt.Printf("Start %s\n", action.ServiceType) service.StartService() case Stop: - fmt.Printf("Stop %s\n", action.ServiceType) service.StopService() case Notify: - fmt.Printf("Notify %s\n", action.ServiceType) service.NotifyService(action.Params) } } diff --git a/cmd/client/wallet/lib/lib.go b/cmd/client/wallet/lib/lib.go index 8991f617d..063334d33 100644 --- a/cmd/client/wallet/lib/lib.go +++ b/cmd/client/wallet/lib/lib.go @@ -47,6 +47,7 @@ func GetPeersFromBeaconChain(walletNode *node.Node) []p2p.Peer { peers = append(peers, v.(p2p.Peer)) return true }) + utils.GetLogInstance().Debug("GetPeersFromBeaconChain", "peers:", peers) return peers } @@ -59,8 +60,8 @@ func SubmitTransaction(tx *types.Transaction, walletNode *node.Node, shardID uin } func getBootNodes() []ma.Multiaddr { - addrStrings := []string{"/ip4/127.0.0.1/tcp/19876/p2p/QmbTLMb9C8dmjrDYoiJb2mayXspcURkNB4ARxgsoA5Aoe3"} //addrStrings := []string{"/ip4/54.213.43.194/tcp/9874/p2p/QmQhPRqqfTRExqWmTifjMaBvRd3HBmnmj9jYAvTy6HPPJj"} + addrStrings := []string{"/ip4/100.26.90.187/tcp/9871/p2p/QmPH2XsLP88jpfejHycQRWB7vDjwDju9qT9rMmdNaNea5v", "/ip4/54.213.43.194/tcp/9871/p2p/QmQLjTciaJppXVPZFoj4gTdME5axzTxtVwty5Lg8kwt6Zs"} bootNodeAddrs, err := utils.StringsToAddrs(addrStrings) if err != nil { panic(err) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index 8d2f14654..fbb5fa3d4 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -15,7 +15,8 @@ import ( "github.com/ethereum/go-ethereum/common" crypto2 "github.com/ethereum/go-ethereum/crypto" - "github.com/ethereum/go-ethereum/log" + + // "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" clientService "github.com/harmony-one/harmony/api/client/service" "github.com/harmony-one/harmony/cmd/client/wallet/lib" @@ -63,8 +64,9 @@ var ( // The main wallet program entrance. Note the this wallet program is for demo-purpose only. It does not implement // the secure storage of keys. func main() { - h := log.StreamHandler(os.Stdout, log.TerminalFormat(false)) - log.Root().SetHandler(h) + // disable logging for wallet + // h := log.StreamHandler(os.Stdout, log.TerminalFormat(false)) + // log.Root().SetHandler(h) // Verify that a subcommand has been provided // os.Arg[0] is the main command From cecf53ae0e8d98e4b4039708d5e996d0a3d6b124 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Wed, 13 Mar 2019 22:02:21 +0000 Subject: [PATCH 2/2] [wallet] enable logging using the --verbose flag at the end For Example: wallet balances --verbose This patch fixes two panic when wallet can't connect to bootnode. Signed-off-by: Leo Chen --- cmd/client/wallet/main.go | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index fbb5fa3d4..a167913b5 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -16,7 +16,7 @@ import ( "github.com/ethereum/go-ethereum/common" crypto2 "github.com/ethereum/go-ethereum/crypto" - // "github.com/ethereum/go-ethereum/log" + "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" clientService "github.com/harmony-one/harmony/api/client/service" "github.com/harmony-one/harmony/cmd/client/wallet/lib" @@ -61,12 +61,16 @@ var ( balanceAddressPtr = balanceCommand.String("address", "", "Specify the account address to check balance for") ) +// setupLog setup log for verbose output +func setupLog() { + // enable logging for wallet + h := log.StreamHandler(os.Stdout, log.TerminalFormat(false)) + log.Root().SetHandler(h) +} + // The main wallet program entrance. Note the this wallet program is for demo-purpose only. It does not implement // the secure storage of keys. func main() { - // disable logging for wallet - // h := log.StreamHandler(os.Stdout, log.TerminalFormat(false)) - // log.Root().SetHandler(h) // Verify that a subcommand has been provided // os.Arg[0] is the main command @@ -92,6 +96,12 @@ func main() { os.Exit(1) } + // Enable log if the last parameter is -verbose + if os.Args[len(os.Args)-1] == "--verbose" { + setupLog() + os.Args = os.Args[:len(os.Args)-1] + } + // Switch on the subcommand switch os.Args[1] { case "-version": @@ -312,7 +322,10 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string { func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]AccountState { result := make(map[uint32]AccountState) peers := lib.GetPeersFromBeaconChain(walletNode) - + if len(peers) == 0 { + fmt.Printf("[FATAL] Can't find peers\n") + return nil + } peer := peers[0] port, _ := strconv.Atoi(peer.Port) client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff)) @@ -326,6 +339,10 @@ func FetchBalance(address common.Address, walletNode *node.Node) map[uint32]Acco // GetFreeToken requests for token test token on each shard func GetFreeToken(address common.Address, walletNode *node.Node) { peers := lib.GetPeersFromBeaconChain(walletNode) + if len(peers) == 0 { + fmt.Printf("[FATAL] Can't find peers\n") + return + } peer := peers[0] port, _ := strconv.Atoi(peer.Port) client := clientService.NewClient(peer.IP, strconv.Itoa(port+node.ClientServicePortDiff))