github.com/codingfuture/orig-energi3@v0.8.4/energi/common/proxy.go (about) 1 // Copyright 2019 The Energi Core Authors 2 // This file is part of the Energi Core library. 3 // 4 // The Energi Core library is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Lesser General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // The Energi Core library is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Lesser General Public License for more details. 13 // 14 // You should have received a copy of the GNU Lesser General Public License 15 // along with the Energi Core library. If not, see <http://www.gnu.org/licenses/>. 16 17 package common 18 19 import ( 20 "context" 21 22 "github.com/ethereum/go-ethereum/common" 23 "github.com/ethereum/go-ethereum/core" 24 "github.com/ethereum/go-ethereum/core/state" 25 26 energi_params "energi.world/core/gen3/energi/params" 27 ) 28 29 // GeneralProxyHashFunc provides the function that helps check for governed 30 // proxy contracts filtered logs. 31 type GeneralProxyHashFunc func(addr common.Address, blockheight *uint64) *common.Hash 32 33 // GeneralProxyHashGen returns a function that helps retrieve the governed proxy contract hash. 34 func GeneralProxyHashGen(blockchain *core.BlockChain) GeneralProxyHashFunc { 35 return func(addr common.Address, blockheight *uint64) *common.Hash { 36 var err error 37 var statedb *state.StateDB 38 39 if blockheight == nil || *blockheight < 1 { 40 statedb, err = blockchain.State() 41 } else { 42 header := blockchain.GetHeaderByNumber(*blockheight) 43 statedb, err = blockchain.StateAt(header.Hash()) 44 } 45 if err != nil { 46 return nil 47 } 48 49 // Get a hash that allows logs from governed proxy checkpoint contract to be filtered. 50 prxyHash := statedb.GetState(addr, energi_params.Storage_ProxyImpl) 51 return &prxyHash 52 } 53 } 54 55 // GeneralProxyHashExtractor retrieves if it exists the proxy hash func passed 56 // through the context. 57 func GeneralProxyHashExtractor(ctx context.Context, qAddr common.Address, blockNo *uint64) *common.Hash { 58 proxyHashFunc := ctx.Value(energi_params.GeneralProxyCtxKey).(GeneralProxyHashFunc) 59 if proxyHashFunc == nil { 60 return nil 61 } 62 63 return proxyHashFunc(qAddr, blockNo) 64 }