-
Notifications
You must be signed in to change notification settings - Fork 238
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
refactor: align accounts/abi/bind with coreth+upstream #1427
base: master
Are you sure you want to change the base?
Changes from all commits
d1919a3
282abdf
5f35962
6702be9
92607ed
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// (c) 2025, Ava Labs, Inc. All rights reserved. | ||
// See the file LICENSE for licensing terms. | ||
|
||
package bind | ||
|
||
import ( | ||
"fmt" | ||
"regexp" | ||
|
||
"github.com/ava-labs/subnet-evm/accounts/abi" | ||
) | ||
|
||
type ( | ||
// These types are exported for use in bind/precompilebind | ||
TmplContract = tmplContract | ||
TmplMethod = tmplMethod | ||
TmplStruct = tmplStruct | ||
) | ||
|
||
// BindHook is a callback function that can be used to customize the binding. | ||
type BindHook func(lang Lang, pkg string, types []string, contracts map[string]*tmplContract, structs map[string]*tmplStruct) (data any, templateSource string, err error) | ||
|
||
func IsKeyWord(arg string) bool { | ||
return isKeyWord(arg) | ||
} | ||
|
||
var bindTypeNew = map[Lang]func(kind abi.Type, structs map[string]*tmplStruct) string{ | ||
LangGo: bindTypeNewGo, | ||
} | ||
|
||
// bindTypeNewGo converts new types to Go ones. | ||
func bindTypeNewGo(kind abi.Type, structs map[string]*tmplStruct) string { | ||
switch kind.T { | ||
case abi.TupleTy: | ||
return structs[kind.TupleRawName+kind.String()].Name + "{}" | ||
case abi.ArrayTy: | ||
return fmt.Sprintf("[%d]", kind.Size) + bindTypeGo(*kind.Elem, structs) + "{}" | ||
case abi.SliceTy: | ||
return "nil" | ||
case abi.AddressTy: | ||
return "common.Address{}" | ||
case abi.IntTy, abi.UintTy: | ||
parts := regexp.MustCompile(`(u)?int([0-9]*)`).FindStringSubmatch(kind.String()) | ||
switch parts[2] { | ||
case "8", "16", "32", "64": | ||
return "0" | ||
} | ||
return "new(big.Int)" | ||
case abi.FixedBytesTy: | ||
return fmt.Sprintf("[%d]byte", kind.Size) + "{}" | ||
case abi.BytesTy: | ||
return "[]byte{}" | ||
case abi.FunctionTy: | ||
return "[24]byte{}" | ||
case abi.BoolTy: | ||
return "false" | ||
case abi.StringTy: | ||
return `""` | ||
default: | ||
return "nil" | ||
} | ||
} | ||
|
||
func mkList(args ...any) []any { | ||
return args | ||
} | ||
|
||
func add(a, b int) int { | ||
return a + b | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,7 +319,7 @@ func (t *tester) generate(parent common.Hash) (common.Hash, *trienode.MergedNode | |
return root, ctx.nodes, triestate.New(ctx.accountOrigin, ctx.storageOrigin, nil) | ||
} | ||
|
||
// lastRoot returns the latest root hash, or empty if nothing is cached. | ||
// lastHash returns the latest root hash, or empty if nothing is cached. | ||
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 is a typo in geth, I propose we revert this, however, if you want, I can be the typo comment man and accumulate these in a branch on the libevm repository, that we can PR to geth when it gets large enough? 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. Coreth already contains this typo fix, so I suppose why not then. Ideally we should revert the fix in coreth but that seems like a lot of trouble for just this. Anyway, I opened ava-labs/libevm#108 feel free to commit to it when you find a geth code typo. 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. Same as above, here I'm just trying to reduce the difference in our repos. |
||
func (t *tester) lastHash() common.Hash { | ||
if len(t.roots) == 0 { | ||
return common.Hash{} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the removal? The geth files seem to have no copyright at all, so I'm not sure why we would modify this 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to match coreth.