Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nits w/ upstream #1272

Merged
merged 3 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions core/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ package core

import (
"bytes"
_ "embed"
"encoding/hex"
"encoding/json"
"errors"
Expand Down Expand Up @@ -119,8 +118,8 @@ type genesisSpecMarshaling struct {
GasUsed math.HexOrDecimal64
Number math.HexOrDecimal64
Difficulty *math.HexOrDecimal256
BaseFee *math.HexOrDecimal256
Alloc map[common.UnprefixedAddress]GenesisAccount
BaseFee *math.HexOrDecimal256
AirdropAmount *math.HexOrDecimal256
ExcessBlobGas *math.HexOrDecimal64
BlobGasUsed *math.HexOrDecimal64
Expand Down
53 changes: 53 additions & 0 deletions paramsext/precompile_upgrade.go
darioush marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package paramsext

import (
"encoding/json"
"errors"
"fmt"

"github.com/ava-labs/subnet-evm/precompile/modules"
"github.com/ava-labs/subnet-evm/precompile/precompileconfig"
)

var errNoKey = errors.New("PrecompileUpgrade cannot be empty")

type PrecompileUpgrade struct {
precompileconfig.Config
}

// UnmarshalJSON unmarshals the json into the correct precompile config type
// based on the key. Keys are defined in each precompile module, and registered in
// precompile/registry/registry.go.
// Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key
func (u *PrecompileUpgrade) UnmarshalJSON(data []byte) error {
raw := make(map[string]json.RawMessage)
if err := json.Unmarshal(data, &raw); err != nil {
return err
}
if len(raw) == 0 {
return errNoKey
}
if len(raw) > 1 {
return fmt.Errorf("PrecompileUpgrade must have exactly one key, got %d", len(raw))
}
for key, value := range raw {
module, ok := modules.GetPrecompileModule(key)
if !ok {
return fmt.Errorf("unknown precompile config: %s", key)
}
config := module.MakeConfig()
if err := json.Unmarshal(value, config); err != nil {
return err
}
u.Config = config
}
return nil
}

// MarshalJSON marshal the precompile config into json based on the precompile key.
// Ex: {"feeManagerConfig": {...}} where "feeManagerConfig" is the key
func (u *PrecompileUpgrade) MarshalJSON() ([]byte, error) {
res := make(map[string]precompileconfig.Config)
res[u.Key()] = u.Config
return json.Marshal(res)
}
Loading