Skip to content

Commit 3add47b

Browse files
committed
Shared extraPayloadOrSetDefault for extraPayload() functions
1 parent 2e73933 commit 3add47b

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

core/types/rlp_payload.libevm.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,27 @@ type extraConstructors struct {
108108
}
109109

110110
func (h *Header) extraPayload() *pseudo.Type {
111-
r := registeredExtras
112-
if !r.Registered() {
113-
// See params.ChainConfig.extraPayload() for panic rationale.
114-
panic(fmt.Sprintf("%T.extraPayload() called before RegisterExtras()", r))
115-
}
116-
if h.extra == nil {
117-
h.extra = r.Get().newHeader()
118-
}
119-
return h.extra
111+
return extraPayloadOrSetDefault(&h.extra, func(c *extraConstructors) *pseudo.Type {
112+
return c.newHeader()
113+
})
120114
}
121115

122116
func (b *Body) extraPayload() *pseudo.Type {
117+
return extraPayloadOrSetDefault(&b.extra, func(c *extraConstructors) *pseudo.Type {
118+
return c.newBody()
119+
})
120+
}
121+
122+
func extraPayloadOrSetDefault(field **pseudo.Type, construct func(*extraConstructors) *pseudo.Type) *pseudo.Type {
123123
r := registeredExtras
124124
if !r.Registered() {
125125
// See params.ChainConfig.extraPayload() for panic rationale.
126-
panic(fmt.Sprintf("%T.extraPayload() called before RegisterExtras()", r))
126+
panic("<T>.extraPayload() called before RegisterExtras()")
127127
}
128-
if b.extra == nil {
129-
b.extra = r.Get().newBody()
128+
if *field == nil {
129+
*field = construct(r.Get())
130130
}
131-
return b.extra
131+
return *field
132132
}
133133

134134
// hooks returns the [Header]'s registered [HeaderHooks], if any, otherwise a

0 commit comments

Comments
 (0)