github.com/arieschain/arieschain@v0.0.0-20191023063405-37c074544356/accounts/abi/event.go (about)

     1  package abi
     2  
     3  import (
     4  	"fmt"
     5  	"strings"
     6  
     7  	"github.com/quickchainproject/quickchain/common"
     8  	"github.com/quickchainproject/quickchain/crypto"
     9  )
    10  
    11  // Event is an event potentially triggered by the EVM's LOG mechanism. The Event
    12  // holds type information (inputs) about the yielded output. Anonymous events
    13  // don't get the signature canonical representation as the first LOG topic.
    14  type Event struct {
    15  	Name      string
    16  	Anonymous bool
    17  	Inputs    Arguments
    18  }
    19  
    20  func (e Event) String() string {
    21  	inputs := make([]string, len(e.Inputs))
    22  	for i, input := range e.Inputs {
    23  		inputs[i] = fmt.Sprintf("%v %v", input.Name, input.Type)
    24  		if input.Indexed {
    25  			inputs[i] = fmt.Sprintf("%v indexed %v", input.Name, input.Type)
    26  		}
    27  	}
    28  	return fmt.Sprintf("e %v(%v)", e.Name, strings.Join(inputs, ", "))
    29  }
    30  
    31  // Id returns the canonical representation of the event's signature used by the
    32  // abi definition to identify event names and types.
    33  func (e Event) Id() common.Hash {
    34  	types := make([]string, len(e.Inputs))
    35  	i := 0
    36  	for _, input := range e.Inputs {
    37  		types[i] = input.Type.String()
    38  		i++
    39  	}
    40  	return common.BytesToHash(crypto.Keccak256([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ",")))))
    41  }