Skip to content

Commit

Permalink
chore: merge genesisapplier & genesisdeployment (#63)
Browse files Browse the repository at this point in the history
* genesis package

* nits
  • Loading branch information
hamdiallam authored Jul 26, 2024
1 parent 7df3085 commit f0ef708
Show file tree
Hide file tree
Showing 36 changed files with 39 additions and 45 deletions.
22 changes: 11 additions & 11 deletions config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"

registry "github.com/ethereum-optimism/superchain-registry/superchain"
"github.com/ethereum-optimism/supersim/genesisdeployment"
"github.com/ethereum-optimism/supersim/genesis"
"github.com/ethereum-optimism/supersim/hdaccount"

"github.com/ethereum/go-ethereum"
Expand All @@ -25,28 +25,28 @@ var (
DefaultChainConfigs = []ChainConfig{
{
Name: "SourceChain",
ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID,
SecretsConfig: DefaultSecretsConfig,
GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L1.GenesisJSON,
GenesisJSON: genesis.GeneratedGenesisDeployment.L1.GenesisJSON,
},
{
Name: "OPChainA",
ChainID: genesisdeployment.GeneratedGenesisDeployment.L2s[0].ChainID,
ChainID: genesis.GeneratedGenesisDeployment.L2s[0].ChainID,
SecretsConfig: DefaultSecretsConfig,
GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[0].GenesisJSON,
GenesisJSON: genesis.GeneratedGenesisDeployment.L2s[0].GenesisJSON,
L2Config: &L2Config{
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[0].RegistryAddressList(),
L1ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesis.GeneratedGenesisDeployment.L2s[0].RegistryAddressList(),
},
},
{
Name: "OPChainB",
ChainID: genesisdeployment.GeneratedGenesisDeployment.L2s[1].ChainID,
ChainID: genesis.GeneratedGenesisDeployment.L2s[1].ChainID,
SecretsConfig: DefaultSecretsConfig,
GenesisJSON: genesisdeployment.GeneratedGenesisDeployment.L2s[1].GenesisJSON,
GenesisJSON: genesis.GeneratedGenesisDeployment.L2s[1].GenesisJSON,
L2Config: &L2Config{
L1ChainID: genesisdeployment.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesisdeployment.GeneratedGenesisDeployment.L2s[1].RegistryAddressList(),
L1ChainID: genesis.GeneratedGenesisDeployment.L1.ChainID,
L1Addresses: genesis.GeneratedGenesisDeployment.L2s[1].RegistryAddressList(),
},
},
}
Expand Down
27 changes: 27 additions & 0 deletions genesis/applier.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package genesis

import (
"encoding/json"
"fmt"
"math/big"

"github.com/ethereum/go-ethereum/core"
)

func ApplyChainID(genesisJson []byte, chainId *big.Int) ([]byte, error) {
var genesis core.Genesis
if err := json.Unmarshal(genesisJson, &genesis); err != nil {
return nil, fmt.Errorf("unable to parse genesis json: %w", err)
}

if genesis.Config.ChainID.Cmp(chainId) != 0 {
genesis.Config.ChainID = chainId
}

result, err := json.Marshal(genesis)
if err != nil {
return nil, fmt.Errorf("error marshaling genesis: %w", err)
}

return result, nil
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package genesisdeployment
package genesis

import (
_ "embed"
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 0 additions & 33 deletions genesisapplier/genesisapplier.go

This file was deleted.

0 comments on commit f0ef708

Please sign in to comment.