-
Notifications
You must be signed in to change notification settings - Fork 70
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(genesis-applier): create genesis_applier package
- Loading branch information
1 parent
dcf29b3
commit fc54c94
Showing
5 changed files
with
287 additions
and
7 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,36 @@ | ||
package genesis_applier | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"math/big" | ||
|
||
"github.com/ethereum/go-ethereum/core" | ||
) | ||
|
||
type GenesisApplier struct { | ||
GenesisJson []byte | ||
} | ||
|
||
// Updates ChainID inside GenesisJson to chainID, | ||
func (ga *GenesisApplier) UpdateChainID(chainID *big.Int) error { | ||
var genesis core.Genesis | ||
|
||
err := json.Unmarshal(ga.GenesisJson, &genesis) | ||
if err != nil { | ||
return fmt.Errorf("unable to parse genesis json") | ||
} | ||
|
||
if genesis.Config.ChainID != chainID { | ||
genesis.Config.ChainID = chainID | ||
} | ||
|
||
result, err := json.Marshal(genesis) | ||
if err != nil { | ||
return fmt.Errorf("error marshaling genesis") | ||
} | ||
|
||
ga.GenesisJson = result | ||
|
||
return 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.