Skip to content

Commit 594b8e0

Browse files
ARR4NDarioush Jalali
authored and
Darioush Jalali
committed
refactor: simplify ChainConfig.UnmarshalJSON() branches
1 parent a9250c6 commit 594b8e0

File tree

2 files changed

+48
-3
lines changed

2 files changed

+48
-3
lines changed

params/config.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ func (c *ChainConfig) Description() string {
478478
if c.VerkleTime != nil {
479479
banner += fmt.Sprintf(" - Verkle: @%-10v\n", *c.VerkleTime)
480480
}
481-
return banner
481+
return banner + c.extraDescription()
482482
}
483483

484484
// IsHomestead returns whether num is either equal to the homestead block or greater.
@@ -671,7 +671,7 @@ func (c *ChainConfig) CheckConfigForkOrder() error {
671671
lastFork = cur
672672
}
673673
}
674-
return nil
674+
return c.extraCheckConfigForkOrder()
675675
}
676676

677677
func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError {
@@ -742,7 +742,7 @@ func (c *ChainConfig) checkCompatible(newcfg *ChainConfig, headNumber *big.Int,
742742
if isForkTimestampIncompatible(c.VerkleTime, newcfg.VerkleTime, headTimestamp) {
743743
return newTimestampCompatError("Verkle fork timestamp", c.VerkleTime, newcfg.VerkleTime)
744744
}
745-
return nil
745+
return c.extraCheckCompatible(newcfg, headNumber, headTimestamp)
746746
}
747747

748748
// BaseFeeChangeDenominator bounds the amount the base fee can change between blocks.

params/config.libevm.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,48 @@ func (r *Rules) extraPayload() *pseudo.Type {
205205
}
206206
return r.extra
207207
}
208+
209+
func (c *ChainConfig) extraDescription() string {
210+
if registeredExtras == nil || c.extra == nil {
211+
return ""
212+
}
213+
214+
type Descriptioner interface {
215+
Description() string
216+
}
217+
d, ok := c.extra.Interface().(Descriptioner)
218+
if !ok {
219+
return ""
220+
}
221+
return d.Description()
222+
}
223+
224+
func (c *ChainConfig) extraCheckCompatible(newcfg *ChainConfig, headNumber *big.Int, headTimestamp uint64) *ConfigCompatError {
225+
if registeredExtras == nil || c.extra == nil {
226+
return nil
227+
}
228+
229+
type CompatibleChecker interface {
230+
CheckCompatible(*ChainConfig, *big.Int, uint64) *ConfigCompatError
231+
}
232+
cc, ok := c.extra.Interface().(CompatibleChecker)
233+
if !ok {
234+
return nil
235+
}
236+
return cc.CheckCompatible(newcfg, headNumber, headTimestamp)
237+
}
238+
239+
func (c *ChainConfig) extraCheckConfigForkOrder() error {
240+
if registeredExtras == nil || c.extra == nil {
241+
return nil
242+
}
243+
244+
type ForkOrderChecker interface {
245+
CheckConfigForkOrder() error
246+
}
247+
cc, ok := c.extra.Interface().(ForkOrderChecker)
248+
if !ok {
249+
return nil
250+
}
251+
return cc.CheckConfigForkOrder()
252+
}

0 commit comments

Comments
 (0)