github.com/status-im/status-go@v1.1.0/services/wallet/walletevent/events.go (about) 1 package walletevent 2 3 import ( 4 "encoding/json" 5 "math/big" 6 "strings" 7 8 "github.com/ethereum/go-ethereum/common" 9 ) 10 11 // EventType type for event types. 12 type EventType string 13 14 // EventType prefix to be used for internal events. 15 // These events are not forwarded to the client, they are only used 16 // within status-go. 17 const InternalEventTypePrefix = "INT-" 18 19 func (t EventType) IsInternal() bool { 20 return strings.HasPrefix(string(t), InternalEventTypePrefix) 21 } 22 23 // Event is a type for transfer events. 24 type Event struct { 25 Type EventType `json:"type"` 26 BlockNumber *big.Int `json:"blockNumber"` 27 Accounts []common.Address `json:"accounts"` 28 Message string `json:"message"` 29 At int64 `json:"at"` 30 ChainID uint64 `json:"chainId"` 31 RequestID *int `json:"requestId,omitempty"` 32 // For Internal events only, not serialized 33 EventParams interface{} 34 } 35 36 func GetPayload[T any](e Event) (*T, error) { 37 var payload T 38 err := json.Unmarshal([]byte(e.Message), &payload) 39 if err != nil { 40 return nil, err 41 } 42 return &payload, nil 43 } 44 45 func ExtractPayload[T any](e Event, payload *T) error { 46 return json.Unmarshal([]byte(e.Message), payload) 47 }