Skip to content

Migrate from accounts/abi/bind to accounts/abi/bind/v2#10

Merged
bobg merged 18 commits into
ethereum-portfrom
copilot/migrate-to-go-ethereum-bind-v2
May 13, 2026
Merged

Migrate from accounts/abi/bind to accounts/abi/bind/v2#10
bobg merged 18 commits into
ethereum-portfrom
copilot/migrate-to-go-ethereum-bind-v2

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 5, 2026

Migrates the codebase from the deprecated github.com/ethereum/go-ethereum/accounts/abi/bind package to github.com/ethereum/go-ethereum/accounts/abi/bind/v2.

Summary of changes

The v2 bind package uses a different code-generation model: instead of per-contract types with bound backends, the generated code provides pack/unpack helpers while bind.BoundContract (created via .Instance(backend, addr)) serves as the runtime handle.

Generated bindings (contract/)

  • Regenerated erc20.go and tredd.go with abigen --v2
  • Updated Taskfile.yml to pass --v2 to both abigen commands
  • TreddABI string variable is replaced by TreddMetaData.ABI

Core library (tx.go)

  • DeployTredd(opts, client, ...)bind.DeployContract(opts, bytecode, client, constructorInput)
  • NewTredd(addr, client)treddABI.Instance(client, addr) returning *bind.BoundContract
  • All contract method calls (con.Cancel(opts), etc.) → bind.Transact(con, opts, treddABI.PackCancel())
  • All contract reads (con.MTokenType(callOpts)) → bind.Call(con, callOpts, treddABI.PackMTokenType(), treddABI.UnpackMTokenType)
  • bind.WaitMined(ctx, client, tx)bind.WaitMined(ctx, client, tx.Hash())
  • Return types of ProposePayment, RevealKey, Cancel, ClaimRefund changed from *contract.Tredd to *bind.BoundContract

Test harness (testutil/harness.go)

  • bind.NewKeyedTransactorWithChainIDbind.NewKeyedTransactor (v2 always requires a chain ID)
  • Removed accounts/abi/bind/backends.SimulatedBackend; added a local testClient struct that embeds *simulated.Backend (for Commit()) and simulated.Client (for ContractBackend methods), preserving the behaviour that waitMined uses to auto-commit on the simulated chain
  • Deploy logic updated to use the v2 deploy API

Contract tests (contract_test.go)

  • Updated all harness.Contract.Method(...) calls to use bind.Call/bind.Transact with the generated pack/unpack helpers

Command (cmd/tredd/)

  • args.go: replaced bind.NewTransactor(keyReader, passphrase) (removed in v2) with explicit keystore decryption via accounts/keystore.DecryptKey + bind.NewKeyedTransactor(key.PrivateKey, chainID). The chainID is now a required parameter.
  • client.go and server.go: Ethereum client connection is established first so the chain ID can be fetched; handleKeyfilePassphrase is then called with the chain ID. WatchEvDecryptionKey is replaced with bind.WatchEvents. queueClaimPaymentHelper parameter type updated from *contract.Tredd to *bind.BoundContract.
  • main.go: contract.TreddABIcontract.TreddMetaData.ABI

Try.md

No changes required: all user-facing CLI flags and the documented workflow are unchanged.

@bobg bobg changed the base branch from master to ethereum-port May 5, 2026 04:58
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Coverage Report for CI Build 25532727102

Coverage increased (+1.3%) to 11.636%

Details

  • Coverage increased (+1.3%) from the base build.
  • Patch coverage: 551 uncovered changes across 11 files (40 of 591 lines covered, 6.77%).
  • 54 coverage regressions across 10 files.

Uncovered Changes

Top 10 Files by Coverage Impact Changed Covered %
contract/tredd.go 250 0 0.0%
contract/erc20.go 119 0 0.0%
contract/instance.go 60 0 0.0%
testutil/harness.go 35 0 0.0%
cmd/tredd/server.go 24 0 0.0%
cmd/tredd/client.go 22 0 0.0%
cmd/tredd/args.go 14 0 0.0%
cmd/tredd/filechunks.go 10 0 0.0%
cmd/tredd/main.go 10 0 0.0%
tx.go 31 25 80.65%

Coverage Regressions

54 previously-covered lines in 10 files lost coverage.

File Lines Losing Coverage Coverage
contract/tredd.go 27 0.0%
contract/erc20.go 15 0.0%
stream.go 4 68.29%
tx.go 2 60.53%
cmd/tredd/client.go 1 0.0%
cmd/tredd/filechunks.go 1 0.0%
cmd/tredd/main.go 1 0.0%
cmd/tredd/server.go 1 0.0%
decrypt.go 1 51.85%
testutil/harness.go 1 0.0%

Coverage Stats

Coverage Status
Relevant Lines: 1693
Covered Lines: 197
Line Coverage: 11.64%
Coverage Strength: 0.12 hits per line

💛 - Coveralls

@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 5, 2026

Modver result

This report was generated by Modver,
a Go package and command that helps you obey semantic versioning rules in your Go module.

This PR requires an increase in your module’s major version number.
If the new major version number is 2 or greater,
you must also add or update the version suffix
on the module path defined in your go.mod file.
See the Go Modules Reference for more info.

checking Cancel
  in parameters of func(ctx context.Context, client github.com/bobg/tredd.clientType, buyer *github.com/ethereum/go-ethereum/accounts/abi/bind.TransactOpts, con *github.com/bobg/tredd/contract.Tredd) (*github.com/ethereum/go-ethereum/core/types.Receipt, error)
    github.com/bobg/tredd/contract.Tredd went from package github.com/bobg/tredd/contract to package github.com/ethereum/go-ethereum/accounts/abi/bind/v2
      Major

@bobg bobg closed this May 5, 2026
@bobg bobg reopened this May 5, 2026
@bobg bobg marked this pull request as ready for review May 6, 2026 19:51
@bobg bobg merged commit c63b8c7 into ethereum-port May 13, 2026
1 check passed
@bobg bobg deleted the copilot/migrate-to-go-ethereum-bind-v2 branch May 13, 2026 02:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants