Merge pull request #1871 from flicker-harmony/pr_oneaddress_support

One address support where its missing
pull/1872/head
Rongjian Lan 5 years ago committed by GitHub
commit a9218b2daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      internal/hmyapi/blockchain.go

@ -500,16 +500,17 @@ func (s *PublicBlockChainAPI) GetActiveValidatorAddresses() ([]common.Address, e
return s.b.GetActiveValidatorAddresses(), nil return s.b.GetActiveValidatorAddresses(), nil
} }
// GetValidatorInfo returns information about a validator. // GetValidatorInformation returns information about a validator.
func (s *PublicBlockChainAPI) GetValidatorInfo(ctx context.Context, address common.Address) (*RPCValidator, error) { func (s *PublicBlockChainAPI) GetValidatorInformation(ctx context.Context, address string) (*RPCValidator, error) {
validator := s.b.GetValidatorInformation(address) validatorAddress := internal_common.ParseAddr(address)
validator := s.b.GetValidatorInformation(validatorAddress)
if validator == nil { if validator == nil {
return nil, fmt.Errorf("validator not found: %s", address.Hex()) return nil, fmt.Errorf("validator not found: %s", validatorAddress.Hex())
} }
rpcValidator := newRPCValidator(validator) rpcValidator := newRPCValidator(validator)
stats := s.b.GetValidatorStats(address) stats := s.b.GetValidatorStats(validatorAddress)
if stats != nil { if stats != nil {
rpcValidator.Uptime = numeric.NewDecFromBigInt(stats.NumBlocksSigned).Quo(numeric.NewDecFromBigInt(stats.NumBlocksToSign)).String() rpcValidator.Uptime = numeric.NewDecFromBigInt(stats.NumBlocksSigned).Quo(numeric.NewDecFromBigInt(stats.NumBlocksToSign)).String()
@ -518,8 +519,9 @@ func (s *PublicBlockChainAPI) GetValidatorInfo(ctx context.Context, address comm
} }
// GetDelegationsByDelegator returns information about a validator. // GetDelegationsByDelegator returns information about a validator.
func (s *PublicBlockChainAPI) GetDelegationsByDelegator(ctx context.Context, address common.Address) ([]*RPCDelegation, error) { func (s *PublicBlockChainAPI) GetDelegationsByDelegator(ctx context.Context, address string) ([]*RPCDelegation, error) {
validators, delegations := s.b.GetDelegationsByDelegator(address) validatorAddress := internal_common.ParseAddr(address)
validators, delegations := s.b.GetDelegationsByDelegator(validatorAddress)
result := []*RPCDelegation{} result := []*RPCDelegation{}
for i := range delegations { for i := range delegations {
delegation := delegations[i] delegation := delegations[i]
@ -534,13 +536,12 @@ func (s *PublicBlockChainAPI) GetDelegationsByDelegator(ctx context.Context, add
} }
result = append(result, &RPCDelegation{ result = append(result, &RPCDelegation{
validators[i], validators[i],
address, validatorAddress,
delegation.Amount, delegation.Amount,
delegation.Reward, delegation.Reward,
undelegations, undelegations,
}) })
} }
return result, nil return result, nil
} }

Loading…
Cancel
Save