-
Notifications
You must be signed in to change notification settings - Fork 51
/
event.go
100 lines (86 loc) · 1.92 KB
/
event.go
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package keeper
import (
"encoding/hex"
"strconv"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/hyperledger/burrow/execution/errors"
"github.com/hyperledger/burrow/execution/exec"
"github.com/shentufoundation/shentu/v2/x/cvm/types"
)
type EventSink struct {
ctx sdk.Context
}
func NewEventSink(ctx sdk.Context) *EventSink {
return &EventSink{ctx}
}
func (es *EventSink) Call(call *exec.CallEvent, exception *errors.Exception) error {
// do not log anything on the first call
if call.StackDepth == 0 {
return nil
}
caller, err := sdk.AccAddressFromHexUnsafe(call.CallData.Caller.String())
if err != nil {
return err
}
callee, err := sdk.AccAddressFromHexUnsafe(call.CallData.Callee.String())
if err != nil {
return err
}
es.ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeInternalCall,
sdk.Attribute{
Key: "caller",
Value: caller.String(),
},
sdk.Attribute{
Key: "callee",
Value: callee.String(),
},
sdk.Attribute{
Key: "data",
Value: call.CallData.Data.String(),
},
sdk.Attribute{
Key: "value",
Value: hex.EncodeToString(call.CallData.Value),
},
sdk.Attribute{
Key: "stack-depth",
Value: strconv.FormatUint(call.StackDepth, 10),
},
),
)
return nil
}
func (es *EventSink) Log(log *exec.LogEvent) error {
topicsString := ""
for _, topic := range log.Topics {
topicsString += topic.String()
}
b32addr, err := sdk.AccAddressFromHexUnsafe(log.Address.String())
if err != nil {
panic("address data in CVM is corrupted")
}
es.ctx.EventManager().EmitEvent(
sdk.NewEvent(
types.EventTypeCVMEvent,
sdk.Attribute{
Key: "address",
Value: b32addr.String(),
},
sdk.Attribute{
Key: "topics",
Value: topicsString,
},
sdk.Attribute{
Key: "data",
Value: log.Data.String(),
},
),
)
return nil
}
func (es *EventSink) Print(print *exec.PrintEvent) error {
return nil
}