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