@@ -121,7 +121,18 @@ func (e *Extras[C, R]) newForRules(c *ChainConfig, r *Rules, blockNum *big.Int,
121121 return pseudo .From (rExtra ).Type
122122}
123123
124- func (* Extras [C , R ]) payloads () (g ExtraPayloads [C , R ]) { return }
124+ func (* Extras [C , R ]) payloads () ExtraPayloads [C , R ] {
125+ return ExtraPayloads [C , R ]{
126+ ChainConfig : pseudo .NewAccessor [* ChainConfig , C ](
127+ func (c * ChainConfig ) * pseudo.Type { return c .extraPayload () },
128+ func (c * ChainConfig , t * pseudo.Type ) { c .extra = t },
129+ ),
130+ Rules : pseudo .NewAccessor [* Rules , R ](
131+ func (r * Rules ) * pseudo.Type { return r .extraPayload () },
132+ func (r * Rules , t * pseudo.Type ) { r .extra = t },
133+ ),
134+ }
135+ }
125136
126137// mustBeStructOrPointerToOne panics if `T` isn't a struct or a *struct.
127138func mustBeStructOrPointerToOne [T any ]() {
@@ -149,12 +160,15 @@ func notStructMessage[T any]() string {
149160// [ChainConfig] and [Rules] structs. The only valid way to construct an
150161// instance is by a call to [RegisterExtras].
151162type ExtraPayloads [C ChainConfigHooks , R RulesHooks ] struct {
152- _ struct {} // make godoc show unexported fields so nobody tries to make their own instance ;)
163+ ChainConfig pseudo.Accessor [* ChainConfig , C ]
164+ Rules pseudo.Accessor [* Rules , R ]
153165}
154166
155167// FromChainConfig returns the ChainConfig's extra payload.
156- func (ExtraPayloads [C , R ]) FromChainConfig (c * ChainConfig ) C {
157- return pseudo.MustNewValue [C ](c .extraPayload ()).Get ()
168+ //
169+ // Deprecated: use the equivalent [ExtraPayloads.ChainConfig] method.
170+ func (e ExtraPayloads [C , R ]) FromChainConfig (c * ChainConfig ) C {
171+ return e .ChainConfig .Get (c )
158172}
159173
160174// PointerFromChainConfig returns a pointer to the ChainConfig's extra payload.
@@ -164,13 +178,17 @@ func (ExtraPayloads[C, R]) FromChainConfig(c *ChainConfig) C {
164178// shallow copy and that the *C returned here will therefore be shared by all
165179// copies. If this is not the desired behaviour, use
166180// [ExtraPayloads.SetOnChainConfig].
167- func (ExtraPayloads [C , R ]) PointerFromChainConfig (c * ChainConfig ) * C {
168- return pseudo.MustPointerTo [C ](c .extraPayload ()).Value .Get ()
181+ //
182+ // Deprecated: use the equivalent [ExtraPayloads.ChainConfig] method.
183+ func (e ExtraPayloads [C , R ]) PointerFromChainConfig (c * ChainConfig ) * C {
184+ return e .ChainConfig .GetPointer (c )
169185}
170186
171187// SetOnChainConfig sets the ChainConfig's extra payload.
188+ //
189+ // Deprecated: use the equivalent [ExtraPayloads.ChainConfig] method.
172190func (e ExtraPayloads [C , R ]) SetOnChainConfig (cc * ChainConfig , val C ) {
173- cc . extra = pseudo . From ( val ). Type
191+ e . ChainConfig . Set ( cc , val )
174192}
175193
176194// hooksFromChainConfig is equivalent to FromChainConfig(), but returns an
@@ -181,8 +199,10 @@ func (e ExtraPayloads[C, R]) hooksFromChainConfig(c *ChainConfig) ChainConfigHoo
181199}
182200
183201// FromRules returns the Rules' extra payload.
184- func (ExtraPayloads [C , R ]) FromRules (r * Rules ) R {
185- return pseudo.MustNewValue [R ](r .extraPayload ()).Get ()
202+ //
203+ // Deprecated: use the equivalent [ExtraPayloads.Rules] method.
204+ func (e ExtraPayloads [C , R ]) FromRules (r * Rules ) R {
205+ return e .Rules .Get (r )
186206}
187207
188208// PointerFromRules returns a pointer to the Rules's extra payload. This is
@@ -191,13 +211,17 @@ func (ExtraPayloads[C, R]) FromRules(r *Rules) R {
191211// Note that copying a Rules by dereferencing a pointer will result in a shallow
192212// copy and that the *R returned here will therefore be shared by all copies. If
193213// this is not the desired behaviour, use [ExtraPayloads.SetOnRules].
194- func (ExtraPayloads [C , R ]) PointerFromRules (r * Rules ) * R {
195- return pseudo.MustPointerTo [R ](r .extraPayload ()).Value .Get ()
214+ //
215+ // Deprecated: use the equivalent [ExtraPayloads.Rules] method.
216+ func (e ExtraPayloads [C , R ]) PointerFromRules (r * Rules ) * R {
217+ return e .Rules .GetPointer (r )
196218}
197219
198220// SetOnRules sets the Rules' extra payload.
221+ //
222+ // Deprecated: use the equivalent [ExtraPayloads.Rules] method.
199223func (e ExtraPayloads [C , R ]) SetOnRules (r * Rules , val R ) {
200- r . extra = pseudo . From ( val ). Type
224+ e . Rules . Set ( r , val )
201225}
202226
203227// hooksFromRules is the [RulesHooks] equivalent of hooksFromChainConfig().
0 commit comments