-
Notifications
You must be signed in to change notification settings - Fork 36
/
events.go
123 lines (112 loc) · 4.55 KB
/
events.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
package types
import (
"encoding/base64"
time "time"
)
const (
// EventTypeAttributeAdded emitted when account attributes are added.
EventTypeAttributeAdded string = "account_attribute_added"
// EventTypeAttributeUpdated emitted when account attributes are updated.
EventTypeAttributeUpdated string = "account_attribute_updated"
// EventTypeAttributeUpdated emitted when a attribute's expiration date is updated.
EventTypeAttributeExpirationUpdated string = "account_attribute_expiration_updated"
// EventTypeAttributeDeleted emitted when account attributes are removed.
EventTypeAttributeDeleted string = "account_attribute_deleted"
// EventTypeAttributeDistinctDeleted emitted when a distinct account attribute is deleted.
EventTypeAttributeDistinctDeleted string = "account_attribute_distinct_deleted"
// EventTypeDeletedExpired emitted when attributes have expired and been deleted in begin blocker
EventTypeDeletedExpired string = "attribute_deleted_expired"
AttributeKeyAttribute string = "attribute"
AttributeKeyNameAttribute string = "attribute_name"
AttributeKeyAccountAddress string = "account_address"
AttributeKeyTotalExpired string = "total_expired_deleted"
// EventTelemetryKeyAdd add telemetry metrics key
EventTelemetryKeyAdd string = "add"
// EventTelemetryKeyUpdate add telemetry metrics key
EventTelemetryKeyUpdate string = "update"
// EventTelemetryKeyDelete delete telemetry metrics key
EventTelemetryKeyDelete string = "delete"
// EventTelemetryKeyDistinctDelete delete telemetry metrics key
EventTelemetryKeyDistinctDelete string = "distinct_delete"
// EventTelemetryLabelName name telemetry metrics label
EventTelemetryLabelName string = "name"
// EventTelemetryLabelName name telemetry metrics label
EventTelemetryLabelValue string = "value"
// EventTelemetryLabelType type telemetry metrics label
EventTelemetryLabelType string = "type"
// EventTelemetryLabelOwner owner telemetry metrics label
EventTelemetryLabelOwner string = "owner"
// EventTelemetryKeyAccount acount telemetry metrics label
EventTelemetryLabelAccount string = "account"
// EventTelemetryKeyAccount size telemetry metrics label
EventTelemetryLabelSize string = "size"
)
func NewEventAttributeAdd(attribute Attribute, owner string) *EventAttributeAdd {
var expirationDate string
if attribute.ExpirationDate != nil {
expirationDate = attribute.ExpirationDate.String()
}
return &EventAttributeAdd{
Name: attribute.Name,
Value: base64.StdEncoding.EncodeToString(attribute.GetValue()),
Type: attribute.AttributeType.String(),
Account: attribute.Address,
Owner: owner,
Expiration: expirationDate,
}
}
func NewEventAttributeUpdate(originalAttribute Attribute, updateAttribute Attribute, owner string) *EventAttributeUpdate {
return &EventAttributeUpdate{
Name: originalAttribute.Name,
OriginalValue: base64.StdEncoding.EncodeToString(originalAttribute.GetValue()),
OriginalType: originalAttribute.AttributeType.String(),
UpdateValue: base64.StdEncoding.EncodeToString(updateAttribute.GetValue()),
UpdateType: updateAttribute.AttributeType.String(),
Account: originalAttribute.Address,
Owner: owner,
}
}
func NewEventAttributeExpirationUpdate(attribute Attribute, originalExpiration *time.Time, owner string) *EventAttributeExpirationUpdate {
var original, updated string
if attribute.ExpirationDate != nil {
updated = attribute.ExpirationDate.String()
}
if originalExpiration != nil {
original = originalExpiration.String()
}
return &EventAttributeExpirationUpdate{
Name: attribute.Name,
Value: base64.StdEncoding.EncodeToString(attribute.GetValue()),
Account: attribute.Address,
Owner: owner,
OriginalExpiration: original,
UpdatedExpiration: updated,
}
}
func NewEventAttributeDelete(name string, account string, owner string) *EventAttributeDelete {
return &EventAttributeDelete{
Name: name,
Owner: owner,
Account: account,
}
}
func NewEventDistinctAttributeDelete(name string, value string, account string, owner string) *EventAttributeDistinctDelete {
return &EventAttributeDistinctDelete{
Name: name,
Value: value,
Owner: owner,
Account: account,
}
}
func NewEventAttributeExpired(attribute Attribute) *EventAttributeExpired {
var expiredTime string
if attribute.ExpirationDate != nil {
expiredTime = attribute.ExpirationDate.String()
}
return &EventAttributeExpired{
Name: attribute.Name,
ValueHash: string(attribute.Hash()),
Account: attribute.Address,
Expiration: expiredTime,
}
}