|
|
@ -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,38 +439,44 @@ 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) |
|
|
|
response, err := client.GetFreeToken(address) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
for retry := 0; retry < rpcRetry; retry++ { |
|
|
|
log.Info("failed to get free token, retrying ...") |
|
|
|
response, err := client.GetFreeToken(address) |
|
|
|
continue |
|
|
|
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 |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|