github.com/MetalBlockchain/subnet-evm@v0.4.9/precompile/tx_allow_list.go (about) 1 // (c) 2019-2020, Ava Labs, Inc. All rights reserved. 2 // See the file LICENSE for licensing terms. 3 4 package precompile 5 6 import ( 7 "encoding/json" 8 "errors" 9 "math/big" 10 11 "github.com/ethereum/go-ethereum/common" 12 ) 13 14 var ( 15 _ StatefulPrecompileConfig = &TxAllowListConfig{} 16 // Singleton StatefulPrecompiledContract for W/R access to the contract deployer allow list. 17 TxAllowListPrecompile StatefulPrecompiledContract = createAllowListPrecompile(TxAllowListAddress) 18 19 ErrSenderAddressNotAllowListed = errors.New("cannot issue transaction from non-allow listed address") 20 ) 21 22 // TxAllowListConfig wraps [AllowListConfig] and uses it to implement the StatefulPrecompileConfig 23 // interface while adding in the TxAllowList specific precompile address. 24 type TxAllowListConfig struct { 25 AllowListConfig 26 UpgradeableConfig 27 } 28 29 // NewTxAllowListConfig returns a config for a network upgrade at [blockTimestamp] that enables 30 // TxAllowList with the given [admins] and [enableds] as members of the allowlist. 31 func NewTxAllowListConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address) *TxAllowListConfig { 32 return &TxAllowListConfig{ 33 AllowListConfig: AllowListConfig{ 34 AllowListAdmins: admins, 35 EnabledAddresses: enableds, 36 }, 37 UpgradeableConfig: UpgradeableConfig{BlockTimestamp: blockTimestamp}, 38 } 39 } 40 41 // NewDisableTxAllowListConfig returns config for a network upgrade at [blockTimestamp] 42 // that disables TxAllowList. 43 func NewDisableTxAllowListConfig(blockTimestamp *big.Int) *TxAllowListConfig { 44 return &TxAllowListConfig{ 45 UpgradeableConfig: UpgradeableConfig{ 46 BlockTimestamp: blockTimestamp, 47 Disable: true, 48 }, 49 } 50 } 51 52 // Address returns the address of the contract deployer allow list. 53 func (c *TxAllowListConfig) Address() common.Address { 54 return TxAllowListAddress 55 } 56 57 // Configure configures [state] with the desired admins based on [c]. 58 func (c *TxAllowListConfig) Configure(_ ChainConfig, state StateDB, _ BlockContext) { 59 c.AllowListConfig.Configure(state, TxAllowListAddress) 60 } 61 62 // Contract returns the singleton stateful precompiled contract to be used for the allow list. 63 func (c *TxAllowListConfig) Contract() StatefulPrecompiledContract { 64 return TxAllowListPrecompile 65 } 66 67 // Equal returns true if [s] is a [*TxAllowListConfig] and it has been configured identical to [c]. 68 func (c *TxAllowListConfig) Equal(s StatefulPrecompileConfig) bool { 69 // typecast before comparison 70 other, ok := (s).(*TxAllowListConfig) 71 if !ok { 72 return false 73 } 74 return c.UpgradeableConfig.Equal(&other.UpgradeableConfig) && c.AllowListConfig.Equal(&other.AllowListConfig) 75 } 76 77 // String returns a string representation of the TxAllowListConfig. 78 func (c *TxAllowListConfig) String() string { 79 bytes, _ := json.Marshal(c) 80 return string(bytes) 81 } 82 83 // GetTxAllowListStatus returns the role of [address] for the contract deployer 84 // allow list. 85 func GetTxAllowListStatus(stateDB StateDB, address common.Address) AllowListRole { 86 return getAllowListStatus(stateDB, TxAllowListAddress, address) 87 } 88 89 // SetTxAllowListStatus sets the permissions of [address] to [role] for the 90 // tx allow list. 91 // assumes [role] has already been verified as valid. 92 func SetTxAllowListStatus(stateDB StateDB, address common.Address, role AllowListRole) { 93 setAllowListRole(stateDB, TxAllowListAddress, address, role) 94 }