[rpc] hex address GetValidatorsStakeByBlockNumber (#4256)

pull/4258/head
Max 2 years ago committed by GitHub
parent c022075771
commit 3cdd9cfab3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      hmy/staking.go

@ -229,12 +229,12 @@ func (hmy *Harmony) GetAllValidatorAddresses() []common.Address {
func (hmy *Harmony) GetValidatorsStakeByBlockNumber( func (hmy *Harmony) GetValidatorsStakeByBlockNumber(
block *types.Block, block *types.Block,
) (map[common.Address]*big.Int, error) { ) (map[string]*big.Int, error) {
if cachedReward, ok := hmy.stakeByBlockNumberCache.Get(block.Hash()); ok { if cachedReward, ok := hmy.stakeByBlockNumberCache.Get(block.Hash()); ok {
return cachedReward.(map[common.Address]*big.Int), nil return cachedReward.(map[string]*big.Int), nil
} }
validatorAddresses := hmy.GetAllValidatorAddresses() validatorAddresses := hmy.GetAllValidatorAddresses()
stakes := make(map[common.Address]*big.Int, len(validatorAddresses)) stakes := make(map[string]*big.Int, len(validatorAddresses))
for _, validatorAddress := range validatorAddresses { for _, validatorAddress := range validatorAddresses {
wrapper, err := hmy.BlockChain.ReadValidatorInformationAtRoot(validatorAddress, block.Root()) wrapper, err := hmy.BlockChain.ReadValidatorInformationAtRoot(validatorAddress, block.Root())
if err != nil { if err != nil {
@ -250,7 +250,7 @@ func (hmy *Harmony) GetValidatorsStakeByBlockNumber(
continue continue
} }
} }
stakes[validatorAddress] = wrapper.TotalDelegation() stakes[validatorAddress.Hex()] = wrapper.TotalDelegation()
} }
hmy.stakeByBlockNumberCache.Add(block.Hash(), stakes) hmy.stakeByBlockNumberCache.Add(block.Hash(), stakes)
return stakes, nil return stakes, nil

Loading…
Cancel
Save