-
Notifications
You must be signed in to change notification settings - Fork 7
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 #17 from VeerChaurasia/Implement/config/types.go-#5
Implement Config/types.go
- Loading branch information
Showing
1 changed file
with
68 additions
and
13 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 |
---|---|---|
@@ -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 | ||
} |