github.com/linapex/ethereum-go-chinese@v0.0.0-20190316121929-f8b7a73c3fa1/accounts/abi/event.go (about)

     1  
     2  //<developer>
     3  //    <name>linapex 曹一峰</name>
     4  //    <email>linapex@163.com</email>
     5  //    <wx>superexc</wx>
     6  //    <qqgroup>128148617</qqgroup>
     7  //    <url>https://jsq.ink</url>
     8  //    <role>pku engineer</role>
     9  //    <date>2019-03-16 19:16:31</date>
    10  //</624450061908054016>
    11  
    12  
    13  package abi
    14  
    15  import (
    16  	"fmt"
    17  	"strings"
    18  
    19  	"github.com/ethereum/go-ethereum/common"
    20  	"github.com/ethereum/go-ethereum/crypto"
    21  )
    22  
    23  //事件是可能由EVM的日志机制触发的事件。事件
    24  //保存有关生成的输出的类型信息(输入)。匿名事件
    25  //不要将签名规范表示作为第一个日志主题。
    26  type Event struct {
    27  	Name      string
    28  	Anonymous bool
    29  	Inputs    Arguments
    30  }
    31  
    32  func (e Event) String() string {
    33  	inputs := make([]string, len(e.Inputs))
    34  	for i, input := range e.Inputs {
    35  		inputs[i] = fmt.Sprintf("%v %v", input.Type, input.Name)
    36  		if input.Indexed {
    37  			inputs[i] = fmt.Sprintf("%v indexed %v", input.Type, input.Name)
    38  		}
    39  	}
    40  	return fmt.Sprintf("event %v(%v)", e.Name, strings.Join(inputs, ", "))
    41  }
    42  
    43  //ID返回由
    44  //用于标识事件名称和类型的ABI定义。
    45  func (e Event) Id() common.Hash {
    46  	types := make([]string, len(e.Inputs))
    47  	i := 0
    48  	for _, input := range e.Inputs {
    49  		types[i] = input.Type.String()
    50  		i++
    51  	}
    52  	return common.BytesToHash(crypto.Keccak256([]byte(fmt.Sprintf("%v(%v)", e.Name, strings.Join(types, ",")))))
    53  }
    54