mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 10:52:25 +00:00
accounts/abi/bind, cmd/abigen: implement java binding tests
This commit is contained in:
parent
334ab967b2
commit
f038f8f3db
4 changed files with 472 additions and 78 deletions
|
|
@ -38,7 +38,6 @@ type Lang int
|
||||||
const (
|
const (
|
||||||
LangGo Lang = iota
|
LangGo Lang = iota
|
||||||
LangJava
|
LangJava
|
||||||
LangObjC
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
|
// Bind generates a Go wrapper around a contract ABI. This wrapper isn't meant
|
||||||
|
|
|
||||||
File diff suppressed because one or more lines are too long
|
|
@ -454,90 +454,90 @@ package {{.Package}};
|
||||||
import org.ethereum.geth.*;
|
import org.ethereum.geth.*;
|
||||||
|
|
||||||
{{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 .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}}";
|
||||||
|
|
||||||
// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
|
// deploy deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
|
||||||
public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
public static {{.Type}} deploy(TransactOpts auth, EthereumClient client{{range .Constructor.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||||
Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
|
Interfaces args = Geth.newInterfaces({{(len .Constructor.Inputs)}});
|
||||||
{{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
{{range $index, $element := .Constructor.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||||
{{end}}
|
|
||||||
return new {{.Type}}(Geth.deployContract(auth, ABI, Geth.decodeFromHex(BYTECODE), client, args));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Internal constructor used by contract deployment.
|
|
||||||
private {{.Type}}(BoundContract deployment) {
|
|
||||||
this.Address = deployment.getAddress();
|
|
||||||
this.Deployer = deployment.getDeployer();
|
|
||||||
this.Contract = deployment;
|
|
||||||
}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
|
return new {{.Type}}(Geth.deployContract(auth, ABI, Geth.decodeFromHex(BYTECODE), client, args));
|
||||||
|
}
|
||||||
|
|
||||||
// Ethereum address where this contract is located at.
|
// Internal constructor used by contract deployment.
|
||||||
public final Address Address;
|
private {{.Type}}(BoundContract deployment) {
|
||||||
|
this.Address = deployment.getAddress();
|
||||||
|
this.Deployer = deployment.getDeployer();
|
||||||
|
this.Contract = deployment;
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
// Ethereum transaction in which this contract was deployed (if known!).
|
// Ethereum address where this contract is located at.
|
||||||
public final Transaction Deployer;
|
public final Address Address;
|
||||||
|
|
||||||
// Contract instance bound to a blockchain address.
|
// Ethereum transaction in which this contract was deployed (if known!).
|
||||||
private final BoundContract Contract;
|
public final Transaction Deployer;
|
||||||
|
|
||||||
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
|
// Contract instance bound to a blockchain address.
|
||||||
public {{.Type}}(Address address, EthereumClient client) throws Exception {
|
private final BoundContract Contract;
|
||||||
this(Geth.bindContract(address, ABI, client));
|
|
||||||
}
|
|
||||||
|
|
||||||
{{range .Calls}}
|
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
|
||||||
{{if gt (len .Normalized.Outputs) 1}}
|
public {{.Type}}(Address address, EthereumClient client) throws Exception {
|
||||||
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
|
this(Geth.bindContract(address, ABI, client));
|
||||||
public class {{capitalise .Normalized.Name}}Results {
|
}
|
||||||
{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
|
{{range .Calls}}
|
||||||
//
|
{{if gt (len .Normalized.Outputs) 1}}
|
||||||
// Solidity: {{.Original.String}}
|
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
|
||||||
public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
public class {{capitalise .Normalized.Name}}Results {
|
||||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
{{range $index, $item := .Normalized.Outputs}}public {{bindtype .Type}} {{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}};
|
||||||
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
|
|
||||||
{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}});
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
if (opts == null) {
|
|
||||||
opts = Geth.newCallOpts();
|
|
||||||
}
|
|
||||||
this.Contract.call(opts, results, "{{.Original.Name}}", args);
|
|
||||||
{{if gt (len .Normalized.Outputs) 1}}
|
|
||||||
{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
|
|
||||||
{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}();
|
|
||||||
{{end}}
|
|
||||||
return result;
|
|
||||||
{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}}
|
|
||||||
{{end}}
|
|
||||||
}
|
|
||||||
{{end}}
|
|
||||||
|
|
||||||
{{range .Transacts}}
|
|
||||||
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}.
|
|
||||||
//
|
|
||||||
// Solidity: {{.Original.String}}
|
|
||||||
public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
|
||||||
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
|
||||||
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
|
||||||
{{end}}
|
|
||||||
return this.Contract.transact(opts, "{{.Original.Name}}" , args);
|
|
||||||
}
|
|
||||||
{{end}}
|
{{end}}
|
||||||
}
|
}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||||
|
//
|
||||||
|
// Solidity: {{.Original.String}}
|
||||||
|
public {{if gt (len .Normalized.Outputs) 1}}{{capitalise .Normalized.Name}}Results{{else}}{{range .Normalized.Outputs}}{{bindtype .Type}}{{end}}{{end}} {{.Normalized.Name}}(CallOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||||
|
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||||
|
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
Interfaces results = Geth.newInterfaces({{(len .Normalized.Outputs)}});
|
||||||
|
{{range $index, $item := .Normalized.Outputs}}Interface result{{$index}} = Geth.newInterface(); result{{$index}}.setDefault{{namedtype (bindtype .Type) .Type}}(); results.set({{$index}}, result{{$index}});
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
if (opts == null) {
|
||||||
|
opts = Geth.newCallOpts();
|
||||||
|
}
|
||||||
|
this.Contract.call(opts, results, "{{.Original.Name}}", args);
|
||||||
|
{{if gt (len .Normalized.Outputs) 1}}
|
||||||
|
{{capitalise .Normalized.Name}}Results result = new {{capitalise .Normalized.Name}}Results();
|
||||||
|
{{range $index, $item := .Normalized.Outputs}}result.{{if ne .Name ""}}{{.Name}}{{else}}Return{{$index}}{{end}} = results.get({{$index}}).get{{namedtype (bindtype .Type) .Type}}();
|
||||||
|
{{end}}
|
||||||
|
return result;
|
||||||
|
{{else}}{{range .Normalized.Outputs}}return results.get(0).get{{namedtype (bindtype .Type) .Type}}();{{end}}
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
|
||||||
|
{{range .Transacts}}
|
||||||
|
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.Id}}.
|
||||||
|
//
|
||||||
|
// Solidity: {{.Original.String}}
|
||||||
|
public Transaction {{.Normalized.Name}}(TransactOpts opts{{range .Normalized.Inputs}}, {{bindtype .Type}} {{.Name}}{{end}}) throws Exception {
|
||||||
|
Interfaces args = Geth.newInterfaces({{(len .Normalized.Inputs)}});
|
||||||
|
{{range $index, $item := .Normalized.Inputs}}Interface arg{{$index}} = Geth.newInterface();arg{{$index}}.set{{namedtype (bindtype .Type) .Type}}({{.Name}});args.set({{$index}},arg{{$index}});
|
||||||
|
{{end}}
|
||||||
|
return this.Contract.transact(opts, "{{.Original.Name}}" , args);
|
||||||
|
}
|
||||||
|
{{end}}
|
||||||
|
}
|
||||||
{{end}}
|
{{end}}
|
||||||
`
|
`
|
||||||
|
|
|
||||||
|
|
@ -69,8 +69,6 @@ func main() {
|
||||||
lang = bind.LangGo
|
lang = bind.LangGo
|
||||||
case "java":
|
case "java":
|
||||||
lang = bind.LangJava
|
lang = bind.LangJava
|
||||||
case "objc":
|
|
||||||
lang = bind.LangObjC
|
|
||||||
default:
|
default:
|
||||||
fmt.Printf("Unsupported destination language \"%s\" (--lang)\n", *langFlag)
|
fmt.Printf("Unsupported destination language \"%s\" (--lang)\n", *langFlag)
|
||||||
os.Exit(-1)
|
os.Exit(-1)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue