Merge pull request #1951 from rlan35/staking_final_final

Use one1 address for staking rpcs.
pull/1955/head
Rongjian Lan 5 years ago committed by GitHub
commit 490804fa84
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 36
      internal/hmyapi/blockchain.go
  2. 9
      internal/hmyapi/types.go

@ -492,13 +492,23 @@ func (s *PublicBlockChainAPI) LatestHeader(ctx context.Context) *HeaderInformati
} }
// GetAllValidatorAddresses returns all validator addresses. // GetAllValidatorAddresses returns all validator addresses.
func (s *PublicBlockChainAPI) GetAllValidatorAddresses() ([]common.Address, error) { func (s *PublicBlockChainAPI) GetAllValidatorAddresses() ([]string, error) {
return s.b.GetAllValidatorAddresses(), nil addresses := []string{}
for _, addr := range s.b.GetAllValidatorAddresses() {
oneAddr, _ := internal_common.AddressToBech32(addr)
addresses = append(addresses, oneAddr)
}
return addresses, nil
} }
// GetActiveValidatorAddresses returns active validator addresses. // GetActiveValidatorAddresses returns active validator addresses.
func (s *PublicBlockChainAPI) GetActiveValidatorAddresses() ([]common.Address, error) { func (s *PublicBlockChainAPI) GetActiveValidatorAddresses() ([]string, error) {
return s.b.GetActiveValidatorAddresses(), nil addresses := []string{}
for _, addr := range s.b.GetActiveValidatorAddresses() {
oneAddr, _ := internal_common.AddressToBech32(addr)
addresses = append(addresses, oneAddr)
}
return addresses, nil
} }
// GetValidatorInformation returns information about a validator. // GetValidatorInformation returns information about a validator.
@ -562,9 +572,11 @@ func (s *PublicBlockChainAPI) GetDelegationsByDelegator(ctx context.Context, add
delegation.Undelegations[j].Epoch, delegation.Undelegations[j].Epoch,
}) })
} }
valAddr, _ := internal_common.AddressToBech32(validators[i])
delAddr, _ := internal_common.AddressToBech32(delegatorAddress)
result = append(result, &RPCDelegation{ result = append(result, &RPCDelegation{
validators[i], valAddr,
delegatorAddress, delAddr,
delegation.Amount, delegation.Amount,
delegation.Reward, delegation.Reward,
undelegations, undelegations,
@ -588,9 +600,11 @@ func (s *PublicBlockChainAPI) GetDelegationsByValidator(ctx context.Context, add
delegation.Undelegations[j].Epoch, delegation.Undelegations[j].Epoch,
}) })
} }
valAddr, _ := internal_common.AddressToBech32(validatorAddress)
delAddr, _ := internal_common.AddressToBech32(delegation.DelegatorAddress)
result = append(result, &RPCDelegation{ result = append(result, &RPCDelegation{
validatorAddress, valAddr,
delegation.DelegatorAddress, delAddr,
delegation.Amount, delegation.Amount,
delegation.Reward, delegation.Reward,
undelegations, undelegations,
@ -618,9 +632,11 @@ func (s *PublicBlockChainAPI) GetDelegationByDelegatorAndValidator(ctx context.C
delegation.Undelegations[j].Epoch, delegation.Undelegations[j].Epoch,
}) })
} }
valAddr, _ := internal_common.AddressToBech32(validatorAddress)
delAddr, _ := internal_common.AddressToBech32(delegatorAddress)
return &RPCDelegation{ return &RPCDelegation{
validatorAddress, valAddr,
delegatorAddress, delAddr,
delegation.Amount, delegation.Amount,
delegation.Reward, delegation.Reward,
undelegations, undelegations,

@ -83,7 +83,7 @@ type HeaderInformation struct {
// RPCValidator represents a validator // RPCValidator represents a validator
type RPCValidator struct { type RPCValidator struct {
Address common.Address `json:"address"` Address string `json:"address"`
SlotPubKeys []shard.BlsPublicKey `json:"slot_pub_keys"` SlotPubKeys []shard.BlsPublicKey `json:"slot_pub_keys"`
SlotShardIDs []int `json:"slot_shard_ids"` SlotShardIDs []int `json:"slot_shard_ids"`
UnbondingHeight *big.Int `json:"unbonding_height"` UnbondingHeight *big.Int `json:"unbonding_height"`
@ -100,8 +100,8 @@ type RPCValidator struct {
// RPCDelegation represents a particular delegation to a validator // RPCDelegation represents a particular delegation to a validator
type RPCDelegation struct { type RPCDelegation struct {
ValidatorAddress common.Address `json:"validator_address" yaml:"validator_address"` ValidatorAddress string `json:"validator_address" yaml:"validator_address"`
DelegatorAddress common.Address `json:"delegator_address" yaml:"delegator_address"` DelegatorAddress string `json:"delegator_address" yaml:"delegator_address"`
Amount *big.Int `json:"amount" yaml:"amount"` Amount *big.Int `json:"amount" yaml:"amount"`
Reward *big.Int `json:"reward" yaml:"reward"` Reward *big.Int `json:"reward" yaml:"reward"`
Undelegations []RPCUndelegation `json:"Undelegations" yaml:"Undelegations"` Undelegations []RPCUndelegation `json:"Undelegations" yaml:"Undelegations"`
@ -172,8 +172,9 @@ func newRPCCXReceipt(cx *types.CXReceipt, blockHash common.Hash, blockNumber uin
} }
func newRPCValidator(validator *types2.Validator) *RPCValidator { func newRPCValidator(validator *types2.Validator) *RPCValidator {
addr, _ := internal_common.AddressToBech32(validator.Address)
return &RPCValidator{ return &RPCValidator{
validator.Address, addr,
validator.SlotPubKeys, validator.SlotPubKeys,
nil, nil,
validator.UnbondingHeight, validator.UnbondingHeight,

Loading…
Cancel
Save