github.com/cheng762/platon-go@v1.8.17-0.20190529111256-7deff2d7be26/core/ppos/candidate_context.go (about) 1 package pposm 2 3 import ( 4 "github.com/PlatONnetwork/PlatON-Go/common" 5 "github.com/PlatONnetwork/PlatON-Go/core/state" 6 "github.com/PlatONnetwork/PlatON-Go/core/types" 7 "github.com/PlatONnetwork/PlatON-Go/core/vm" 8 "github.com/PlatONnetwork/PlatON-Go/p2p/discover" 9 "github.com/PlatONnetwork/PlatON-Go/params" 10 "math/big" 11 ) 12 13 type CandidatePoolContext struct { 14 Configs *params.PposConfig 15 } 16 17 var cContext *CandidatePoolContext 18 19 // Initialize the global candidate pool context object 20 func NewCandidatePoolContext(configs *params.PposConfig) *CandidatePoolContext { 21 cContext = &CandidatePoolContext{ 22 Configs: configs, 23 } 24 return cContext 25 } 26 27 func GetCandidateContextPtr() *CandidatePoolContext { 28 return cContext 29 } 30 31 func (c *CandidatePoolContext) initCandidatePool() *CandidatePool { 32 return NewCandidatePool(c.Configs) 33 } 34 35 func (c *CandidatePoolContext) SetCandidate(state vm.StateDB, nodeId discover.NodeID, can *types.Candidate) error { 36 return c.initCandidatePool().SetCandidate(state, nodeId, can) 37 } 38 39 func (c *CandidatePoolContext) GetCandidate(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) *types.Candidate { 40 return c.initCandidatePool().GetCandidate(state, nodeId, blockNumber) 41 } 42 43 func (c *CandidatePoolContext) GetCandidateArr(state vm.StateDB, blockNumber *big.Int, nodeIds ...discover.NodeID) types.CandidateQueue { 44 return c.initCandidatePool().GetCandidateArr(state, blockNumber, nodeIds...) 45 } 46 47 func (c *CandidatePoolContext) GetWitnessCandidate(state vm.StateDB, nodeId discover.NodeID, flag int, blockNumber *big.Int) *types.Candidate { 48 return c.initCandidatePool().GetWitnessCandidate(state, nodeId, flag, blockNumber) 49 } 50 51 func (c *CandidatePoolContext) WithdrawCandidate(state vm.StateDB, nodeId discover.NodeID, price, blockNumber *big.Int) error { 52 return c.initCandidatePool().WithdrawCandidate(state, nodeId, price, blockNumber) 53 } 54 55 func (c *CandidatePoolContext) GetChosens(state vm.StateDB, flag int, blockNumber *big.Int) types.KindCanQueue { 56 return c.initCandidatePool().GetChosens(state, flag, blockNumber) 57 } 58 59 func (c *CandidatePoolContext) GetCandidatePendArr (state vm.StateDB, flag int, blockNumber *big.Int) types.CandidateQueue { 60 return c.initCandidatePool().GetCandidatePendArr(state, flag, blockNumber) 61 } 62 63 func (c *CandidatePoolContext) GetChairpersons(state vm.StateDB, blockNumber *big.Int) types.CandidateQueue { 64 return c.initCandidatePool().GetChairpersons(state, blockNumber) 65 } 66 67 func (c *CandidatePoolContext) GetDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) types.RefundQueue { 68 return c.initCandidatePool().GetDefeat(state, nodeId, blockNumber) 69 } 70 71 func (c *CandidatePoolContext) IsDefeat(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool { 72 return c.initCandidatePool().IsDefeat(state, nodeId, blockNumber) 73 } 74 75 func (c *CandidatePoolContext) IsChosens(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) bool { 76 return c.initCandidatePool().IsChosens(state, nodeId, blockNumber) 77 } 78 79 func (c *CandidatePoolContext) RefundBalance(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) error { 80 return c.initCandidatePool().RefundBalance(state, nodeId, blockNumber) 81 } 82 83 func (c *CandidatePoolContext) GetOwner(state vm.StateDB, nodeId discover.NodeID, blockNumber *big.Int) common.Address { 84 return c.initCandidatePool().GetOwner(state, nodeId, blockNumber) 85 } 86 87 func (c *CandidatePoolContext) GetRefundInterval(blockNumber *big.Int) uint32 { 88 return c.initCandidatePool().GetRefundInterval(blockNumber) 89 } 90 91 func (c *CandidatePoolContext) MaxCount() uint32 { 92 return c.initCandidatePool().MaxCount() 93 } 94 95 func (c *CandidatePoolContext) MaxChair() uint32 { 96 return c.initCandidatePool().MaxChair() 97 } 98 99 func (c *CandidatePoolContext) Election(state *state.StateDB, parentHash common.Hash, blocknumber *big.Int) ([]*discover.Node, error) { 100 return c.initCandidatePool().Election(state, parentHash, blocknumber) 101 } 102 103 func (c *CandidatePoolContext) Switch(state *state.StateDB, blockNumber *big.Int) bool { 104 return c.initCandidatePool().Switch(state, blockNumber) 105 } 106 107 func (c *CandidatePoolContext) GetWitness(state *state.StateDB, flag int, blockNumber *big.Int) ([]*discover.Node, error) { 108 return c.initCandidatePool().GetWitness(state, flag, blockNumber) 109 } 110 111 func (c *CandidatePoolContext) GetAllWitness(state *state.StateDB, blockNumber *big.Int) ([]*discover.Node, []*discover.Node, []*discover.Node, error) { 112 return c.initCandidatePool().GetAllWitness(state, blockNumber) 113 } 114 115 func (c *CandidatePoolContext) SetCandidateExtra(state vm.StateDB, nodeId discover.NodeID, extra string) error { 116 return c.initCandidatePool().SetCandidateExtra(state, nodeId, extra) 117 } 118 119 func (c *CandidatePoolContext) UpdateElectedQueue(state vm.StateDB, currBlockNumber *big.Int, nodeIds ...discover.NodeID) error { 120 return c.initCandidatePool().UpdateElectedQueue(state, currBlockNumber, nodeIds...) 121 }