Skip to content

Commit

Permalink
feat: params.ExtraPayloadGetter.SetOnChainConfig() + Rules equiv
Browse files Browse the repository at this point in the history
  • Loading branch information
ARR4N committed Sep 12, 2024
1 parent d31803a commit 5d50626
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
12 changes: 12 additions & 0 deletions params/config.libevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ func (ExtraPayloadGetter[C, R]) PointerFromChainConfig(c *ChainConfig) *C {
return pseudo.MustPointerTo[C](c.extraPayload()).Value.Get()
}

// SetOnChainConfig sets the ChainConfig's extra payload. It is equivalent to
// `*e.PointerFromChainConfig(cc) = val`.
func (e ExtraPayloadGetter[C, R]) SetOnChainConfig(cc *ChainConfig, val C) {
*e.PointerFromChainConfig(cc) = val
}

// hooksFromChainConfig is equivalent to FromChainConfig(), but returns an
// interface instead of the concrete type implementing it; this allows it to be
// used in non-generic code.
Expand All @@ -176,6 +182,12 @@ func (ExtraPayloadGetter[C, R]) PointerFromRules(r *Rules) *R {
return pseudo.MustPointerTo[R](r.extraPayload()).Value.Get()
}

// SetOnRules sets the Rules' extra payload. It is equivalent to
// `*e.PointerFromRules(r) = val`.
func (e ExtraPayloadGetter[C, R]) SetOnRules(r *Rules, val R) {
*e.PointerFromRules(r) = val
}

// hooksFromRules is the [RulesHooks] equivalent of hooksFromChainConfig().
func (e ExtraPayloadGetter[C, R]) hooksFromRules(r *Rules) RulesHooks {
return e.FromRules(r)
Expand Down
4 changes: 2 additions & 2 deletions params/config.libevm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,11 @@ func TestModificationOfZeroExtras(t *testing.T) {
assertRulesExtra(t, rulesExtra{X: pi}, "after setting via pointer field")

ccReplace := ccExtra{X: 142857}
*getter.PointerFromChainConfig(config) = ccReplace
getter.SetOnChainConfig(config, ccReplace)
assertChainConfigExtra(t, ccReplace, "after replacement of entire extra via `*pointer = x`")

rulesReplace := rulesExtra{X: 18101986}
*getter.PointerFromRules(rules) = rulesReplace
getter.SetOnRules(rules, rulesReplace)
assertRulesExtra(t, rulesReplace, "after replacement of entire extra via `*pointer = x`")

if t.Failed() {
Expand Down

0 comments on commit 5d50626

Please sign in to comment.