@ -22,17 +22,24 @@ import "github.com/harmony-one/harmony/accounts/abi"
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
Libraries map [ string ] string // Map the bytecode's link pattern to the library name
Structs map [ string ] * tmplStruct // Contract struct type definitions
}
// 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
InputBin string // Optional EVM bytecode used to denetare deploy code from
InputBin string // Optional EVM bytecode used to generate 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
Fallback * tmplMethod // Additional special fallback function
Receive * tmplMethod // Additional special receive function
Events map [ string ] * tmplEvent // Contract events accessors
Libraries map [ string ] string // Same as tmplData, but filtered to only keep what the contract needs
Library bool // Indicator whether the contract is a library
}
// tmplMethod is a wrapper around an abi.Method that contains a few preprocessed
@ -43,12 +50,28 @@ type tmplMethod struct {
Structured bool // Whether the returns should be accumulated into a struct
}
// tmplEvent is a wrapper around an a
// tmplEvent is a wrapper around an abi.Event that contains a few preprocessed
// and cached data fields.
type tmplEvent struct {
Original abi . Event // Original event as parsed by the abi package
Normalized abi . Event // Normalized version of the parsed fields
}
// 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
}
// tmplStruct is a wrapper around an abi.tuple and contains an auto-generated
// struct name.
type tmplStruct struct {
Name string // Auto-generated struct name(before solidity v0.5.11) or raw name.
Fields [ ] * tmplField // Struct fields definition depends on the binding language.
}
// tmplSource is language to template mapping containing all the supported
// programming languages the package can generate to.
var tmplSource = map [ Lang ] string {
@ -56,8 +79,8 @@ var tmplSource = map[Lang]string{
LangJava : tmplSourceJava ,
}
// tmplSourceGo is the Go source template use to generate the contract binding
// based on.
// tmplSourceGo is the Go source template that the generated Go contract binding
// is based on.
const tmplSourceGo = `
// Code generated - DO NOT EDIT.
// This file is a generated binding and any manual changes will be lost.
@ -69,10 +92,10 @@ import (
"strings"
ethereum "github.com/ethereum/go-ethereum"
"github.com/harmony-one/harmony /accounts/abi"
"github.com/harmony-one/harmony /accounts/abi/bind"
"github.com/ethereum/go-ethereum /accounts/abi"
"github.com/ethereum/go-ethereum /accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/harmony-one/harmony /core/types"
"github.com/ethereum/go-ethereum /core/types"
"github.com/ethereum/go-ethereum/event"
)
@ -81,27 +104,47 @@ var (
_ = big . NewInt
_ = strings . NewReader
_ = ethereum . NotFound
_ = abi . U256
_ = bind . Bind
_ = common . Big1
_ = types . BloomLookup
_ = event . NewSubscription
)
{ { $ structs := . Structs } }
{ { range $ structs } }
// {{.Name}} is an auto generated low-level Go binding around an user-defined struct.
type { { . Name } } struct {
{ { range $ field := . Fields } }
{ { $ field . Name } } { { $ field . Type } } { { end } }
}
{ { end } }
{ { range $ contract := . Contracts } }
// {{.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}}` + " ` " + `
var { { . Type } } Bin = "0x{{.InputBin}}"
// Deploy{{.Type}} deploys a new Ethereum contract, binding an instance of {{.Type}} to it.
func Deploy { { . Type } } ( auth * bind . TransactOpts , backend bind . ContractBackend { { range . Constructor . Inputs } } , { { . Name } } { { bindtype . Type } } { { end } } ) ( common . Address , * types . Transaction , * { { . Type } } , error ) {
func Deploy { { . Type } } ( auth * bind . TransactOpts , backend bind . ContractBackend { { range . Constructor . Inputs } } , { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( common . Address , * types . Transaction , * { { . Type } } , error ) {
parsed , err := abi . JSON ( strings . NewReader ( { { . Type } } ABI ) )
if err != nil {
return common . Address { } , nil , nil , err
}
{ { range $ pattern , $ name := . Libraries } }
{ { decapitalise $ name } } Addr , _ , _ , _ := Deploy { { capitalise $ name } } ( auth , backend )
{ { $ contract . Type } } Bin = strings . Replace ( { { $ contract . Type } } Bin , "__${{$pattern}}$__" , { { decapitalise $ name } } Addr . String ( ) [ 2 : ] , - 1 )
{ { end } }
address , tx , contract , err := bind . DeployContract ( auth , parsed , common . FromHex ( { { . Type } } Bin ) , backend { { range . Constructor . Inputs } } , { { . Name } } { { end } } )
if err != nil {
return common . Address { } , nil , nil , err
@ -114,7 +157,7 @@ var (
type { { . Type } } struct {
{ { . Type } } Caller // Read-only binding to the contract
{ { . Type } } Transactor // Write-only binding to the contract
{ { . Type } } Filterer // Log filterer for contract events
{ { . Type } } Filterer // Log filterer for contract events
}
// {{.Type}}Caller is an auto generated read-only Go binding around an Ethereum contract.
@ -218,7 +261,7 @@ var (
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Raw ) Call ( opts * bind . CallOpts , result interface { } , method string , params ... interface { } ) error {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Raw ) Call ( opts * bind . CallOpts , result * [ ] interface { } , method string , params ... interface { } ) error {
return _ { { $ contract . Type } } . Contract . { { $ contract . Type } } Caller . contract . Call ( opts , result , method , params ... )
}
@ -237,7 +280,7 @@ var (
// sets the output to result. The result type might be a single field for simple
// returns, a slice of interfaces for anonymous returns and a struct for named
// returns.
func ( _ { { $ contract . Type } } * { { $ contract . Type } } CallerRaw ) Call ( opts * bind . CallOpts , result interface { } , method string , params ... interface { } ) error {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } CallerRaw ) Call ( opts * bind . CallOpts , result * [ ] interface { } , method string , params ... interface { } ) error {
return _ { { $ contract . Type } } . Contract . contract . Call ( opts , result , method , params ... )
}
@ -256,33 +299,40 @@ var (
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Caller ) { { . Normalized . Name } } ( opts * bind . CallOpts { { range . Normalized . Inputs } } , { { . Name } } { { bindtype . Type } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type } } , { { end } } { { end } } error ) {
{ { if . Structured } } ret := new ( struct {
{ { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type } }
{ { end } }
} ) { { else } } var (
{ { range $ i , $ _ := . Normalized . Outputs } } ret { { $ i } } = new ( { { bindtype . Type } } )
{ { end } }
) { { end } }
out := { { if . Structured } } ret { { else } } { { if eq ( len . Normalized . Outputs ) 1 } } ret0 { { else } } & [ ] interface { } {
{ { range $ i , $ _ := . Normalized . Outputs } } ret { { $ i } } ,
{ { end } }
} { { end } } { { end } }
err := _ { { $ contract . Type } } . contract . Call ( opts , out , "{{.Original.Name}}" { { range . Normalized . Inputs } } , { { . Name } } { { end } } )
return { { if . Structured } } * ret , { { else } } { { range $ i , $ _ := . Normalized . Outputs } } * ret { { $ i } } , { { end } } { { end } } err
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Caller ) { { . Normalized . Name } } ( opts * bind . CallOpts { { range . Normalized . Inputs } } , { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type $ structs } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type $ structs } } , { { end } } { { end } } error ) {
var out [ ] interface { }
err := _ { { $ contract . Type } } . contract . Call ( opts , & out , "{{.Original.Name}}" { { range . Normalized . Inputs } } , { { . Name } } { { end } } )
{ { if . Structured } }
outstruct := new ( struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type $ structs } } ; { { end } } } )
if err != nil {
return * outstruct , err
}
{ { range $ i , $ t := . Normalized . Outputs } }
outstruct . { { . Name } } = out [ { { $ i } } ] . ( { { bindtype . Type $ structs } } ) { { end } }
return * outstruct , err
{ { else } }
if err != nil {
return { { range $ i , $ _ := . Normalized . Outputs } } * new ( { { bindtype . Type $ structs } } ) , { { end } } err
}
{ { range $ i , $ t := . Normalized . Outputs } }
out { { $ i } } := * abi . ConvertType ( out [ { { $ i } } ] , new ( { { bindtype . Type $ structs } } ) ) . ( * { { bindtype . Type $ structs } } ) { { end } }
return { { range $ i , $ t := . Normalized . Outputs } } out { { $ i } } , { { end } } err
{ { end } }
}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type } } , { { end } } { { end } } error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type $ structs } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type $ structs } } , { { end } } { { end } } error ) {
return _ { { $ contract . Type } } . Contract . { { . Normalized . Name } } ( & _ { { $ contract . Type } } . CallOpts { { range . Normalized . Inputs } } , { { . Name } } { { end } } )
}
// {{.Normalized.Name}} is a free data retrieval call binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } CallerSession ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type } } , { { end } } { { end } } error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } CallerSession ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( { { if . Structured } } struct { { { range . Normalized . Outputs } } { { . Name } } { { bindtype . Type $ structs } } ; { { end } } } , { { else } } { { range . Normalized . Outputs } } { { bindtype . Type $ structs } } , { { end } } { { end } } error ) {
return _ { { $ contract . Type } } . Contract . { { . Normalized . Name } } ( & _ { { $ contract . Type } } . CallOpts { { range . Normalized . Inputs } } , { { . Name } } { { end } } )
}
{ { end } }
@ -291,25 +341,71 @@ var (
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Transactor ) { { . Normalized . Name } } ( opts * bind . TransactOpts { { range . Normalized . Inputs } } , { { . Name } } { { bindtype . Type } } { { end } } ) ( * types . Transaction , error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Transactor ) { { . Normalized . Name } } ( opts * bind . TransactOpts { { range . Normalized . Inputs } } , { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . contract . Transact ( opts , "{{.Original.Name}}" { { range . Normalized . Inputs } } , { { . Name } } { { end } } )
}
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type } } { { end } } ) ( * types . Transaction , error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . { { . Normalized . Name } } ( & _ { { $ contract . Type } } . TransactOpts { { range $ i , $ _ := . Normalized . Inputs } } , { { . Name } } { { end } } )
}
// {{.Normalized.Name}} is a paid mutator transaction binding the contract method 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } TransactorSession ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type } } { { end } } ) ( * types . Transaction , error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } TransactorSession ) { { . Normalized . Name } } ( { { range $ i , $ _ := . Normalized . Inputs } } { { if ne $ i 0 } } , { { end } } { { . Name } } { { bindtype . Type $ structs } } { { end } } ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . { { . Normalized . Name } } ( & _ { { $ contract . Type } } . TransactOpts { { range $ i , $ _ := . Normalized . Inputs } } , { { . Name } } { { end } } )
}
{ { end } }
{ { if . Fallback } }
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Transactor ) Fallback ( opts * bind . TransactOpts , calldata [ ] byte ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . contract . RawTransact ( opts , calldata )
}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) Fallback ( calldata [ ] byte ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . Fallback ( & _ { { $ contract . Type } } . TransactOpts , calldata )
}
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } TransactorSession ) Fallback ( calldata [ ] byte ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . Fallback ( & _ { { $ contract . Type } } . TransactOpts , calldata )
}
{ { end } }
{ { if . Receive } }
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Transactor ) Receive ( opts * bind . TransactOpts ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . contract . RawTransact ( opts , nil ) // calldata is disallowed for receive function
}
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Session ) Receive ( ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . Receive ( & _ { { $ contract . Type } } . TransactOpts )
}
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } TransactorSession ) Receive ( ) ( * types . Transaction , error ) {
return _ { { $ contract . Type } } . Contract . Receive ( & _ { { $ contract . Type } } . TransactOpts )
}
{ { end } }
{ { range . Events } }
// {{$contract.Type}}{{.Normalized.Name}}Iterator is returned from Filter{{.Normalized.Name}} and is used to iterate over the raw logs and unpacked data for {{.Normalized.Name}} events raised by the {{$contract.Type}} contract.
type { { $ contract . Type } } { { . Normalized . Name } } Iterator struct {
@ -377,14 +473,14 @@ var (
// {{$contract.Type}}{{.Normalized.Name}} represents a {{.Normalized.Name}} event raised by the {{$contract.Type}} contract.
type { { $ contract . Type } } { { . Normalized . Name } } struct { { { range . Normalized . Inputs } }
{ { capitalise . Name } } { { if . Indexed } } { { bindtopictype . Type } } { { else } } { { bindtype . Type } } { { end } } ; { { end } }
{ { capitalise . Name } } { { if . Indexed } } { { bindtopictype . Type $ structs } } { { else } } { { bindtype . Type $ structs } } { { end } } ; { { end } }
Raw types . Log // Blockchain specific contextual infos
}
// Filter{{.Normalized.Name}} is a free log retrieval operation binding the contract event 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Filterer ) Filter { { . Normalized . Name } } ( opts * bind . FilterOpts { { range . Normalized . Inputs } } { { if . Indexed } } , { { . Name } } [ ] { { bindtype . Type } } { { end } } { { end } } ) ( * { { $ contract . Type } } { { . Normalized . Name } } Iterator , error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Filterer ) Filter { { . Normalized . Name } } ( opts * bind . FilterOpts { { range . Normalized . Inputs } } { { if . Indexed } } , { { . Name } } [ ] { { bindtype . Type $ structs } } { { end } } { { end } } ) ( * { { $ contract . Type } } { { . Normalized . Name } } Iterator , error ) {
{ { range . Normalized . Inputs } }
{ { if . Indexed } } var { { . Name } } Rule [ ] interface { }
for _ , { { . Name } } Item := range { { . Name } } {
@ -401,7 +497,7 @@ var (
// Watch{{.Normalized.Name}} is a free log subscription operation binding the contract event 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Filterer ) Watch { { . Normalized . Name } } ( opts * bind . WatchOpts , sink chan <- * { { $ contract . Type } } { { . Normalized . Name } } { { range . Normalized . Inputs } } { { if . Indexed } } , { { . Name } } [ ] { { bindtype . Type } } { { end } } { { end } } ) ( event . Subscription , error ) {
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Filterer ) Watch { { . Normalized . Name } } ( opts * bind . WatchOpts , sink chan <- * { { $ contract . Type } } { { . Normalized . Name } } { { range . Normalized . Inputs } } { { if . Indexed } } , { { . Name } } [ ] { { bindtype . Type $ structs } } { { end } } { { end } } ) ( event . Subscription , error ) {
{ { range . Normalized . Inputs } }
{ { if . Indexed } } var { { . Name } } Rule [ ] interface { }
for _ , { { . Name } } Item := range { { . Name } } {
@ -439,12 +535,25 @@ var (
}
} ) , nil
}
// Parse{{.Normalized.Name}} is a log parse operation binding the contract event 0x{{printf "%x" .Original.ID}}.
//
// Solidity: {{.Original.String}}
func ( _ { { $ contract . Type } } * { { $ contract . Type } } Filterer ) Parse { { . Normalized . Name } } ( log types . Log ) ( * { { $ contract . Type } } { { . Normalized . Name } } , error ) {
event := new ( { { $ contract . Type } } { { . Normalized . Name } } )
if err := _ { { $ contract . Type } } . contract . UnpackLog ( event , "{{.Original.Name}}" , log ) ; err != nil {
return nil , err
}
event . Raw = log
return event , nil
}
{ { end } }
{ { end } }
`
// tmplSourceJava is the Java source template use to generate the contract binding
// based on.
// tmplSourceJava is the Java source template that the generated Java contract binding
// is based on.
const tmplSourceJava = `
// This file is an automatically generated Java binding. Do not modify as any
// change will likely be lost upon the next re-generation!
@ -452,95 +561,130 @@ const tmplSourceJava = `
package { { . Package } } ;
import org . ethereum . geth . * ;
import org . ethereum . geth . interna l. * ;
import java . uti l. * ;
{ { $ structs := . Structs } }
{ { range $ contract := . Contracts } }
public class { { . Type } } {
// ABI is the input ABI used to generate the binding from.
public final static String ABI = "{{.InputABI}}" ;
{ { if . InputBin } }
// BYTECODE is the compiled bytecode used for deploying new contracts.
public final static byte [ ] BYTECODE = "{{.InputBin}}" . getBytes ( ) ;
// 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 {
Interfaces args = Geth . newInterfaces ( { { ( len . Constructor . Inputs ) } } ) ;
{ { range $ index , $ element := . Constructor . Inputs } }
args . set ( { { $ index } } , Geth . newInterface ( ) ) ; args . get ( { { $ index } } ) . set { { namedtype ( bindtype . Type ) . Type } } ( { { . Name } } ) ;
{ { end } }
return new { { . Type } } ( Geth . deployContract ( auth , ABI , BYTECODE , client , args ) ) ;
}
// Internal constructor used by contract deployment.
private { { . Type } } ( BoundContract deployment ) {
this . Address = deployment . getAddress ( ) ;
this . Deployer = deployment . getDeployer ( ) ;
this . Contract = deployment ;
}
{ { if not . Library } } public { { end } } 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}}" ;
// 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 $ structs } } { { . Name } } { { end } } ) throws Exception {
Interfaces args = Geth . newInterfaces ( { { ( len . Constructor . Inputs ) } } ) ;
String bytecode = BYTECODE ;
{ { if . Libraries } }
// "link" contract to dependent libraries by deploying them first.
{ { range $ pattern , $ name := . Libraries } }
{ { capitalise $ name } } { { decapitalise $ name } } Inst = { { capitalise $ name } } . deploy ( auth , client ) ;
bytecode = bytecode . replace ( "__${{$pattern}}$__" , { { decapitalise $ name } } Inst . Address . getHex ( ) . substring ( 2 ) ) ;
{ { end } }
{ { end } }
{ { range $ index , $ element := . Constructor . Inputs } } Interface arg { { $ index } } = Geth . newInterface ( ) ; arg { { $ index } } . set { { namedtype ( bindtype . Type $ structs ) . Type } } ( { { . Name } } ) ; args . set ( { { $ index } } , arg { { $ index } } ) ;
{ { end } }
return new { { . Type } } ( Geth . deployContract ( auth , ABI , Geth . decodeFromHex ( bytecode ) , client , args ) ) ;
}
// Ethereum address where this contract is located at.
public final Address Address ;
// Internal constructor used by contract deployment.
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!).
public final Transaction Deployer ;
// Ethereum address where this contract is located at .
public final Address Address ;
// Contract instance bound to a blockchain address.
private final BoundContract Contract ;
// Ethereum transaction in which this contract was deployed (if known!) .
public final Transaction Deployer ;
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
public { { . Type } } ( Address address , EthereumClient client ) throws Exception {
this ( Geth . bindContract ( address , ABI , client ) ) ;
}
// Contract instance bound to a blockchain address.
private final BoundContract Contract ;
{ { range . Calls } }
{ { if gt ( len . Normalized . Outputs ) 1 } }
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
public class { { capitalise . Normalized . Name } } Results {
{ { range $ index , $ item := . Normalized . Outputs } } public { { bindtype . Type } } { { if ne . Name "" } } { { . Name } } { { else } } Return { { $ index } } { { end } } ;
{ { end } }
}
{ { end } }
// Creates a new instance of {{.Type}}, bound to a specific deployed contract.
public { { . Type } } ( Address address , EthereumClient client ) throws Exception {
this ( Geth . bindContract ( address , ABI , client ) ) ;
}
// {{.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 } } args . set ( { { $ index } } , Geth . newInterface ( ) ) ; args . get ( { { $ index } } ) . set { { namedtype ( bindtype . Type ) . Type } } ( { { . Name } } ) ;
{ { end } }
{ { range . Calls } }
{ { if gt ( len . Normalized . Outputs ) 1 } }
// {{capitalise .Normalized.Name}}Results is the output of a call to {{.Normalized.Name}}.
public class { { capitalise . Normalized . Name } } Results {
{ { range $ index , $ item := . Normalized . Outputs } } public { { bindtype . Type $ structs } } { { if ne . Name "" } } { { . Name } } { { else } } Return { { $ index } } { { end } } ;
{ { end } }
}
{ { 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 } }
// {{.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 if eq ( len . Normalized . Outputs ) 0 } } void { { else } } { { range . Normalized . Outputs } } { { bindtype . Type $ structs } } { { end } } { { end } } { { . Normalized . Name } } ( CallOpts opts { { range . Normalized . Inputs } } , { { bindtype . Type $ structs } } { { . 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 $ structs ) . Type } } ( { { . Name } } ) ; args . set ( { { $ index } } , arg { { $ 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 } }
}
Interfaces results = Geth . newInterfaces ( { { ( len . Normalized . Outputs ) } } ) ;
{ { range $ index , $ item := . Normalized . Outputs } } Interface result { { $ index } } = Geth . newInterface ( ) ; result { { $ index } } . setDefault { { namedtype ( bindtype . Type $ structs ) . Type } } ( ) ; results . set ( { { $ index } } , result { { $ index } } ) ;
{ { 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 } } args . set ( { { $ index } } , Geth . newInterface ( ) ) ; args . get ( { { $ index } } ) . set { { namedtype ( bindtype . Type ) . Type } } ( { { . Name } } ) ;
{ { 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 $ structs ) . Type } } ( ) ;
{ { end } }
return result ;
{ { else } } { { range . Normalized . Outputs } } return results . get ( 0 ) . get { { namedtype ( bindtype . Type $ structs ) . Type } } ( ) ; { { end } }
{ { end } }
}
{ { end } }
return this . Contract . transact ( opts , "{{.Original.Name}}" , args ) ;
}
{ { 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 $ structs } } { { . 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 $ structs ) . Type } } ( { { . Name } } ) ; args . set ( { { $ index } } , arg { { $ index } } ) ;
{ { end } }
return this . Contract . transact ( opts , "{{.Original.Name}}" , args ) ;
}
{ { end } }
{ { if . Fallback } }
// Fallback is a paid mutator transaction binding the contract fallback function.
//
// Solidity: {{.Fallback.Original.String}}
public Transaction Fallback ( TransactOpts opts , byte [ ] calldata ) throws Exception {
return this . Contract . rawTransact ( opts , calldata ) ;
}
{ { end } }
{ { if . Receive } }
// Receive is a paid mutator transaction binding the contract receive function.
//
// Solidity: {{.Receive.Original.String}}
public Transaction Receive ( TransactOpts opts ) throws Exception {
return this . Contract . rawTransact ( opts , null ) ;
}
{ { end } }
}
{ { end } }
`