2016-03-21 14:34:49 +02:00
|
|
|
// Copyright 2016 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
package bind
|
|
|
|
|
2024-07-02 15:58:15 +03:00
|
|
|
import (
|
|
|
|
_ "embed"
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/abi"
|
|
|
|
)
|
2016-03-21 14:34:49 +02:00
|
|
|
|
|
|
|
// tmplData is the data structure required to fill the binding template.
|
|
|
|
type tmplData struct {
|
|
|
|
Package string // Name of the package to place the generated file in
|
|
|
|
Contracts map[string]*tmplContract // List of contracts to generate into this file
|
2019-07-08 11:27:05 +03:00
|
|
|
Libraries map[string]string // Map the bytecode's link pattern to the library name
|
2019-11-25 16:03:22 +03:00
|
|
|
Structs map[string]*tmplStruct // Contract struct type definitions
|
2016-03-21 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// tmplContract contains the data needed to generate an individual contract binding.
|
|
|
|
type tmplContract struct {
|
|
|
|
Type string // Type name of the main contract binding
|
|
|
|
InputABI string // JSON ABI used as the input to generate the binding from
|
2020-09-20 11:43:57 +03:00
|
|
|
InputBin string // Optional EVM bytecode used to generate deploy code from
|
2019-07-02 10:52:58 +03:00
|
|
|
FuncSigs map[string]string // Optional map: string signature -> 4-byte signature
|
2016-03-21 14:34:49 +02:00
|
|
|
Constructor abi.Method // Contract constructor for deploy parametrization
|
|
|
|
Calls map[string]*tmplMethod // Contract calls that only read state data
|
|
|
|
Transacts map[string]*tmplMethod // Contract calls that write state data
|
2020-04-15 10:23:58 +03:00
|
|
|
Fallback *tmplMethod // Additional special fallback function
|
|
|
|
Receive *tmplMethod // Additional special receive function
|
2018-01-05 13:39:24 +03:00
|
|
|
Events map[string]*tmplEvent // Contract events accessors
|
2019-07-08 11:27:05 +03:00
|
|
|
Libraries map[string]string // Same as tmplData, but filtered to only keep what the contract needs
|
2019-11-25 16:03:22 +03:00
|
|
|
Library bool // Indicator whether the contract is a library
|
2016-03-21 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// tmplMethod is a wrapper around an abi.Method that contains a few preprocessed
|
|
|
|
// and cached data fields.
|
|
|
|
type tmplMethod struct {
|
|
|
|
Original abi.Method // Original method as parsed by the abi package
|
|
|
|
Normalized abi.Method // Normalized version of the parsed method (capitalized names, non-anonymous args/returns)
|
2018-01-05 13:39:24 +03:00
|
|
|
Structured bool // Whether the returns should be accumulated into a struct
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:43:57 +03:00
|
|
|
// tmplEvent is a wrapper around an abi.Event that contains a few preprocessed
|
|
|
|
// and cached data fields.
|
2018-01-05 13:39:24 +03:00
|
|
|
type tmplEvent struct {
|
|
|
|
Original abi.Event // Original event as parsed by the abi package
|
|
|
|
Normalized abi.Event // Normalized version of the parsed fields
|
2016-03-21 14:34:49 +02:00
|
|
|
}
|
|
|
|
|
2019-07-03 13:17:43 +03:00
|
|
|
// tmplField is a wrapper around a struct field with binding language
|
|
|
|
// struct type definition and relative filed name.
|
|
|
|
type tmplField struct {
|
|
|
|
Type string // Field type representation depends on target binding language
|
|
|
|
Name string // Field name converted from the raw user-defined field name
|
|
|
|
SolKind abi.Type // Raw abi type information
|
|
|
|
}
|
|
|
|
|
2020-09-20 11:43:57 +03:00
|
|
|
// tmplStruct is a wrapper around an abi.tuple and contains an auto-generated
|
2019-07-03 13:17:43 +03:00
|
|
|
// struct name.
|
|
|
|
type tmplStruct struct {
|
2019-10-31 16:17:51 +03:00
|
|
|
Name string // Auto-generated struct name(before solidity v0.5.11) or raw name.
|
2019-07-03 13:17:43 +03:00
|
|
|
Fields []*tmplField // Struct fields definition depends on the binding language.
|
|
|
|
}
|
|
|
|
|
2016-09-05 19:07:57 +03:00
|
|
|
// tmplSource is language to template mapping containing all the supported
|
|
|
|
// programming languages the package can generate to.
|
|
|
|
var tmplSource = map[Lang]string{
|
2023-02-03 13:26:29 +03:00
|
|
|
LangGo: tmplSourceGo,
|
2016-09-05 19:07:57 +03:00
|
|
|
}
|
|
|
|
|
2020-09-20 11:43:57 +03:00
|
|
|
// tmplSourceGo is the Go source template that the generated Go contract binding
|
|
|
|
// is based on.
|
2024-07-02 15:58:15 +03:00
|
|
|
//
|
|
|
|
//go:embed source.go.tpl
|
|
|
|
var tmplSourceGo string
|