@@ -46,13 +46,21 @@ func RegisterExtras[
4646 HeaderHooks
4747 * H
4848 },
49+ BodyExtra any , BodyExtraPtr interface {
50+ BodyHooks
51+ * BodyExtra
52+ },
4953 SA any ,
50- ]() ExtraPayloads [HPtr , SA ] {
51- extra := ExtraPayloads [HPtr , SA ]{
54+ ]() ExtraPayloads [HPtr , BodyExtraPtr , SA ] {
55+ extra := ExtraPayloads [HPtr , BodyExtraPtr , SA ]{
5256 Header : pseudo .NewAccessor [* Header , HPtr ](
5357 (* Header ).extraPayload ,
5458 func (h * Header , t * pseudo.Type ) { h .extra = t },
5559 ),
60+ Body : pseudo .NewAccessor [* Body , BodyExtraPtr ](
61+ (* Body ).extraPayload ,
62+ func (b * Body , t * pseudo.Type ) { b .extra = t },
63+ ),
5664 StateAccount : pseudo .NewAccessor [StateOrSlimAccount , SA ](
5765 func (a StateOrSlimAccount ) * pseudo.Type { return a .extra ().payload () },
5866 func (a StateOrSlimAccount , t * pseudo.Type ) { a .extra ().t = t },
@@ -63,10 +71,11 @@ func RegisterExtras[
6371 var x SA
6472 return fmt .Sprintf ("%T" , x )
6573 }(),
66- // The [ExtraPayloads] that we returns is based on [HPtr,SA], not [H,SA]
67- // so our constructors MUST match that. This guarantees that calls to
68- // the [HeaderHooks] methods will never be performed on a nil pointer.
69- newHeader : pseudo .NewConstructor [H ]().NewPointer , // i.e. non-nil HPtr
74+ // The [ExtraPayloads] that we returns is based on [HPtr,BodyExtraPtr,SA], not
75+ // [H,BodyExtra,SA] so our constructors MUST match that. This guarantees that calls to
76+ // the [HeaderHooks] and [BodyHooks] methods will never be performed on a nil pointer.
77+ newHeader : pseudo .NewConstructor [H ]().NewPointer , // i.e. non-nil HPtr
78+ newBody : pseudo .NewConstructor [BodyExtra ]().NewPointer , // i.e. non-nil BodyExtraPtr
7079 newStateAccount : pseudo .NewConstructor [SA ]().Zero ,
7180 cloneStateAccount : extra .cloneStateAccount ,
7281 hooks : extra ,
@@ -87,11 +96,14 @@ func TestOnlyClearRegisteredExtras() {
8796var registeredExtras register.AtMostOnce [* extraConstructors ]
8897
8998type extraConstructors struct {
90- stateAccountType string
91- newHeader , newStateAccount func () * pseudo.Type
92- cloneStateAccount func (* StateAccountExtra ) * StateAccountExtra
93- hooks interface {
99+ stateAccountType string
100+ newHeader func () * pseudo.Type
101+ newBody func () * pseudo.Type
102+ newStateAccount func () * pseudo.Type
103+ cloneStateAccount func (* StateAccountExtra ) * StateAccountExtra
104+ hooks interface {
94105 hooksFromHeader (* Header ) HeaderHooks
106+ hooksFromBody (* Body ) BodyHooks
95107 }
96108}
97109
@@ -105,14 +117,15 @@ func (e *StateAccountExtra) clone() *StateAccountExtra {
105117}
106118
107119// ExtraPayloads provides strongly typed access to the extra payload carried by
108- // [Header], [StateAccount], and [SlimAccount] structs. The only valid way to
120+ // [Header], [Body], [ StateAccount], and [SlimAccount] structs. The only valid way to
109121// construct an instance is by a call to [RegisterExtras].
110- type ExtraPayloads [HPtr HeaderHooks , SA any ] struct {
122+ type ExtraPayloads [HPtr HeaderHooks , BodyExtraPtr BodyHooks , SA any ] struct {
111123 Header pseudo.Accessor [* Header , HPtr ]
124+ Body pseudo.Accessor [* Body , BodyExtraPtr ]
112125 StateAccount pseudo.Accessor [StateOrSlimAccount , SA ] // Also provides [SlimAccount] access.
113126}
114127
115- func (ExtraPayloads [HPtr , SA ]) cloneStateAccount (s * StateAccountExtra ) * StateAccountExtra {
128+ func (ExtraPayloads [HPtr , BodyExtraPtr , SA ]) cloneStateAccount (s * StateAccountExtra ) * StateAccountExtra {
116129 v := pseudo.MustNewValue [SA ](s .t )
117130 return & StateAccountExtra {
118131 t : pseudo .From (v .Get ()).Type ,
0 commit comments