remove debug info

This commit is contained in:
AnilChinchawale 2018-12-04 12:27:26 +05:30
parent 2b7010d51f
commit 87896dcdf9
3 changed files with 1 additions and 71 deletions

View file

@ -1,13 +1,7 @@
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"
)
@ -17,13 +11,9 @@ var (
"blockSigners": 0,
"blocks": 1,
}
ParsedBlockSignerABI, _ = abi.JSON(strings.NewReader(blockSignerContract.BlockSignerABI))
)
func GetSigners(statedb *state.StateDB, 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)
@ -37,10 +27,7 @@ func GetSigners(statedb *state.StateDB, block *types.Block) []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

@ -1,13 +1,7 @@
package contracts
import (
"fmt"
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
randomizeContract "github.com/ethereum/go-ethereum/contracts/randomize/contract"
"github.com/ethereum/go-ethereum/core/state"
)
@ -16,17 +10,12 @@ var (
"randomSecret": 0,
"randomOpening": 1,
}
ParsedRandomizeABI, _ = abi.JSON(strings.NewReader(randomizeContract.XDCRandomizeABI))
)
func GetSecret(statedb *state.StateDB, address common.Address) [][32]byte {
start := time.Now()
fmt.Printf("--------GetSecret---------\n")
slot := slotRandomizeMapping["randomSecret"]
locSecret := getLocMappingAtKey(address.Hash(), slot)
arrLength := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locSecret))
fmt.Printf("Secret length: %v\n", arrLength.Hex())
keys := []common.Hash{}
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
key := getLocDynamicArrAtElement(common.BigToHash(locSecret), i, 1)
@ -36,23 +25,13 @@ func GetSecret(statedb *state.StateDB, address common.Address) [][32]byte {
for _, key := range keys {
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), key)
rets = append(rets, ret)
fmt.Printf("ret hex: %v - ret byte: %v\n", ret.Hex(), ret.Bytes())
}
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return rets
}
func GetOpening(statedb *state.StateDB, address common.Address) [32]byte {
start := time.Now()
fmt.Printf("--------GetOpening---------\n")
slot := slotRandomizeMapping["randomOpening"]
locOpening := getLocMappingAtKey(address.Hash(), slot)
ret := statedb.GetState(common.HexToAddress(common.RandomizeSMC), common.BigToHash(locOpening))
fmt.Printf("ret hex: %v - ret byte: %v\n", ret.Hex(), ret.Bytes())
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return ret
}

View file

@ -1,20 +1,15 @@
package contracts
import (
"fmt"
"math/big"
"strings"
"time"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
validatorContract "github.com/ethereum/go-ethereum/contracts/validator/contract"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/crypto"
)
var (
ParsedValidatorABI, _ = abi.JSON(strings.NewReader(validatorContract.XDCValidatorABI))
slotValidatorMapping = map[string]uint64{
"withdrawsState": 0,
"validatorsState": 1,
@ -29,12 +24,10 @@ var (
}
)
func GetCandidates(statedb *state.StateDB, parsed abi.ABI) []common.Address {
start := time.Now()
func GetCandidates(statedb *state.StateDB) []common.Address {
slot := slotValidatorMapping["candidates"]
slotHash := common.BigToHash(new(big.Int).SetUint64(slot))
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), slotHash)
fmt.Printf("Candidates length: %v\n", arrLength.Hex())
keys := []common.Hash{}
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
key := getLocDynamicArrAtElement(slotHash, i, 1)
@ -44,53 +37,33 @@ func GetCandidates(statedb *state.StateDB, parsed abi.ABI) []common.Address {
for _, key := range keys {
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), 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
}
func GetCandidateOwner(statedb *state.StateDB, 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: %v\n", common.HexToAddress(ret.Hex()).Hex())
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return common.HexToAddress(ret.Hex())
}
func GetCandidateCap(statedb *state.StateDB, parsed abi.ABI, candidate common.Address) string {
start := time.Now()
slot := slotValidatorMapping["validatorsState"]
// validatorsState[_candidate].cap;
locValidatorsState := getLocMappingAtKey(candidate.Hash(), slot)
locCandidateCap := locValidatorsState.Add(locValidatorsState, new(big.Int).SetUint64(uint64(1)))
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locCandidateCap))
fmt.Printf("ret hex: %v\n", ret.Hex())
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return ret.Hex()
}
func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Address {
start := time.Now()
fmt.Printf("--------GetVoters---------\n")
//mapping(address => address[]) voters;
slot := slotValidatorMapping["voters"]
locVoters := getLocMappingAtKey(candidate.Hash(), slot)
arrLength := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BigToHash(locVoters))
fmt.Printf("Voters length: %v\n", arrLength.Hex())
keys := []common.Hash{}
for i := uint64(0); i < arrLength.Big().Uint64(); i++ {
key := getLocDynamicArrAtElement(common.BigToHash(locVoters), i, 1)
@ -100,25 +73,16 @@ func GetVoters(statedb *state.StateDB, candidate common.Address) []common.Addres
for _, key := range keys {
ret := statedb.GetState(common.HexToAddress(common.MasternodeVotingSMC), 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
}
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(2)))
retByte := crypto.Keccak256(voter.Hash().Bytes(), common.BigToHash(locCandidateVoters).Bytes())
ret := state.GetState(common.HexToAddress(common.MasternodeVotingSMC), common.BytesToHash(retByte))
fmt.Printf("voter: %v - cap: %v\n", voter.Hex(), ret.Big().String())
elapsed := time.Since(start)
fmt.Printf("Execution time: %s\n", elapsed)
return ret.Big()
}