diff --git a/abigen/gen.go b/abigen/gen.go index f88b9181..a9987edb 100644 --- a/abigen/gen.go +++ b/abigen/gen.go @@ -24,9 +24,6 @@ func cleanName(str string) string { } func outputArg(str string) string { - if str == "" { - - } return str } @@ -231,14 +228,19 @@ func ({{$.Ptr}} *{{$.Name}}) {{funcName $key}}({{range $index, $val := tupleElem return } {{end}}{{end}} - // txns {{range $key, $value := .Abi.Methods}}{{if not .Const}} // {{funcName $key}} sends a {{$key}} transaction in the solidity contract func ({{$.Ptr}} *{{$.Name}}) {{funcName $key}}({{range $index, $input := tupleElems .Inputs}}{{if $index}}, {{end}}{{clean .Name}} {{arg .}}{{end}}) *contract.Txn { return {{$.Ptr}}.c.Txn("{{$key}}"{{range $index, $elem := tupleElems .Inputs}}, {{clean $elem.Name}}{{end}}) } -{{end}}{{end}}` +{{end}}{{end}} +// events +{{range $key, $value := .Abi.Events}} +func ({{$.Ptr}} *{{$.Name}}) {{funcName $key}}EventSig() web3.Hash { + return a.c.ABI().Events["{{funcName $key}}"].ID() +} +{{end}}` var templateBinStr = `package {{.Config.Package}} diff --git a/abigen/main.go b/abigen/main.go index ee833ed9..6b808b96 100644 --- a/abigen/main.go +++ b/abigen/main.go @@ -18,12 +18,12 @@ const ( ) func main() { - var source string + var sources string var pckg string var output string var name string - flag.StringVar(&source, "source", "", "List of abi files") + flag.StringVar(&sources, "source", "", "List of abi files") flag.StringVar(&pckg, "package", "main", "Name of the package") flag.StringVar(&output, "output", "", "Output directory") flag.StringVar(&name, "name", "", "name of the contract") @@ -36,25 +36,27 @@ func main() { Name: name, } - if source == "" { + if sources == "" { fmt.Println(version) os.Exit(0) } - matches, err := filepath.Glob(source) - if err != nil { - fmt.Printf("Failed to read files: %v", err) - os.Exit(1) - } - for _, source := range matches { - artifacts, err := process(source, config) + for _, source := range strings.Split(sources, ",") { + matches, err := filepath.Glob(source) if err != nil { - fmt.Printf("Failed to parse sources: %v", err) + fmt.Printf("Failed to read files: %v", err) os.Exit(1) } - if err := gen(artifacts, config); err != nil { - fmt.Printf("Failed to generate sources: %v", err) - os.Exit(1) + for _, source := range matches { + artifacts, err := process(source, config) + if err != nil { + fmt.Printf("Failed to parse sources: %v", err) + os.Exit(1) + } + if err := gen(artifacts, config); err != nil { + fmt.Printf("Failed to generate sources: %v", err) + os.Exit(1) + } } } } diff --git a/contract/builtin/ens/ens.go b/contract/builtin/ens/ens.go index e89211ad..ef41f469 100644 --- a/contract/builtin/ens/ens.go +++ b/contract/builtin/ens/ens.go @@ -36,7 +36,7 @@ func (a *ENS) Contract() *contract.Contract { // calls // Owner calls the owner method in the solidity contract -func (a *ENS) Owner(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) { +func (a *ENS) Owner(node [32]byte, block ...web3.BlockNumber) (retval0 web3.Address, err error) { var out map[string]interface{} var ok bool @@ -46,17 +46,17 @@ func (a *ENS) Owner(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address } // decode outputs - val0, ok = out["0"].(web3.Address) + retval0, ok = out["0"].(web3.Address) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // Resolver calls the resolver method in the solidity contract -func (a *ENS) Resolver(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) { +func (a *ENS) Resolver(node [32]byte, block ...web3.BlockNumber) (retval0 web3.Address, err error) { var out map[string]interface{} var ok bool @@ -66,17 +66,17 @@ func (a *ENS) Resolver(node [32]byte, block ...web3.BlockNumber) (val0 web3.Addr } // decode outputs - val0, ok = out["0"].(web3.Address) + retval0, ok = out["0"].(web3.Address) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // Ttl calls the ttl method in the solidity contract -func (a *ENS) Ttl(node [32]byte, block ...web3.BlockNumber) (val0 uint64, err error) { +func (a *ENS) Ttl(node [32]byte, block ...web3.BlockNumber) (retval0 uint64, err error) { var out map[string]interface{} var ok bool @@ -86,16 +86,15 @@ func (a *ENS) Ttl(node [32]byte, block ...web3.BlockNumber) (val0 uint64, err er } // decode outputs - val0, ok = out["0"].(uint64) + retval0, ok = out["0"].(uint64) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } - // txns // SetOwner sends a setOwner transaction in the solidity contract @@ -117,3 +116,21 @@ func (a *ENS) SetSubnodeOwner(node [32]byte, label [32]byte, owner web3.Address) func (a *ENS) SetTTL(node [32]byte, ttl uint64) *contract.Txn { return a.c.Txn("setTTL", node, ttl) } + +// events + +func (a *ENS) NewOwnerEventSig() web3.Hash { + return a.c.ABI().Events["NewOwner"].ID() +} + +func (a *ENS) NewResolverEventSig() web3.Hash { + return a.c.ABI().Events["NewResolver"].ID() +} + +func (a *ENS) NewTTLEventSig() web3.Hash { + return a.c.ABI().Events["NewTTL"].ID() +} + +func (a *ENS) TransferEventSig() web3.Hash { + return a.c.ABI().Events["Transfer"].ID() +} diff --git a/contract/builtin/ens/resolver.go b/contract/builtin/ens/resolver.go index 80fb75c1..fdbce552 100644 --- a/contract/builtin/ens/resolver.go +++ b/contract/builtin/ens/resolver.go @@ -36,7 +36,7 @@ func (a *Resolver) Contract() *contract.Contract { // calls // ABI calls the ABI method in the solidity contract -func (a *Resolver) ABI(node [32]byte, contentTypes *big.Int, block ...web3.BlockNumber) (val0 *big.Int, val1 []byte, err error) { +func (a *Resolver) ABI(node [32]byte, contentTypes *big.Int, block ...web3.BlockNumber) (retval0 *big.Int, retval1 []byte, err error) { var out map[string]interface{} var ok bool @@ -46,12 +46,12 @@ func (a *Resolver) ABI(node [32]byte, contentTypes *big.Int, block ...web3.Block } // decode outputs - val0, ok = out["contentType"].(*big.Int) + retval0, ok = out["contentType"].(*big.Int) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - val1, ok = out["data"].([]byte) + retval1, ok = out["data"].([]byte) if !ok { err = fmt.Errorf("failed to encode output at index 1") return @@ -61,7 +61,7 @@ func (a *Resolver) ABI(node [32]byte, contentTypes *big.Int, block ...web3.Block } // Addr calls the addr method in the solidity contract -func (a *Resolver) Addr(node [32]byte, block ...web3.BlockNumber) (val0 web3.Address, err error) { +func (a *Resolver) Addr(node [32]byte, block ...web3.BlockNumber) (retval0 web3.Address, err error) { var out map[string]interface{} var ok bool @@ -71,7 +71,7 @@ func (a *Resolver) Addr(node [32]byte, block ...web3.BlockNumber) (val0 web3.Add } // decode outputs - val0, ok = out["ret"].(web3.Address) + retval0, ok = out["ret"].(web3.Address) if !ok { err = fmt.Errorf("failed to encode output at index 0") return @@ -81,7 +81,7 @@ func (a *Resolver) Addr(node [32]byte, block ...web3.BlockNumber) (val0 web3.Add } // Content calls the content method in the solidity contract -func (a *Resolver) Content(node [32]byte, block ...web3.BlockNumber) (val0 [32]byte, err error) { +func (a *Resolver) Content(node [32]byte, block ...web3.BlockNumber) (retval0 [32]byte, err error) { var out map[string]interface{} var ok bool @@ -91,7 +91,7 @@ func (a *Resolver) Content(node [32]byte, block ...web3.BlockNumber) (val0 [32]b } // decode outputs - val0, ok = out["ret"].([32]byte) + retval0, ok = out["ret"].([32]byte) if !ok { err = fmt.Errorf("failed to encode output at index 0") return @@ -101,7 +101,7 @@ func (a *Resolver) Content(node [32]byte, block ...web3.BlockNumber) (val0 [32]b } // Name calls the name method in the solidity contract -func (a *Resolver) Name(node [32]byte, block ...web3.BlockNumber) (val0 string, err error) { +func (a *Resolver) Name(node [32]byte, block ...web3.BlockNumber) (retval0 string, err error) { var out map[string]interface{} var ok bool @@ -111,7 +111,7 @@ func (a *Resolver) Name(node [32]byte, block ...web3.BlockNumber) (val0 string, } // decode outputs - val0, ok = out["ret"].(string) + retval0, ok = out["ret"].(string) if !ok { err = fmt.Errorf("failed to encode output at index 0") return @@ -121,7 +121,7 @@ func (a *Resolver) Name(node [32]byte, block ...web3.BlockNumber) (val0 string, } // Pubkey calls the pubkey method in the solidity contract -func (a *Resolver) Pubkey(node [32]byte, block ...web3.BlockNumber) (val0 [32]byte, val1 [32]byte, err error) { +func (a *Resolver) Pubkey(node [32]byte, block ...web3.BlockNumber) (retval0 [32]byte, retval1 [32]byte, err error) { var out map[string]interface{} var ok bool @@ -131,12 +131,12 @@ func (a *Resolver) Pubkey(node [32]byte, block ...web3.BlockNumber) (val0 [32]by } // decode outputs - val0, ok = out["x"].([32]byte) + retval0, ok = out["x"].([32]byte) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - val1, ok = out["y"].([32]byte) + retval1, ok = out["y"].([32]byte) if !ok { err = fmt.Errorf("failed to encode output at index 1") return @@ -146,7 +146,7 @@ func (a *Resolver) Pubkey(node [32]byte, block ...web3.BlockNumber) (val0 [32]by } // SupportsInterface calls the supportsInterface method in the solidity contract -func (a *Resolver) SupportsInterface(interfaceID [4]byte, block ...web3.BlockNumber) (val0 bool, err error) { +func (a *Resolver) SupportsInterface(interfaceID [4]byte, block ...web3.BlockNumber) (retval0 bool, err error) { var out map[string]interface{} var ok bool @@ -156,7 +156,7 @@ func (a *Resolver) SupportsInterface(interfaceID [4]byte, block ...web3.BlockNum } // decode outputs - val0, ok = out["0"].(bool) + retval0, ok = out["0"].(bool) if !ok { err = fmt.Errorf("failed to encode output at index 0") return @@ -165,7 +165,6 @@ func (a *Resolver) SupportsInterface(interfaceID [4]byte, block ...web3.BlockNum return } - // txns // SetABI sends a setABI transaction in the solidity contract @@ -192,3 +191,25 @@ func (a *Resolver) SetName(node [32]byte, name string) *contract.Txn { func (a *Resolver) SetPubkey(node [32]byte, x [32]byte, y [32]byte) *contract.Txn { return a.c.Txn("setPubkey", node, x, y) } + +// events + +func (a *Resolver) ABIChangedEventSig() web3.Hash { + return a.c.ABI().Events["ABIChanged"].ID() +} + +func (a *Resolver) AddrChangedEventSig() web3.Hash { + return a.c.ABI().Events["AddrChanged"].ID() +} + +func (a *Resolver) ContentChangedEventSig() web3.Hash { + return a.c.ABI().Events["ContentChanged"].ID() +} + +func (a *Resolver) NameChangedEventSig() web3.Hash { + return a.c.ABI().Events["NameChanged"].ID() +} + +func (a *Resolver) PubkeyChangedEventSig() web3.Hash { + return a.c.ABI().Events["PubkeyChanged"].ID() +} diff --git a/contract/builtin/erc20/erc20.go b/contract/builtin/erc20/erc20.go index 3a038e63..df814ae0 100644 --- a/contract/builtin/erc20/erc20.go +++ b/contract/builtin/erc20/erc20.go @@ -31,7 +31,7 @@ func (a *ERC20) Contract() *contract.Contract { // calls // Allowance calls the allowance method in the solidity contract -func (a *ERC20) Allowance(owner web3.Address, spender web3.Address, block ...web3.BlockNumber) (val0 *big.Int, err error) { +func (a *ERC20) Allowance(owner web3.Address, spender web3.Address, block ...web3.BlockNumber) (retval0 *big.Int, err error) { var out map[string]interface{} var ok bool @@ -41,17 +41,17 @@ func (a *ERC20) Allowance(owner web3.Address, spender web3.Address, block ...web } // decode outputs - val0, ok = out["0"].(*big.Int) + retval0, ok = out["0"].(*big.Int) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // BalanceOf calls the balanceOf method in the solidity contract -func (a *ERC20) BalanceOf(owner web3.Address, block ...web3.BlockNumber) (val0 *big.Int, err error) { +func (a *ERC20) BalanceOf(owner web3.Address, block ...web3.BlockNumber) (retval0 *big.Int, err error) { var out map[string]interface{} var ok bool @@ -61,17 +61,17 @@ func (a *ERC20) BalanceOf(owner web3.Address, block ...web3.BlockNumber) (val0 * } // decode outputs - val0, ok = out["balance"].(*big.Int) + retval0, ok = out["balance"].(*big.Int) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // Decimals calls the decimals method in the solidity contract -func (a *ERC20) Decimals(block ...web3.BlockNumber) (val0 uint8, err error) { +func (a *ERC20) Decimals(block ...web3.BlockNumber) (retval0 uint8, err error) { var out map[string]interface{} var ok bool @@ -81,17 +81,17 @@ func (a *ERC20) Decimals(block ...web3.BlockNumber) (val0 uint8, err error) { } // decode outputs - val0, ok = out["0"].(uint8) + retval0, ok = out["0"].(uint8) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // Name calls the name method in the solidity contract -func (a *ERC20) Name(block ...web3.BlockNumber) (val0 string, err error) { +func (a *ERC20) Name(block ...web3.BlockNumber) (retval0 string, err error) { var out map[string]interface{} var ok bool @@ -101,17 +101,17 @@ func (a *ERC20) Name(block ...web3.BlockNumber) (val0 string, err error) { } // decode outputs - val0, ok = out["0"].(string) + retval0, ok = out["0"].(string) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // Symbol calls the symbol method in the solidity contract -func (a *ERC20) Symbol(block ...web3.BlockNumber) (val0 string, err error) { +func (a *ERC20) Symbol(block ...web3.BlockNumber) (retval0 string, err error) { var out map[string]interface{} var ok bool @@ -121,17 +121,17 @@ func (a *ERC20) Symbol(block ...web3.BlockNumber) (val0 string, err error) { } // decode outputs - val0, ok = out["0"].(string) + retval0, ok = out["0"].(string) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } // TotalSupply calls the totalSupply method in the solidity contract -func (a *ERC20) TotalSupply(block ...web3.BlockNumber) (val0 *big.Int, err error) { +func (a *ERC20) TotalSupply(block ...web3.BlockNumber) (retval0 *big.Int, err error) { var out map[string]interface{} var ok bool @@ -141,12 +141,12 @@ func (a *ERC20) TotalSupply(block ...web3.BlockNumber) (val0 *big.Int, err error } // decode outputs - val0, ok = out["0"].(*big.Int) + retval0, ok = out["0"].(*big.Int) if !ok { err = fmt.Errorf("failed to encode output at index 0") return } - + return } @@ -166,3 +166,13 @@ func (a *ERC20) Transfer(to web3.Address, value *big.Int) *contract.Txn { func (a *ERC20) TransferFrom(from web3.Address, to web3.Address, value *big.Int) *contract.Txn { return a.c.Txn("transferFrom", from, to, value) } + +// events + +func (a *ERC20) ApprovalEventSig() web3.Hash { + return a.c.ABI().Events["Approval"].ID() +} + +func (a *ERC20) TransferEventSig() web3.Hash { + return a.c.ABI().Events["Transfer"].ID() +} diff --git a/contract/contract.go b/contract/contract.go index f7087e2d..07f9f83f 100644 --- a/contract/contract.go +++ b/contract/contract.go @@ -38,6 +38,11 @@ func NewContract(addr web3.Address, abi *abi.ABI, provider *jsonrpc.Client) *Con } } +// ABI returns the abi of the contract +func (c *Contract) ABI() *abi.ABI { + return c.abi +} + // Addr returns the address of the contract func (c *Contract) Addr() web3.Address { return c.addr