mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
add GetVoterCap func
This commit is contained in:
parent
237111a5ba
commit
b7306c639e
2 changed files with 15 additions and 6 deletions
|
|
@ -385,12 +385,7 @@ func GetRewardBalancesRate(foundationWalletAddr common.Address, state *state.Sta
|
||||||
// Get voters capacities.
|
// Get voters capacities.
|
||||||
voterCaps := make(map[common.Address]*big.Int)
|
voterCaps := make(map[common.Address]*big.Int)
|
||||||
for _, voteAddr := range voters {
|
for _, voteAddr := range voters {
|
||||||
voterCap, err := GetVoterCap(state, masterAddr, voteAddr)
|
voterCap := GetVoterCap(state, masterAddr, voteAddr)
|
||||||
if err != nil {
|
|
||||||
log.Error("Fail to get vote capacity", "error", err)
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
totalCap.Add(totalCap, voterCap)
|
totalCap.Add(totalCap, voterCap)
|
||||||
voterCaps[voteAddr] = voterCap
|
voterCaps[voteAddr] = voterCap
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,3 +106,17 @@ func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Addres
|
||||||
fmt.Printf("Execution time: %s\n", elapsed)
|
fmt.Printf("Execution time: %s\n", elapsed)
|
||||||
return rets
|
return rets
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetVoterCap(state *state.StateDB, candidate, voter common.Address) *big.Int {
|
||||||
|
//validatorsState[_candidate].voters[_voter]
|
||||||
|
start := time.Now()
|
||||||
|
fmt.Printf("--------GetVoterCap---------\n")
|
||||||
|
slot := slotValidatorMapping["validatorsState"]
|
||||||
|
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
|
||||||
|
locCandidateVoters := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(3)))
|
||||||
|
locVoters := getLocMappingAtKey(voter.Hash(), locCandidateVoters.Uint64())
|
||||||
|
ret := state.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locVoters))
|
||||||
|
elapsed := time.Since(start)
|
||||||
|
fmt.Printf("Execution time: %s\n", elapsed)
|
||||||
|
return ret.Big()
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue