Skip to content

Commit

Permalink
Add event signature to abigen (umbracle#92)
Browse files Browse the repository at this point in the history
  • Loading branch information
ferranbt authored Sep 21, 2021
1 parent 13a0ca7 commit 1a00db7
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 62 deletions.
12 changes: 7 additions & 5 deletions abigen/gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ func cleanName(str string) string {
}

func outputArg(str string) string {
if str == "" {

}
return str
}

Expand Down Expand Up @@ -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}}
Expand Down
30 changes: 16 additions & 14 deletions abigen/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
}
}
}
}
Expand Down
37 changes: 27 additions & 10 deletions contract/builtin/ens/ens.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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()
}
51 changes: 36 additions & 15 deletions contract/builtin/ens/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
Expand All @@ -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()
}
Loading

0 comments on commit 1a00db7

Please sign in to comment.