add GetVoterCap func

This commit is contained in:
AnilChinchawale 2018-12-02 11:30:04 +05:30
parent 8a456132e5
commit b10d8170c7

View file

@ -105,4 +105,18 @@ func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Addres
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
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()
}