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:
Guillaume Ballet
2019-07-02 09:52:58 +02:00
committed by GitHub
parent 0b26a826e9
commit 6bf5555c4f
6 changed files with 100 additions and 14 deletions

View File

@ -44,7 +44,7 @@ const (
// 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
// 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
contracts := make(map[string]*tmplContract)
@ -125,6 +125,9 @@ func Bind(types []string, abis []string, bytecodes []string, pkg string, lang La
Transacts: transacts,
Events: events,
}
if len(fsigs) > i {
contracts[types[i]].FuncSigs = fsigs[i]
}
}
// Generate the contract template data content and render it
data := &tmplData{
@ -180,8 +183,7 @@ func bindBasicTypeGo(kind abi.Type) string {
case abi.BytesTy:
return "[]byte"
case abi.FunctionTy:
// todo(rjl493456442)
return ""
return "[24]byte"
default:
// string, bool types
return kind.String()
@ -240,8 +242,7 @@ func bindBasicTypeJava(kind abi.Type) string {
case abi.StringTy:
return "String"
case abi.FunctionTy:
// todo(rjl493456442)
return ""
return "byte[24]"
default:
return kind.String()
}

File diff suppressed because one or more lines are too long

View File

@ -29,6 +29,7 @@ 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
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
Calls map[string]*tmplMethod // Contract calls that only read 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.
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}}
// {{.Type}}Bin is the compiled bytecode used for deploying new contracts.
const {{.Type}}Bin = ` + "`" + `{{.InputBin}}` + "`" + `
@ -464,12 +474,23 @@ const tmplSourceJava = `
package {{.Package}};
import org.ethereum.geth.*;
import java.util.*;
{{range $contract := .Contracts}}
public class {{.Type}} {
// ABI is the input ABI used to generate the binding from.
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}}
// BYTECODE is the compiled bytecode used for deploying new contracts.
public final static String BYTECODE = "0x{{.InputBin}}";