aboutsummaryrefslogtreecommitdiffstats
path: root/state/log.go
blob: 49da3053588cac3029b2e934f7e3f68eada17fb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package state

import (
    "fmt"
    "strings"

    "github.com/ethereum/go-ethereum/ethutil"
)

type Log struct {
    Address []byte
    Topics  [][]byte
    Data    []byte
}

func NewLogFromValue(decoder *ethutil.Value) *Log {
    log := &Log{
        Address: decoder.Get(0).Bytes(),
        Data:    decoder.Get(2).Bytes(),
    }

    it := decoder.Get(1).NewIterator()
    for it.Next() {
        log.Topics = append(log.Topics, it.Value().Bytes())
    }

    return log
}

func (self *Log) RlpData() interface{} {
    return []interface{}{self.Address, ethutil.ByteSliceToInterface(self.Topics), self.Data}
}

func (self *Log) String() string {
    return fmt.Sprintf(`log: %x %x %x`, self.Address, self.Topics, self.Data)
}

type Logs []*Log

func (self Logs) RlpData() interface{} {
    data := make([]interface{}, len(self))
    for i, log := range self {
        data[i] = log.RlpData()
    }

    return data
}

func (self Logs) String() string {
    var logs []string
    for _, log := range self {
        logs = append(logs, log.String())
    }
    return "[ " + strings.Join(logs, ", ") + " ]"
}