github.com/MetalBlockchain/subnet-evm@v0.4.9/precompile/contract_deployer_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  	"math/big"
     9  
    10  	"github.com/ethereum/go-ethereum/common"
    11  )
    12  
    13  var (
    14  	_ StatefulPrecompileConfig = &ContractDeployerAllowListConfig{}
    15  	// Singleton StatefulPrecompiledContract for W/R access to the contract deployer allow list.
    16  	ContractDeployerAllowListPrecompile StatefulPrecompiledContract = createAllowListPrecompile(ContractDeployerAllowListAddress)
    17  )
    18  
    19  // ContractDeployerAllowListConfig wraps [AllowListConfig] and uses it to implement the StatefulPrecompileConfig
    20  // interface while adding in the contract deployer specific precompile address.
    21  type ContractDeployerAllowListConfig struct {
    22  	AllowListConfig
    23  	UpgradeableConfig
    24  }
    25  
    26  // NewContractDeployerAllowListConfig returns a config for a network upgrade at [blockTimestamp] that enables
    27  // ContractDeployerAllowList with [admins] and [enableds] as members of the allowlist.
    28  func NewContractDeployerAllowListConfig(blockTimestamp *big.Int, admins []common.Address, enableds []common.Address) *ContractDeployerAllowListConfig {
    29  	return &ContractDeployerAllowListConfig{
    30  		AllowListConfig: AllowListConfig{
    31  			AllowListAdmins:  admins,
    32  			EnabledAddresses: enableds,
    33  		},
    34  		UpgradeableConfig: UpgradeableConfig{BlockTimestamp: blockTimestamp},
    35  	}
    36  }
    37  
    38  // NewDisableContractDeployerAllowListConfig returns config for a network upgrade at [blockTimestamp]
    39  // that disables ContractDeployerAllowList.
    40  func NewDisableContractDeployerAllowListConfig(blockTimestamp *big.Int) *ContractDeployerAllowListConfig {
    41  	return &ContractDeployerAllowListConfig{
    42  		UpgradeableConfig: UpgradeableConfig{
    43  			BlockTimestamp: blockTimestamp,
    44  			Disable:        true,
    45  		},
    46  	}
    47  }
    48  
    49  // Address returns the address of the contract deployer allow list.
    50  func (c *ContractDeployerAllowListConfig) Address() common.Address {
    51  	return ContractDeployerAllowListAddress
    52  }
    53  
    54  // Configure configures [state] with the desired admins based on [c].
    55  func (c *ContractDeployerAllowListConfig) Configure(_ ChainConfig, state StateDB, _ BlockContext) {
    56  	c.AllowListConfig.Configure(state, ContractDeployerAllowListAddress)
    57  }
    58  
    59  // Contract returns the singleton stateful precompiled contract to be used for the allow list.
    60  func (c *ContractDeployerAllowListConfig) Contract() StatefulPrecompiledContract {
    61  	return ContractDeployerAllowListPrecompile
    62  }
    63  
    64  // Equal returns true if [s] is a [*ContractDeployerAllowListConfig] and it has been configured identical to [c].
    65  func (c *ContractDeployerAllowListConfig) Equal(s StatefulPrecompileConfig) bool {
    66  	// typecast before comparison
    67  	other, ok := (s).(*ContractDeployerAllowListConfig)
    68  	if !ok {
    69  		return false
    70  	}
    71  	return c.UpgradeableConfig.Equal(&other.UpgradeableConfig) && c.AllowListConfig.Equal(&other.AllowListConfig)
    72  }
    73  
    74  // String returns a string representation of the ContractDeployerAllowListConfig.
    75  func (c *ContractDeployerAllowListConfig) String() string {
    76  	bytes, _ := json.Marshal(c)
    77  	return string(bytes)
    78  }
    79  
    80  // GetContractDeployerAllowListStatus returns the role of [address] for the contract deployer
    81  // allow list.
    82  func GetContractDeployerAllowListStatus(stateDB StateDB, address common.Address) AllowListRole {
    83  	return getAllowListStatus(stateDB, ContractDeployerAllowListAddress, address)
    84  }
    85  
    86  // SetContractDeployerAllowListStatus sets the permissions of [address] to [role] for the
    87  // contract deployer allow list.
    88  // assumes [role] has already been verified as valid.
    89  func SetContractDeployerAllowListStatus(stateDB StateDB, address common.Address, role AllowListRole) {
    90  	setAllowListRole(stateDB, ContractDeployerAllowListAddress, address, role)
    91  }