From dc113de26d59d3a545b042d23dc2df16c8a8c0ea Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 8 Apr 2019 21:29:43 +0000 Subject: [PATCH 1/2] [wallet] fix fetch balance error it should display the right balance even though some shard may not be available. Signed-off-by: Leo Chen --- cmd/client/wallet/main.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index e23bd04fa..50adb0db0 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -422,8 +422,10 @@ func convertBalanceIntoReadableFormat(balance *big.Int) string { // FetchBalance fetches account balance of specified address from the Harmony network func FetchBalance(address common.Address) map[uint32]AccountState { result := make(map[uint32]AccountState) - balance := big.NewInt(0) for i := 0; i < walletProfile.Shards; i++ { + balance := big.NewInt(0) + var nonce uint64 + result[uint32(i)] = AccountState{balance, 0} for retry := 0; retry < rpcRetry; retry++ { @@ -441,9 +443,10 @@ func FetchBalance(address common.Address) map[uint32]AccountState { } log.Debug("FetchBalance", "response", response) balance.SetBytes(response.Balance) - result[uint32(i)] = AccountState{balance, response.Nonce} + nonce = response.Nonce break } + result[uint32(i)] = AccountState{balance, nonce} } return result } From 147ce51a769358a1a0ae669d0a706635674e7953 Mon Sep 17 00:00:00 2001 From: Leo Chen Date: Mon, 8 Apr 2019 22:28:48 +0000 Subject: [PATCH 2/2] [wallet] send getFreeToken calls to all shards Signed-off-by: Leo Chen --- cmd/client/wallet/main.go | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/cmd/client/wallet/main.go b/cmd/client/wallet/main.go index 50adb0db0..388ac0d1f 100644 --- a/cmd/client/wallet/main.go +++ b/cmd/client/wallet/main.go @@ -439,6 +439,7 @@ func FetchBalance(address common.Address) map[uint32]AccountState { response, err := client.GetBalance(address) if err != nil { log.Info("failed to get balance, retrying ...") + time.Sleep(200 * time.Millisecond) continue } log.Debug("FetchBalance", "response", response) @@ -453,25 +454,29 @@ func FetchBalance(address common.Address) map[uint32]AccountState { // GetFreeToken requests for token test token on each shard func GetFreeToken(address common.Address) { - for retry := 0; retry < rpcRetry; retry++ { - // use the 1st server from shard 0 (beacon chain) to make the getFreeToken call - server := walletProfile.RPCServer[0][0] + for i := 0; i < walletProfile.Shards; i++ { + // use the 1st server (leader) to make the getFreeToken call + server := walletProfile.RPCServer[i][0] client, err := clientService.NewClient(server.IP, server.Port) if err != nil { continue } log.Debug("GetFreeToken", "server", server) - response, err := client.GetFreeToken(address) - if err != nil { - log.Info("failed to get free token, retrying ...") - continue + + for retry := 0; retry < rpcRetry; retry++ { + response, err := client.GetFreeToken(address) + if err != nil { + log.Info("failed to get free token, retrying ...") + time.Sleep(200 * time.Millisecond) + continue + } + log.Debug("GetFreeToken", "response", response) + txID := common.Hash{} + txID.SetBytes(response.TxId) + fmt.Printf("Transaction Id requesting free token in shard %d: %s\n", int(0), txID.Hex()) + break } - log.Debug("GetFreeToken", "response", response) - txID := common.Hash{} - txID.SetBytes(response.TxId) - fmt.Printf("Transaction Id requesting free token in shard %d: %s\n", int(0), txID.Hex()) - break } }