From fd3bb352fe9b85dedb5cb55a550df5742ae75790 Mon Sep 17 00:00:00 2001 From: Felix Lange Date: Tue, 28 Jan 2025 00:52:20 +0100 Subject: [PATCH] accounts/abi/bind: make MetaData independent of v2 --- accounts/abi/bind/old.go | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/accounts/abi/bind/old.go b/accounts/abi/bind/old.go index b79144effe..5fe7bb13d8 100644 --- a/accounts/abi/bind/old.go +++ b/accounts/abi/bind/old.go @@ -24,6 +24,8 @@ import ( "errors" "io" "math/big" + "strings" + "sync" "github.com/ethereum/go-ethereum/accounts" "github.com/ethereum/go-ethereum/accounts/abi" @@ -228,10 +230,28 @@ func DeployContract(opts *TransactOpts, abi abi.ABI, bytecode []byte, backend Co return bind2.DeployContract(opts, abi, bytecode, backend, params...) } -type MetaData bind2.MetaData +// MetaData collects all metadata for a bound contract. +type MetaData struct { + Bin string // runtime bytecode (as a hex string) + ABI string // the raw ABI definition (JSON) + Sigs map[string]string // 4byte identifier -> function signature + mu sync.Mutex + parsedABI *abi.ABI +} +// GetAbi returns the parsed ABI definition. func (m *MetaData) GetAbi() (*abi.ABI, error) { - return (*bind2.MetaData)(m).ParseABI() + m.mu.Lock() + defer m.mu.Unlock() + if m.parsedABI != nil { + return m.parsedABI, nil + } + if parsed, err := abi.JSON(strings.NewReader(m.ABI)); err != nil { + return nil, err + } else { + m.parsedABI = &parsed + } + return m.parsedABI, nil } // util.go