Skip to content

Commit

Permalink
Merge pull request #17 from VeerChaurasia/Implement/config/types.go-#5
Browse files Browse the repository at this point in the history
Implement Config/types.go
  • Loading branch information
star-gazer111 authored Aug 25, 2024
2 parents 2ee584a + 9f815f5 commit 9422a18
Showing 1 changed file with 68 additions and 13 deletions.
81 changes: 68 additions & 13 deletions config/types.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,71 @@
package config

type ChainConfig struct{

import (
"encoding/hex"
"encoding/json"
)
type ChainConfig struct {
ChainID uint64 `json:"chain_id"`
GenesisTime uint64 `json:"genesis_time"`
GenesisRoot []byte `json:"genesis_root"`
}
type Fork struct{
epoch uint64
fork_version []uint8
type Fork struct {
Epoch uint64 `json:"epoch"`
ForkVersion []byte `json:"fork_version"`
}
type Forks struct {
Genesis Fork `json:"genesis"`
Altair Fork `json:"altair"`
Bellatrix Fork `json:"bellatrix"`
Capella Fork `json:"capella"`
Deneb Fork `json:"deneb"`
}
func (c ChainConfig) MarshalJSON() ([]byte, error) {
type Alias ChainConfig
return json.Marshal(&struct {
Alias
GenesisRoot string `json:"genesis_root"`
}{
Alias: (Alias)(c),
GenesisRoot: hex.EncodeToString(c.GenesisRoot),
})
}
func (c *ChainConfig) UnmarshalJSON(data []byte) error {
type Alias ChainConfig
aux := &struct {
*Alias
GenesisRoot string `json:"genesis_root"`
}{
Alias: (*Alias)(c),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
var err error
c.GenesisRoot, err = hex.DecodeString(aux.GenesisRoot)
return err
}
func (f Fork) MarshalJSON() ([]byte, error) {
type Alias Fork
return json.Marshal(&struct {
Alias
ForkVersion string `json:"fork_version"`
}{
Alias: (Alias)(f),
ForkVersion: hex.EncodeToString(f.ForkVersion),
})
}
func (f *Fork) UnmarshalJSON(data []byte) error {
type Alias Fork
aux := &struct {
*Alias
ForkVersion string `json:"fork_version"`
}{
Alias: (*Alias)(f),
}
if err := json.Unmarshal(data, &aux); err != nil {
return err
}
var err error
f.ForkVersion, err = hex.DecodeString(aux.ForkVersion)
return err
}
type Forks struct{
genesis Fork
altair Fork
bellatrix Fork
capella Fork
deneb Fork
}

0 comments on commit 9422a18

Please sign in to comment.