|
|
@ -278,37 +278,52 @@ func (s *Service) GetCommittee(w http.ResponseWriter, r *http.Request) { |
|
|
|
shardID, err = strconv.ParseUint(shardIDRead, 10, 32) |
|
|
|
shardID, err = strconv.ParseUint(shardIDRead, 10, 32) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read shard id") |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read shard id") |
|
|
|
|
|
|
|
w.WriteHeader(400) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if epochRead != "" { |
|
|
|
if epochRead != "" { |
|
|
|
epoch, err = strconv.ParseUint(epochRead, 10, 64) |
|
|
|
epoch, err = strconv.ParseUint(epochRead, 10, 64) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read shard epoch") |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read shard epoch") |
|
|
|
|
|
|
|
w.WriteHeader(400) |
|
|
|
|
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if s.ShardID != uint32(shardID) { |
|
|
|
if s.ShardID != uint32(shardID) { |
|
|
|
utils.Logger().Warn().Err(err).Msg("incorrect shard id") |
|
|
|
utils.Logger().Warn().Msg("incorrect shard id") |
|
|
|
|
|
|
|
w.WriteHeader(400) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
db := s.storage.GetDB() |
|
|
|
db := s.storage.GetDB() |
|
|
|
bytes, err := db.Get([]byte(GetCommitteeKey(uint32(shardID), epoch))) |
|
|
|
bytes, err := db.Get([]byte(GetCommitteeKey(uint32(shardID), epoch))) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read committee") |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot read committee") |
|
|
|
|
|
|
|
w.WriteHeader(500) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
committee := &types.Committee{} |
|
|
|
committee := &types.Committee{} |
|
|
|
if rlp.DecodeBytes(bytes, committee) != nil { |
|
|
|
if err := rlp.DecodeBytes(bytes, committee); err != nil { |
|
|
|
utils.Logger().Warn().Msg("cannot convert data from DB") |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot decode committee data from DB") |
|
|
|
|
|
|
|
w.WriteHeader(500) |
|
|
|
return |
|
|
|
return |
|
|
|
} |
|
|
|
} |
|
|
|
validators := &Committee{} |
|
|
|
validators := &Committee{} |
|
|
|
for _, validator := range committee.NodeList { |
|
|
|
for _, validator := range committee.NodeList { |
|
|
|
validatorStake := big.NewInt(0) |
|
|
|
validatorBalance := big.NewInt(0) |
|
|
|
validatorStake, err = s.GetAccountBalance(validator.EcdsaAddress) |
|
|
|
validatorBalance, err := s.GetAccountBalance(validator.EcdsaAddress) |
|
|
|
validators.Validators = append(validators.Validators, &Validator{Address: common2.MustAddressToBech32(validator.EcdsaAddress), Stake: validatorStake}) |
|
|
|
if err != nil { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
oneAddress, err := common2.AddressToBech32(validator.EcdsaAddress) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
validators.Validators = append(validators.Validators, &Validator{Address: oneAddress, Balance: validatorBalance}) |
|
|
|
} |
|
|
|
} |
|
|
|
if err := json.NewEncoder(w).Encode(validators); err != nil { |
|
|
|
if err := json.NewEncoder(w).Encode(validators); err != nil { |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot JSON-encode committee") |
|
|
|
utils.Logger().Warn().Err(err).Msg("cannot JSON-encode committee") |
|
|
|
|
|
|
|
w.WriteHeader(500) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|