Public func

This commit is contained in:
denis k 2018-08-22 17:33:45 +10:00
parent e232ba43a3
commit 507ef74a91

View file

@ -5,12 +5,12 @@ import (
"errors"
"fmt"
"encoding/binary"
"github.com/pavelkrolevets/go-ethereum/common"
"github.com/pavelkrolevets/go-ethereum/crypto/sha3"
"github.com/pavelkrolevets/go-ethereum/ethdb"
"github.com/pavelkrolevets/go-ethereum/rlp"
"github.com/pavelkrolevets/go-ethereum/trie"
"encoding/binary"
"github.com/pavelkrolevets/go-ethereum/ethdb"
)
type LCPContext struct {
@ -174,9 +174,9 @@ func (d *LCPContext) Copy() *LCPContext {
voteTrie := *d.voteTrie
candidateTrie := *d.candidateTrie
mintCntTrie := *d.mintCntTrie
periodTrie:= *d.periodBlock
maxValidatorTrie:= *d.maxValidators
epochIntervalTrie:= *d.epochInterval
periodTrie := *d.periodBlock
maxValidatorTrie := *d.maxValidators
epochIntervalTrie := *d.epochInterval
return &LCPContext{
epochTrie: &epochTrie,
delegateTrie: &delegateTrie,
@ -264,8 +264,6 @@ type LCPContextProto struct {
periodBlockHash common.Hash `json:"periodBlockRoot" gencodec:"required"`
maxValidatorsHash common.Hash `json:"maxValidatorRoot" gencodec:"required"`
epochIntervalHash common.Hash `json:"epochIntervalRoot" gencodec:"required"`
}
func (d *LCPContext) ToProto() *LCPContextProto {
@ -389,6 +387,7 @@ func (d *LCPContext) UnDelegate(delegatorAddr, candidateAddr common.Address) err
}
return d.voteTrie.TryDelete(delegator)
}
//function to write tries to memory
func (d *LCPContext) CommitTo(db ethdb.Database) (*LCPContextProto, error) {
epochRoot, err := d.epochTrie.Commit(nil)
@ -451,7 +450,6 @@ func (dc *LCPContext) SetVote(vote *trie.Trie) { dc.voteTrie = vote }
func (dc *LCPContext) SetCandidate(candidate *trie.Trie) { dc.candidateTrie = candidate }
func (dc *LCPContext) SetMintCnt(mintCnt *trie.Trie) { dc.mintCntTrie = mintCnt }
func (dc *LCPContext) GetValidators() ([]common.Address, error) {
var validators []common.Address
key := []byte("validator")
@ -474,15 +472,15 @@ func (dc *LCPContext) SetValidators(validators []common.Address) error {
// Set and Get block creation speed
func (dc *LCPContext) SetPeriodBlock(period int64) error {
key:= []byte("BlockPeriod")
periodByte :=make([]byte, 8)
binary.LittleEndian.PutUint64(periodByte,uint64(period))
key := []byte("BlockPeriod")
periodByte := make([]byte, 8)
binary.LittleEndian.PutUint64(periodByte, uint64(period))
dc.epochTrie.Update(key, periodByte)
return nil
}
}
func (dc *LCPContext) GetPeriodBlock() (int64) {
key:= []byte("BlockPeriod")
func (dc *LCPContext) GetPeriodBlock() int64 {
key := []byte("BlockPeriod")
periodRLP := dc.epochTrie.Get(key)
period := int64(binary.LittleEndian.Uint64(periodRLP))
return period
@ -490,15 +488,15 @@ func (dc *LCPContext) GetPeriodBlock() (int64) {
//Set and Get maximim validators
func (dc *LCPContext) SetMaxValidators(maxVal int64) error {
key:= []byte("MaxValidators")
maxValByte :=make([]byte, 8)
binary.LittleEndian.PutUint64(maxValByte,uint64(maxVal))
key := []byte("MaxValidators")
maxValByte := make([]byte, 8)
binary.LittleEndian.PutUint64(maxValByte, uint64(maxVal))
dc.epochTrie.Update(key, maxValByte)
return nil
}
func (dc *LCPContext) GetMaxValidators() (int64) {
key:= []byte("MaxValidators")
func (dc *LCPContext) GetMaxValidators() int64 {
key := []byte("MaxValidators")
maxValRLP := dc.epochTrie.Get(key)
maxVal := int64(binary.LittleEndian.Uint64(maxValRLP))
return maxVal
@ -506,14 +504,14 @@ func (dc *LCPContext) GetMaxValidators() (int64) {
//Set and Get epoch interval
func (dc *LCPContext) SetEpochInterval(epochInt int64) error {
key:= []byte("EpochInterval")
epochIntByte :=make([]byte, 8)
binary.LittleEndian.PutUint64(epochIntByte,uint64(epochInt))
key := []byte("EpochInterval")
epochIntByte := make([]byte, 8)
binary.LittleEndian.PutUint64(epochIntByte, uint64(epochInt))
dc.epochTrie.Update(key, epochIntByte)
return nil
}
func (dc *LCPContext) GetEpochInterval() (int64) {
key:= []byte("EpochInterval")
func (dc *LCPContext) GetEpochInterval() int64 {
key := []byte("EpochInterval")
epochIntRLP := dc.epochTrie.Get(key)
period := int64(binary.LittleEndian.Uint64(epochIntRLP))
return period