Apply suggestions from code review

Accept error handling suggestions.

Co-Authored-By: Eugene Kim <ek@harmony.one>
pull/1903/head
Rongjian Lan 5 years ago committed by GitHub
parent 8e9dac2831
commit b273ab0e35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      hmy/api_backend.go
  2. 2
      internal/hmyapi/backend.go
  3. 6
      internal/hmyapi/blockchain.go

@ -364,10 +364,10 @@ func (b *APIBackend) GetValidatorSelfDelegation(addr common.Address) *big.Int {
}
// GetShardState ...
func (b *APIBackend) GetShardState() *shard.State {
func (b *APIBackend) GetShardState() (shard.State, error) {
state, err := b.hmy.BlockChain().ReadShardState(b.hmy.BlockChain().CurrentHeader().Epoch())
if err != nil {
return &shard.State{}
return nil, errors.Wrapf(err, "cannot read from DB")
}
return &state
return state, nil
}

@ -80,7 +80,7 @@ type Backend interface {
GetDelegationsByValidator(validator common.Address) []*staking.Delegation
GetDelegationsByDelegator(delegator common.Address) ([]common.Address, []*staking.Delegation)
GetValidatorSelfDelegation(addr common.Address) *big.Int
GetShardState() *shard.State
GetShardState() (shard.State, error)
}
// GetAPIs returns all the APIs.

@ -518,11 +518,11 @@ func (s *PublicBlockChainAPI) GetValidatorInformation(ctx context.Context, addre
rpcValidator.TotalEffectiveStake = stats.TotalEffectiveStake.String()
}
shardState := s.b.GetShardState()
if shardState != nil {
shardState, err := s.b.GetShardState()
if err == nil {
blsKeyToShardID := make(map[shard.BlsPublicKey]uint32)
for _, committee := range *shardState {
for _, committee := range shardState {
for _, slot := range committee.Slots {
blsKeyToShardID[slot.BlsPublicKey] = committee.ShardID
}

Loading…
Cancel
Save