github.com/gilgames000/kcc-geth@v1.0.6/consensus/posa/interactive.go (about) 1 package posa 2 3 import ( 4 "strings" 5 6 "github.com/ethereum/go-ethereum/accounts/abi" 7 "github.com/ethereum/go-ethereum/common" 8 "github.com/ethereum/go-ethereum/consensus" 9 "github.com/ethereum/go-ethereum/core" 10 "github.com/ethereum/go-ethereum/core/state" 11 "github.com/ethereum/go-ethereum/core/types" 12 "github.com/ethereum/go-ethereum/core/vm" 13 "github.com/ethereum/go-ethereum/params" 14 ) 15 16 type chainContext struct { 17 chainReader consensus.ChainHeaderReader 18 engine consensus.Engine 19 } 20 21 func newChainContext(chainReader consensus.ChainHeaderReader, engine consensus.Engine) *chainContext { 22 return &chainContext{ 23 chainReader: chainReader, 24 engine: engine, 25 } 26 } 27 28 // Engine retrieves the chain's consensus engine. 29 func (cc *chainContext) Engine() consensus.Engine { 30 return cc.engine 31 } 32 33 // GetHeader returns the hash corresponding to their hash. 34 func (cc *chainContext) GetHeader(hash common.Hash, number uint64) *types.Header { 35 return cc.chainReader.GetHeader(hash, number) 36 } 37 38 func getInteractiveABI() map[string]abi.ABI { 39 abiMap := make(map[string]abi.ABI, 0) 40 tmpABI, _ := abi.JSON(strings.NewReader(validatorsInteractiveABI)) 41 abiMap[validatorsContractName] = tmpABI 42 tmpABI, _ = abi.JSON(strings.NewReader(punishInteractiveABI)) 43 abiMap[punishContractName] = tmpABI 44 tmpABI, _ = abi.JSON(strings.NewReader(proposalInteractiveABI)) 45 abiMap[proposalContractName] = tmpABI 46 47 return abiMap 48 } 49 50 // executeMsg executes transaction sent to system contracts. 51 func executeMsg(msg core.Message, state *state.StateDB, header *types.Header, chainContext core.ChainContext, chainConfig *params.ChainConfig) (ret []byte, err error) { 52 // Set gas price to zero 53 context := core.NewEVMBlockContext(header, chainContext, nil) 54 txContext := core.NewEVMTxContext(msg) 55 vmenv := vm.NewEVM(context, txContext, state, chainConfig, vm.Config{}) 56 57 msg.GasPrice() 58 59 ret, _, err = vmenv.Call(vm.AccountRef(msg.From()), *msg.To(), msg.Data(), msg.Gas(), msg.Value()) 60 61 if err != nil { 62 return []byte{}, err 63 } 64 65 return ret, nil 66 }