-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from ethereum-optimism/harry/genesis_applier
feat(genesis-applier): create genesisapplier package
- Loading branch information
Showing
6 changed files
with
300 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package genesisapplier | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core" | ||
) | ||
|
||
type Config struct { | ||
ChainID *big.Int | ||
} | ||
|
||
func UpdateGenesisWithConfig(genesisJson []byte, config Config) ([]byte, error) { | ||
var genesis core.Genesis | ||
|
||
err := json.Unmarshal(genesisJson, &genesis) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to parse genesis json") | ||
} | ||
|
||
if config.ChainID != nil && genesis.Config.ChainID != config.ChainID { | ||
genesis.Config.ChainID = config.ChainID | ||
} | ||
|
||
result, err := json.Marshal(genesis) | ||
if err != nil { | ||
return nil, fmt.Errorf("error marshaling genesis") | ||
} | ||
|
||
return result, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.