-
Notifications
You must be signed in to change notification settings - Fork 5
feat: types.StateAccount pseudo-generic payload
#44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 14 commits
854fa2d
08e0f2a
10eb6f8
bb4c914
095415f
0db9528
cda5afb
780a592
9925590
0d19b34
782f028
a981d54
1602fdb
5b15698
17022ce
f1a1c67
e2af2a6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -579,6 +579,7 @@ func (s *StateDB) getDeletedStateObject(addr common.Address) *stateObject { | |
| Balance: acc.Balance, | ||
| CodeHash: acc.CodeHash, | ||
| Root: common.BytesToHash(acc.Root), | ||
| Extra: acc.Extra, // no need to deep-copy as `acc` is short-lived | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this code is also removed upstream in upcoming revisions, fyi |
||
| } | ||
| if len(data.CodeHash) == 0 { | ||
| data.CodeHash = types.EmptyCodeHash.Bytes() | ||
|
|
||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // Copyright 2024 the libevm authors. | ||
| // | ||
| // The libevm additions to go-ethereum are free software: you can redistribute | ||
| // them and/or modify them under the terms of the GNU Lesser General Public License | ||
| // as published by the Free Software Foundation, either version 3 of the License, | ||
| // or (at your option) any later version. | ||
| // | ||
| // The libevm additions are distributed in the hope that they will be useful, | ||
| // but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser | ||
| // General Public License for more details. | ||
| // | ||
| // You should have received a copy of the GNU Lesser General Public License | ||
| // along with the go-ethereum library. If not, see | ||
| // <http://www.gnu.org/licenses/>. | ||
|
|
||
| package types | ||
|
|
||
| import ( | ||
| "io" | ||
|
|
||
| "github.com/ethereum/go-ethereum/libevm/pseudo" | ||
| "github.com/ethereum/go-ethereum/rlp" | ||
| ) | ||
|
|
||
| type Extras[SA any] struct{} | ||
|
|
||
| func RegisterExtras[SA any](extras Extras[SA]) { | ||
| if registeredExtras != nil { | ||
| panic("re-registration of Extras") | ||
| } | ||
| registeredExtras = &extraConstructors{ | ||
| newStateAccount: pseudo.NewConstructor[SA]().Zero, | ||
| cloneStateAccount: extras.cloneStateAccount, | ||
| } | ||
| } | ||
|
|
||
| func (e Extras[SA]) cloneStateAccount(s *StateAccountExtra) *StateAccountExtra { | ||
| v := pseudo.MustNewValue[SA](s.t) | ||
| return &StateAccountExtra{ | ||
| t: pseudo.From(v.Get()).Type, | ||
| } | ||
| } | ||
|
|
||
| var registeredExtras *extraConstructors | ||
|
|
||
| type extraConstructors struct { | ||
| newStateAccount func() *pseudo.Type | ||
| cloneStateAccount func(*StateAccountExtra) *StateAccountExtra | ||
| } | ||
|
|
||
| type StateAccountExtra struct { | ||
| t *pseudo.Type | ||
| } | ||
|
|
||
| func (e *StateAccountExtra) clone() *StateAccountExtra { | ||
| switch r := registeredExtras; { | ||
| case r == nil, e == nil: | ||
| return nil | ||
| default: | ||
| return r.cloneStateAccount(e) | ||
| } | ||
| } | ||
|
|
||
| var _ interface { | ||
| rlp.Encoder | ||
| rlp.Decoder | ||
| } = (*StateAccountExtra)(nil) | ||
|
|
||
| func (e *StateAccountExtra) EncodeRLP(w io.Writer) error { | ||
| switch r := registeredExtras; { | ||
| case r == nil: | ||
| return nil | ||
| case e == nil: | ||
| e = &StateAccountExtra{} | ||
| fallthrough | ||
| case e.t == nil: | ||
| e.t = r.newStateAccount() | ||
| } | ||
| return e.t.EncodeRLP(w) | ||
| } | ||
|
|
||
| func (e *StateAccountExtra) DecodeRLP(s *rlp.Stream) error { | ||
| switch r := registeredExtras; { | ||
| case r == nil: | ||
| return nil | ||
| case e.t == nil: | ||
| e.t = r.newStateAccount() | ||
| fallthrough | ||
| default: | ||
| return s.Decode(e.t) | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.