diff --git a/accounts/abi/bind/bind.go b/accounts/abi/abigen/bind.go
similarity index 98%
rename from accounts/abi/bind/bind.go
rename to accounts/abi/abigen/bind.go
index 020fec750e..42653c4fe1 100644
--- a/accounts/abi/bind/bind.go
+++ b/accounts/abi/abigen/bind.go
@@ -14,11 +14,11 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see .
-// Package bind generates Ethereum contract Go bindings.
+// Package abigen generates Ethereum contract Go bindings.
//
// Detailed usage document and tutorial available on the go-ethereum Wiki page:
-// https://github.com/ethereum/go-ethereum/wiki/Native-DApps:-Go-bindings-to-Ethereum-contracts
-package bind
+// https://geth.ethereum.org/docs/developers/dapp-developer/native-bindings
+package abigen
import (
"bytes"
diff --git a/accounts/abi/bind/bind_test.go b/accounts/abi/abigen/bind_test.go
similarity index 99%
rename from accounts/abi/bind/bind_test.go
rename to accounts/abi/abigen/bind_test.go
index a1533f689a..4812654dd9 100644
--- a/accounts/abi/bind/bind_test.go
+++ b/accounts/abi/abigen/bind_test.go
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see .
-package bind
+package abigen
import (
"fmt"
@@ -2079,13 +2079,15 @@ func TestBindings(t *testing.T) {
if !common.FileExist(gocmd) {
t.Skip("go sdk not found for testing")
}
- // Create a temporary workspace for the test suite
- ws := t.TempDir()
+ // Create a temporary workspace for the test suite
+ ws, _ := os.MkdirTemp("", "abigen")
pkg := filepath.Join(ws, "bindtest")
if err := os.MkdirAll(pkg, 0700); err != nil {
t.Fatalf("failed to create package: %v", err)
}
+ t.Log("tmpdir", pkg)
+
// Generate the test suite for all the contracts
for i, tt := range bindTests {
t.Run(tt.name, func(t *testing.T) {
diff --git a/accounts/abi/bind/bindv2.go b/accounts/abi/abigen/bindv2.go
similarity index 92%
rename from accounts/abi/bind/bindv2.go
rename to accounts/abi/abigen/bindv2.go
index 9fd353ec11..0c8d36ddbb 100644
--- a/accounts/abi/bind/bindv2.go
+++ b/accounts/abi/abigen/bindv2.go
@@ -1,4 +1,20 @@
-package bind
+// Copyright 2024 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it 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 go-ethereum library is distributed in the hope that it 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 .
+
+package abigen
import (
"bytes"
diff --git a/accounts/abi/bind/bindv2_test.go b/accounts/abi/abigen/bindv2_test.go
similarity index 98%
rename from accounts/abi/bind/bindv2_test.go
rename to accounts/abi/abigen/bindv2_test.go
index 0374eecaa5..ac51cfbca9 100644
--- a/accounts/abi/bind/bindv2_test.go
+++ b/accounts/abi/abigen/bindv2_test.go
@@ -1,7 +1,22 @@
-package bind
+// Copyright 2024 The go-ethereum Authors
+// This file is part of the go-ethereum library.
+//
+// The go-ethereum library is free software: you can redistribute it and/or modify
+// it 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 go-ethereum library is distributed in the hope that it 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 .
+
+package abigen
import (
- _ "embed"
"fmt"
"os"
"strings"
@@ -249,7 +264,7 @@ var bindTests2 = []bindV2Test{
// that no mutations occurred compared to the expected output included under internal/convertedv1bindtests.
func TestBindingV2ConvertedV1Tests(t *testing.T) {
for _, tc := range bindTests2 {
- fname := fmt.Sprintf("v2/internal/convertedv1bindtests/%v.go", strings.ToLower(tc.name))
+ fname := fmt.Sprintf("testdata/v2/%v.go.txt", strings.ToLower(tc.name))
t.Run(tc.name, func(t *testing.T) {
if tc.types == nil {
tc.types = []string{tc.name}
diff --git a/accounts/abi/bind/source.go.tpl b/accounts/abi/abigen/source.go.tpl
similarity index 100%
rename from accounts/abi/bind/source.go.tpl
rename to accounts/abi/abigen/source.go.tpl
diff --git a/accounts/abi/bind/source2.go.tpl b/accounts/abi/abigen/source2.go.tpl
similarity index 100%
rename from accounts/abi/bind/source2.go.tpl
rename to accounts/abi/abigen/source2.go.tpl
diff --git a/accounts/abi/bind/template.go b/accounts/abi/abigen/template.go
similarity index 99%
rename from accounts/abi/bind/template.go
rename to accounts/abi/abigen/template.go
index 1eb95a6dcc..9b918e3fd6 100644
--- a/accounts/abi/bind/template.go
+++ b/accounts/abi/abigen/template.go
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see .
-package bind
+package abigen
import (
_ "embed"
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/callbackparam.go b/accounts/abi/abigen/testdata/v2/callbackparam.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/callbackparam.go
rename to accounts/abi/abigen/testdata/v2/callbackparam.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/crowdsale.go b/accounts/abi/abigen/testdata/v2/crowdsale.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/crowdsale.go
rename to accounts/abi/abigen/testdata/v2/crowdsale.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/dao.go b/accounts/abi/abigen/testdata/v2/dao.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/dao.go
rename to accounts/abi/abigen/testdata/v2/dao.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/deeplynestedarray.go b/accounts/abi/abigen/testdata/v2/deeplynestedarray.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/deeplynestedarray.go
rename to accounts/abi/abigen/testdata/v2/deeplynestedarray.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/empty.go b/accounts/abi/abigen/testdata/v2/empty.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/empty.go
rename to accounts/abi/abigen/testdata/v2/empty.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/eventchecker.go b/accounts/abi/abigen/testdata/v2/eventchecker.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/eventchecker.go
rename to accounts/abi/abigen/testdata/v2/eventchecker.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/getter.go b/accounts/abi/abigen/testdata/v2/getter.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/getter.go
rename to accounts/abi/abigen/testdata/v2/getter.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/identifiercollision.go b/accounts/abi/abigen/testdata/v2/identifiercollision.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/identifiercollision.go
rename to accounts/abi/abigen/testdata/v2/identifiercollision.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/inputchecker.go b/accounts/abi/abigen/testdata/v2/inputchecker.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/inputchecker.go
rename to accounts/abi/abigen/testdata/v2/inputchecker.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/interactor.go b/accounts/abi/abigen/testdata/v2/interactor.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/interactor.go
rename to accounts/abi/abigen/testdata/v2/interactor.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/nameconflict.go b/accounts/abi/abigen/testdata/v2/nameconflict.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/nameconflict.go
rename to accounts/abi/abigen/testdata/v2/nameconflict.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/numericmethodname.go b/accounts/abi/abigen/testdata/v2/numericmethodname.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/numericmethodname.go
rename to accounts/abi/abigen/testdata/v2/numericmethodname.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/outputchecker.go b/accounts/abi/abigen/testdata/v2/outputchecker.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/outputchecker.go
rename to accounts/abi/abigen/testdata/v2/outputchecker.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/overload.go b/accounts/abi/abigen/testdata/v2/overload.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/overload.go
rename to accounts/abi/abigen/testdata/v2/overload.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/rangekeyword.go b/accounts/abi/abigen/testdata/v2/rangekeyword.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/rangekeyword.go
rename to accounts/abi/abigen/testdata/v2/rangekeyword.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/slicer.go b/accounts/abi/abigen/testdata/v2/slicer.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/slicer.go
rename to accounts/abi/abigen/testdata/v2/slicer.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/structs.go b/accounts/abi/abigen/testdata/v2/structs.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/structs.go
rename to accounts/abi/abigen/testdata/v2/structs.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/token.go b/accounts/abi/abigen/testdata/v2/token.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/token.go
rename to accounts/abi/abigen/testdata/v2/token.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/tuple.go b/accounts/abi/abigen/testdata/v2/tuple.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/tuple.go
rename to accounts/abi/abigen/testdata/v2/tuple.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/tupler.go b/accounts/abi/abigen/testdata/v2/tupler.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/tupler.go
rename to accounts/abi/abigen/testdata/v2/tupler.go.txt
diff --git a/accounts/abi/bind/v2/internal/convertedv1bindtests/underscorer.go b/accounts/abi/abigen/testdata/v2/underscorer.go.txt
similarity index 100%
rename from accounts/abi/bind/v2/internal/convertedv1bindtests/underscorer.go
rename to accounts/abi/abigen/testdata/v2/underscorer.go.txt
diff --git a/accounts/abi/bind/util.go b/accounts/abi/bind/util.go
index c83116e9a1..a6ceede116 100644
--- a/accounts/abi/bind/util.go
+++ b/accounts/abi/bind/util.go
@@ -22,11 +22,18 @@ import (
"time"
"github.com/ethereum/go-ethereum"
+ "github.com/ethereum/go-ethereum/accounts/abi/abigen"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/log"
)
+// Bind generates a v1 contract binding.
+// Deprecated: binding generation has moved to github.com/ethereum/go-ethereum/accounts/abi/abigen
+func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, libs map[string]string, aliases map[string]string) (string, error) {
+ return abigen.Bind(types, abis, bytecodes, fsigs, pkg, libs, aliases)
+}
+
// WaitMined waits for tx to be mined on the blockchain.
// It stops waiting when the context is canceled.
func WaitMined(ctx context.Context, b DeployBackend, tx *types.Transaction) (*types.Receipt, error) {
diff --git a/accounts/abi/bind/v2/generate_test.go b/accounts/abi/bind/v2/generate_test.go
index 4c42e477d4..ae35e0b475 100644
--- a/accounts/abi/bind/v2/generate_test.go
+++ b/accounts/abi/bind/v2/generate_test.go
@@ -23,12 +23,14 @@ import (
"strings"
"testing"
- bind1 "github.com/ethereum/go-ethereum/accounts/abi/bind"
+ "github.com/ethereum/go-ethereum/accounts/abi/abigen"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/crypto"
)
+// Run go generate to recreate the test bindings.
+//
//go:generate go run github.com/ethereum/go-ethereum/cmd/abigen -v2 -combined-json internal/contracts/db/combined-abi.json -type DBStats -pkg db -out internal/contracts/db/bindings.go
//go:generate go run github.com/ethereum/go-ethereum/cmd/abigen -v2 -combined-json internal/contracts/events/combined-abi.json -type C -pkg events -out internal/contracts/events/bindings.go
//go:generate go run github.com/ethereum/go-ethereum/cmd/abigen -v2 -combined-json internal/contracts/nested_libraries/combined-abi.json -type C1 -pkg nested_libraries -out internal/contracts/nested_libraries/bindings.go
@@ -84,7 +86,7 @@ func TestBindingGeneration(t *testing.T) {
libPattern := crypto.Keccak256Hash([]byte(name)).String()[2:36] // the first 2 chars are 0x
libs[libPattern] = typeName
}
- code, err := bind1.BindV2(types, abis, bins, dir, libs, make(map[string]string))
+ code, err := abigen.BindV2(types, abis, bins, dir, libs, make(map[string]string))
if err != nil {
t.Fatalf("error creating bindings for package %s: %v", dir, err)
}
diff --git a/cmd/abigen/main.go b/cmd/abigen/main.go
index d573176372..56f2170aa9 100644
--- a/cmd/abigen/main.go
+++ b/cmd/abigen/main.go
@@ -24,7 +24,7 @@ import (
"regexp"
"strings"
- "github.com/ethereum/go-ethereum/accounts/abi/bind"
+ "github.com/ethereum/go-ethereum/accounts/abi/abigen"
"github.com/ethereum/go-ethereum/cmd/utils"
"github.com/ethereum/go-ethereum/common/compiler"
"github.com/ethereum/go-ethereum/crypto"
@@ -88,10 +88,10 @@ func init() {
aliasFlag,
v2Flag,
}
- app.Action = abigen
+ app.Action = generate
}
-func abigen(c *cli.Context) error {
+func generate(c *cli.Context) error {
utils.CheckExclusive(c, abiFlag, jsonFlag) // Only one source can be selected.
if c.String(pkgFlag.Name) == "" {
@@ -213,9 +213,9 @@ func abigen(c *cli.Context) error {
err error
)
if c.IsSet(v2Flag.Name) {
- code, err = bind.BindV2(types, abis, bins, c.String(pkgFlag.Name), libs, aliases)
+ code, err = abigen.BindV2(types, abis, bins, c.String(pkgFlag.Name), libs, aliases)
} else {
- code, err = bind.Bind(types, abis, bins, sigs, c.String(pkgFlag.Name), libs, aliases)
+ code, err = abigen.Bind(types, abis, bins, sigs, c.String(pkgFlag.Name), libs, aliases)
}
if err != nil {
utils.Fatalf("Failed to generate ABI binding: %v", err)