github.com/sberex/go-sberex@v1.8.2-0.20181113200658-ed96ac38f7d7/accounts/abi/event.go (about)

     1  // This file is part of the go-sberex library. The go-sberex library is 
     2  // free software: you can redistribute it and/or modify it under the terms 
     3  // of the GNU Lesser General Public License as published by the Free 
     4  // Software Foundation, either version 3 of the License, or (at your option)
     5  // any later version.
     6  //
     7  // The go-sberex library is distributed in the hope that it will be useful, 
     8  // but WITHOUT ANY WARRANTY; without even the implied warranty of
     9  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 
    10  // General Public License <http://www.gnu.org/licenses/> for more details.
    11  
    12  package abi
    13  
    14  import (
    15  	"fmt"
    16  	"strings"
    17  
    18  	"github.com/Sberex/go-sberex/common"
    19  	"github.com/Sberex/go-sberex/crypto"
    20  )
    21  
    22  // Event is an event potentially triggered by the EVM's LOG mechanism. The Event
    23  // holds type information (inputs) about the yielded output. Anonymous events
    24  // don't get the signature canonical representation as the first LOG topic.
    25  type Event struct {
    26  	Name      string
    27  	Anonymous bool
    28  	Inputs    Arguments
    29  }
    30  
    31  func (event Event) String() string {
    32  	inputs := make([]string, len(event.Inputs))
    33  	for i, input := range event.Inputs {
    34  		inputs[i] = fmt.Sprintf("%v %v", input.Name, input.Type)
    35  		if input.Indexed {
    36  			inputs[i] = fmt.Sprintf("%v indexed %v", input.Name, input.Type)
    37  		}
    38  	}
    39  	return fmt.Sprintf("event %v(%v)", event.Name, strings.Join(inputs, ", "))
    40  }
    41  
    42  // Id returns the canonical representation of the event's signature used by the
    43  // abi definition to identify event names and types.
    44  func (e Event) Id() common.Hash {
    45  	types := make([]string, len(e.Inputs))
    46  	i := 0
    47  	for _, input := range e.Inputs {
    48  		types[i] = input.Type.String()
    49  		i++
    50  	}
    51  	return common.BytesToHash(crypto.Keccak256([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ",")))))
    52  }