forked from cerc-io/plugeth
accounts/abi/bind: Accept function ptr parameter (#19755)
* accounts/abi/bind: Accept function ptr parameter They are translated as [24]byte * Add Java template version * accounts/abi/bind: fix merge issue * Fix CI
This commit is contained in:
parent
0b26a826e9
commit
6bf5555c4f
@ -44,7 +44,7 @@ const (
|
|||||||
// to be used as is in client code, but rather as an intermediate struct which
|
// to be used as is in client code, but rather as an intermediate struct which
|
||||||
// enforces compile time type safety and naming convention opposed to having to
|
// enforces compile time type safety and naming convention opposed to having to
|
||||||
// manually maintain hard coded strings that break on runtime.
|
// manually maintain hard coded strings that break on runtime.
|
||||||
func Bind(types []string, abis []string, bytecodes []string, pkg string, lang Lang) (string, error) {
|
func Bind(types []string, abis []string, bytecodes []string, fsigs []map[string]string, pkg string, lang Lang) (string, error) {
|
||||||
// Process each individual contract requested binding
|
// Process each individual contract requested binding
|
||||||
contracts := make(map[string]*tmplContract)
|
contracts := make(map[string]*tmplContract)
|
||||||
|
|
||||||
@ -125,6 +125,9 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
|
|||||||
Transacts: transacts,
|
Transacts: transacts,
|
||||||
Events: events,
|
Events: events,
|
||||||
}
|
}
|
||||||
|
if len(fsigs) > i {
|
||||||
|
contracts[types[i]].FuncSigs = fsigs[i]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Generate the contract template data content and render it
|
// Generate the contract template data content and render it
|
||||||
data := &tmplData{
|
data := &tmplData{
|
||||||
@ -180,8 +183,7 @@ func bindBasicTypeGo(kind abi.Type) string {
|
|||||||
case abi.BytesTy:
|
case abi.BytesTy:
|
||||||
return "[]byte"
|
return "[]byte"
|
||||||
case abi.FunctionTy:
|
case abi.FunctionTy:
|
||||||
// todo(rjl493456442)
|
return "[24]byte"
|
||||||
return ""
|
|
||||||
default:
|
default:
|
||||||
// string, bool types
|
// string, bool types
|
||||||
return kind.String()
|
return kind.String()
|
||||||
@ -240,8 +242,7 @@ func bindBasicTypeJava(kind abi.Type) string {
|
|||||||
case abi.StringTy:
|
case abi.StringTy:
|
||||||
return "String"
|
return "String"
|
||||||
case abi.FunctionTy:
|
case abi.FunctionTy:
|
||||||
// todo(rjl493456442)
|
return "byte[24]"
|
||||||
return ""
|
|
||||||
default:
|
default:
|
||||||
return kind.String()
|
return kind.String()
|
||||||
}
|
}
|
||||||
|
File diff suppressed because one or more lines are too long
@ -29,6 +29,7 @@ type tmplContract struct {
|
|||||||
Type string // Type name of the main contract binding
|
Type string // Type name of the main contract binding
|
||||||
InputABI string // JSON ABI used as the input to generate the binding from
|
InputABI string // JSON ABI used as the input to generate the binding from
|
||||||
InputBin string // Optional EVM bytecode used to denetare deploy code from
|
InputBin string // Optional EVM bytecode used to denetare deploy code from
|
||||||
|
FuncSigs map[string]string // Optional map: string signature -> 4-byte signature
|
||||||
Constructor abi.Method // Contract constructor for deploy parametrization
|
Constructor abi.Method // Contract constructor for deploy parametrization
|
||||||
Calls map[string]*tmplMethod // Contract calls that only read state data
|
Calls map[string]*tmplMethod // Contract calls that only read state data
|
||||||
Transacts map[string]*tmplMethod // Contract calls that write state data
|
Transacts map[string]*tmplMethod // Contract calls that write state data
|
||||||
@ -92,6 +93,15 @@ var (
|
|||||||
// {{.Type}}ABI is the input ABI used to generate the binding from.
|
// {{.Type}}ABI is the input ABI used to generate the binding from.
|
||||||
const {{.Type}}ABI = "{{.InputABI}}"
|
const {{.Type}}ABI = "{{.InputABI}}"
|
||||||
|
|
||||||
|
{{if $contract.FuncSigs}}
|
||||||
|
// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
|
||||||
|
var {{.Type}}FuncSigs = map[string]string{
|
||||||
|
{{range $strsig, $binsig := .FuncSigs}}
|
||||||
|
"{{$binsig}}": "{{$strsig}}",
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
{{if .InputBin}}
|
{{if .InputBin}}
|
||||||
// {{.Type}}Bin is the compiled bytecode used for deploying new contracts.
|
// {{.Type}}Bin is the compiled bytecode used for deploying new contracts.
|
||||||
const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + `
|
const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + `
|
||||||
@ -464,12 +474,23 @@ const tmplSourceJava = `
|
|||||||
package {{.Package}};
|
package {{.Package}};
|
||||||
|
|
||||||
import org.ethereum.geth.*;
|
import org.ethereum.geth.*;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
{{range $contract := .Contracts}}
|
{{range $contract := .Contracts}}
|
||||||
public class {{.Type}} {
|
public class {{.Type}} {
|
||||||
// ABI is the input ABI used to generate the binding from.
|
// ABI is the input ABI used to generate the binding from.
|
||||||
public final static String ABI = "{{.InputABI}}";
|
public final static String ABI = "{{.InputABI}}";
|
||||||
|
{{if $contract.FuncSigs}}
|
||||||
|
// {{.Type}}FuncSigs maps the 4-byte function signature to its string representation.
|
||||||
|
public final static Map<String, String> {{.Type}}FuncSigs;
|
||||||
|
static {
|
||||||
|
Hashtable<String, String> temp = new Hashtable<String, String>();
|
||||||
|
{{range $strsig, $binsig := .FuncSigs}}
|
||||||
|
temp.put("{{$binsig}}", "{{$strsig}}");
|
||||||
|
{{end}}
|
||||||
|
{{.Type}}FuncSigs = Collections.unmodifiableMap(temp);
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
{{if .InputBin}}
|
{{if .InputBin}}
|
||||||
// BYTECODE is the compiled bytecode used for deploying new contracts.
|
// BYTECODE is the compiled bytecode used for deploying new contracts.
|
||||||
public final static String BYTECODE = "0x{{.InputBin}}";
|
public final static String BYTECODE = "0x{{.InputBin}}";
|
||||||
|
@ -78,6 +78,7 @@ func main() {
|
|||||||
abis []string
|
abis []string
|
||||||
bins []string
|
bins []string
|
||||||
types []string
|
types []string
|
||||||
|
sigs []map[string]string
|
||||||
)
|
)
|
||||||
if *solFlag != "" || *vyFlag != "" || *abiFlag == "-" {
|
if *solFlag != "" || *vyFlag != "" || *abiFlag == "-" {
|
||||||
// Generate the list of types to exclude from binding
|
// Generate the list of types to exclude from binding
|
||||||
@ -121,6 +122,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
abis = append(abis, string(abi))
|
abis = append(abis, string(abi))
|
||||||
bins = append(bins, contract.Code)
|
bins = append(bins, contract.Code)
|
||||||
|
sigs = append(sigs, contract.Hashes)
|
||||||
|
|
||||||
nameParts := strings.Split(name, ":")
|
nameParts := strings.Split(name, ":")
|
||||||
types = append(types, nameParts[len(nameParts)-1])
|
types = append(types, nameParts[len(nameParts)-1])
|
||||||
@ -151,7 +153,7 @@ func main() {
|
|||||||
types = append(types, kind)
|
types = append(types, kind)
|
||||||
}
|
}
|
||||||
// Generate the contract binding
|
// Generate the contract binding
|
||||||
code, err := bind.Bind(types, abis, bins, *pkgFlag, lang)
|
code, err := bind.Bind(types, abis, bins, sigs, *pkgFlag, lang)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Failed to generate ABI binding: %v\n", err)
|
fmt.Printf("Failed to generate ABI binding: %v\n", err)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
|
@ -27,9 +27,10 @@ var versionRegexp = regexp.MustCompile(`([0-9]+)\.([0-9]+)\.([0-9]+)`)
|
|||||||
|
|
||||||
// Contract contains information about a compiled contract, alongside its code and runtime code.
|
// Contract contains information about a compiled contract, alongside its code and runtime code.
|
||||||
type Contract struct {
|
type Contract struct {
|
||||||
Code string `json:"code"`
|
Code string `json:"code"`
|
||||||
RuntimeCode string `json:"runtime-code"`
|
RuntimeCode string `json:"runtime-code"`
|
||||||
Info ContractInfo `json:"info"`
|
Info ContractInfo `json:"info"`
|
||||||
|
Hashes map[string]string `json:"hashes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// ContractInfo contains information about a compiled contract, including access
|
// ContractInfo contains information about a compiled contract, including access
|
||||||
|
@ -39,6 +39,7 @@ type solcOutput struct {
|
|||||||
BinRuntime string `json:"bin-runtime"`
|
BinRuntime string `json:"bin-runtime"`
|
||||||
SrcMapRuntime string `json:"srcmap-runtime"`
|
SrcMapRuntime string `json:"srcmap-runtime"`
|
||||||
Bin, SrcMap, Abi, Devdoc, Userdoc, Metadata string
|
Bin, SrcMap, Abi, Devdoc, Userdoc, Metadata string
|
||||||
|
Hashes map[string]string
|
||||||
}
|
}
|
||||||
Version string
|
Version string
|
||||||
}
|
}
|
||||||
@ -49,7 +50,7 @@ func (s *Solidity) makeArgs() []string {
|
|||||||
"--optimize", // code optimizer switched on
|
"--optimize", // code optimizer switched on
|
||||||
}
|
}
|
||||||
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
if s.Major > 0 || s.Minor > 4 || s.Patch > 6 {
|
||||||
p[1] += ",metadata"
|
p[1] += ",metadata,hashes"
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@ -161,6 +162,7 @@ func ParseCombinedJSON(combinedJSON []byte, source string, languageVersion strin
|
|||||||
contracts[name] = &Contract{
|
contracts[name] = &Contract{
|
||||||
Code: "0x" + info.Bin,
|
Code: "0x" + info.Bin,
|
||||||
RuntimeCode: "0x" + info.BinRuntime,
|
RuntimeCode: "0x" + info.BinRuntime,
|
||||||
|
Hashes: info.Hashes,
|
||||||
Info: ContractInfo{
|
Info: ContractInfo{
|
||||||
Source: source,
|
Source: source,
|
||||||
Language: "Solidity",
|
Language: "Solidity",
|
||||||
|
Loading…
Reference in New Issue
Block a user