github.com/karalabe/go-ethereum@v0.8.5/state/log.go (about)

     1  package state
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/ethereum/go-ethereum/ethutil"
     7  )
     8  
     9  type Log interface {
    10  	ethutil.RlpEncodable
    11  
    12  	Address() []byte
    13  	Topics() [][]byte
    14  	Data() []byte
    15  
    16  	Number() uint64
    17  }
    18  
    19  type StateLog struct {
    20  	address []byte
    21  	topics  [][]byte
    22  	data    []byte
    23  	number  uint64
    24  }
    25  
    26  func NewLog(address []byte, topics [][]byte, data []byte, number uint64) *StateLog {
    27  	return &StateLog{address, topics, data, number}
    28  }
    29  
    30  func (self *StateLog) Address() []byte {
    31  	return self.address
    32  }
    33  
    34  func (self *StateLog) Topics() [][]byte {
    35  	return self.topics
    36  }
    37  
    38  func (self *StateLog) Data() []byte {
    39  	return self.data
    40  }
    41  
    42  func (self *StateLog) Number() uint64 {
    43  	return self.number
    44  }
    45  
    46  func NewLogFromValue(decoder *ethutil.Value) *StateLog {
    47  	log := &StateLog{
    48  		address: decoder.Get(0).Bytes(),
    49  		data:    decoder.Get(2).Bytes(),
    50  	}
    51  
    52  	it := decoder.Get(1).NewIterator()
    53  	for it.Next() {
    54  		log.topics = append(log.topics, it.Value().Bytes())
    55  	}
    56  
    57  	return log
    58  }
    59  
    60  func (self *StateLog) RlpData() interface{} {
    61  	return []interface{}{self.address, ethutil.ByteSliceToInterface(self.topics), self.data}
    62  }
    63  
    64  func (self *StateLog) String() string {
    65  	return fmt.Sprintf(`log: %x %x %x`, self.address, self.topics, self.data)
    66  }
    67  
    68  type Logs []Log
    69  
    70  func (self Logs) RlpData() interface{} {
    71  	data := make([]interface{}, len(self))
    72  	for i, log := range self {
    73  		data[i] = log.RlpData()
    74  	}
    75  
    76  	return data
    77  }
    78  
    79  func (self Logs) String() (ret string) {
    80  	for _, log := range self {
    81  		ret += fmt.Sprintf("%v", log)
    82  	}
    83  
    84  	return "[" + ret + "]"
    85  }