github.com/MetalBlockchain/subnet-evm@v0.6.3/params/precompiles.go (about)

     1  // (c) 2023 Ava Labs, Inc. All rights reserved.
     2  // See the file LICENSE for licensing terms.
     3  
     4  package params
     5  
     6  import (
     7  	"encoding/json"
     8  
     9  	"github.com/MetalBlockchain/subnet-evm/precompile/modules"
    10  	"github.com/MetalBlockchain/subnet-evm/precompile/precompileconfig"
    11  )
    12  
    13  type Precompiles map[string]precompileconfig.Config
    14  
    15  // UnmarshalJSON parses the JSON-encoded data into the ChainConfigPrecompiles.
    16  // ChainConfigPrecompiles is a map of precompile module keys to their
    17  // configuration.
    18  func (ccp *Precompiles) UnmarshalJSON(data []byte) error {
    19  	raw := make(map[string]json.RawMessage)
    20  	if err := json.Unmarshal(data, &raw); err != nil {
    21  		return err
    22  	}
    23  
    24  	*ccp = make(Precompiles)
    25  	for _, module := range modules.RegisteredModules() {
    26  		key := module.ConfigKey
    27  		if value, ok := raw[key]; ok {
    28  			conf := module.MakeConfig()
    29  			if err := json.Unmarshal(value, conf); err != nil {
    30  				return err
    31  			}
    32  			(*ccp)[key] = conf
    33  		}
    34  	}
    35  	return nil
    36  }