update blocksigner(smc) reader

This commit is contained in:
parmarrushabh 2018-12-02 11:10:48 +05:30
parent 3cf363ea27
commit 271cab95a4
2 changed files with 49 additions and 1 deletions

View file

@ -0,0 +1,46 @@
package contracts
import (
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
blockSignerContract "github.com/ethereum/go-ethereum/contracts/blocksigner/contract"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
)
var (
slotBlockSignerMapping = map[string]uint64{
"blockSigners": 0,
"blocks": 1,
}
ParsedBlockSignerABI, _ = abi.JSON(strings.NewReader(blockSignerContract.BlockSignerABI))
)
func GetSigners(statedb *state.StateDB, parsed abi.ABI, block *types.Block) []common.Address {
methodName := "getSigners"
fmt.Printf("---%s---\n", methodName)
start := time.Now()
slot := slotBlockSignerMapping["blockSigners"]
keys := []common.Hash{}
keyArrSlot := getLocMappingAtKey(block.Hash(), slot)
arrSlot := statedb.GetState(common.HexToAddress(common.BlockSigners), common.BigToHash(keyArrSlot))
arrLength := arrSlot.Big().Uint64()
for i := uint64(0); i < arrLength; i++ {
key := getLocDynamicArrAtElement(common.BigToHash(keyArrSlot), i, 1)
keys = append(keys, key)
}
rets := []common.Address{}
for _, key := range keys {
ret := statedb.GetState(common.HexToAddress(common.BlockSigners), key)
rets = append(rets, common.HexToAddress(ret.Hex()))
fmt.Printf("%v\n", common.HexToAddress(ret.Hex()).Hex())
}
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return rets
}

View file

@ -52,13 +52,14 @@ func GetCandidates(statedb *state.StateDB, parsed abi.ABI) []common.Address {
func GetCandidateOwner(statedb *state.StateDB, parsed abi.ABI, candidate common.Address) common.Address {
start := time.Now()
fmt.Printf("--------GetCandidateOwner---------\n")
slot := slotValidatorMapping["validatorsState"]
// validatorsState[_candidate].owner;
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
locCandidateOwner := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(0)))
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateOwner))
fmt.Printf("ret hex: %v\n", ret.Hex())
fmt.Printf("ret: %v\n", common.HexToAddress(ret.Hex()).Hex())
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
@ -82,6 +83,7 @@ func GetCandidateCap(statedb *state.StateDB, parsed abi.ABI, candidate common.Ad
func GetVoters(statedb *state.StateDB, parsed abi.ABI, candidate common.Address) []common.Address {
start := time.Now()
fmt.Printf("--------GetVoters---------\n")
//mapping(address => address[]) voters;
slot := slotValidatorMapping["voters"]