Merge pull request #697 from LeoHChen/wallet_fix_on_multi_shards

Wallet fix on multi shards
pull/704/head
Leo Chen 6 years ago committed by GitHub
commit 3608611399
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      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 // FetchBalance fetches account balance of specified address from the Harmony network
func FetchBalance(address common.Address) map[uint32]AccountState { func FetchBalance(address common.Address) map[uint32]AccountState {
result := make(map[uint32]AccountState) result := make(map[uint32]AccountState)
balance := big.NewInt(0)
for i := 0; i < walletProfile.Shards; i++ { for i := 0; i < walletProfile.Shards; i++ {
balance := big.NewInt(0)
var nonce uint64
result[uint32(i)] = AccountState{balance, 0} result[uint32(i)] = AccountState{balance, 0}
for retry := 0; retry < rpcRetry; retry++ { for retry := 0; retry < rpcRetry; retry++ {
@ -437,31 +439,36 @@ func FetchBalance(address common.Address) map[uint32]AccountState {
response, err := client.GetBalance(address) response, err := client.GetBalance(address)
if err != nil { if err != nil {
log.Info("failed to get balance, retrying ...") log.Info("failed to get balance, retrying ...")
time.Sleep(200 * time.Millisecond)
continue continue
} }
log.Debug("FetchBalance", "response", response) log.Debug("FetchBalance", "response", response)
balance.SetBytes(response.Balance) balance.SetBytes(response.Balance)
result[uint32(i)] = AccountState{balance, response.Nonce} nonce = response.Nonce
break break
} }
result[uint32(i)] = AccountState{balance, nonce}
} }
return result return result
} }
// GetFreeToken requests for token test token on each shard // GetFreeToken requests for token test token on each shard
func GetFreeToken(address common.Address) { func GetFreeToken(address common.Address) {
for retry := 0; retry < rpcRetry; retry++ { for i := 0; i < walletProfile.Shards; i++ {
// use the 1st server from shard 0 (beacon chain) to make the getFreeToken call // use the 1st server (leader) to make the getFreeToken call
server := walletProfile.RPCServer[0][0] server := walletProfile.RPCServer[i][0]
client, err := clientService.NewClient(server.IP, server.Port) client, err := clientService.NewClient(server.IP, server.Port)
if err != nil { if err != nil {
continue continue
} }
log.Debug("GetFreeToken", "server", server) log.Debug("GetFreeToken", "server", server)
for retry := 0; retry < rpcRetry; retry++ {
response, err := client.GetFreeToken(address) response, err := client.GetFreeToken(address)
if err != nil { if err != nil {
log.Info("failed to get free token, retrying ...") log.Info("failed to get free token, retrying ...")
time.Sleep(200 * time.Millisecond)
continue continue
} }
log.Debug("GetFreeToken", "response", response) log.Debug("GetFreeToken", "response", response)
@ -471,6 +478,7 @@ func GetFreeToken(address common.Address) {
break break
} }
} }
}
// ReadAddresses reads the addresses stored in local keystore // ReadAddresses reads the addresses stored in local keystore
func ReadAddresses() []common.Address { func ReadAddresses() []common.Address {

Loading…
Cancel
Save