-
Notifications
You must be signed in to change notification settings - Fork 12
/
message.go
84 lines (69 loc) · 2.78 KB
/
message.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
// SPDX-FileCopyrightText: 2023 PK Lab AG <contact@pklab.io>
// SPDX-License-Identifier: MIT
package responses
import (
"time"
"github.com/celenium-io/celestia-indexer/internal/storage"
"github.com/celenium-io/celestia-indexer/internal/storage/types"
pkgTypes "github.com/celenium-io/celestia-indexer/pkg/types"
)
type Message struct {
Id uint64 `example:"321" format:"int64" json:"id" swaggertype:"integer"`
Height pkgTypes.Level `example:"100" format:"int64" json:"height" swaggertype:"integer"`
Time time.Time `example:"2023-07-04T03:10:57+00:00" format:"date-time" json:"time" swaggertype:"string"`
Position int64 `example:"2" format:"int64" json:"position" swaggertype:"integer"`
TxId uint64 `example:"11" format:"int64" json:"tx_id,omitempty" swaggertype:"integer"`
Type types.MsgType `example:"MsgCreatePeriodicVestingAccount" json:"type"`
Data map[string]any `json:"data"`
Tx *Tx `json:"tx,omitempty"`
}
func NewMessage(msg storage.Message) Message {
return Message{
Id: msg.Id,
Height: msg.Height,
Time: msg.Time,
Position: msg.Position,
Type: msg.Type,
TxId: msg.TxId,
Data: msg.Data,
}
}
func NewMessageWithTx(msg storage.MessageWithTx) Message {
message := Message{
Id: msg.Id,
Height: msg.Height,
Time: msg.Time,
Position: msg.Position,
Type: msg.Type,
TxId: msg.TxId,
Data: msg.Data,
}
if msg.Tx != nil {
tx := NewTx(*msg.Tx)
message.Tx = &tx
}
return message
}
type MessageForAddress struct {
Id uint64 `example:"321" format:"int64" json:"id" swaggertype:"integer"`
Height pkgTypes.Level `example:"100" format:"int64" json:"height" swaggertype:"integer"`
Time time.Time `example:"2023-07-04T03:10:57+00:00" format:"date-time" json:"time" swaggertype:"string"`
Position int64 `example:"2" format:"int64" json:"position" swaggertype:"integer"`
TxId uint64 `example:"11" format:"int64" json:"tx_id,omitempty" swaggertype:"integer"`
Type types.MsgType `example:"MsgCreatePeriodicVestingAccount" json:"type"`
Data map[string]any `json:"data"`
Tx TxForAddress `json:"tx"`
}
func NewMessageForAddress(msg storage.AddressMessageWithTx) MessageForAddress {
message := MessageForAddress{
Id: msg.MsgId,
Height: msg.Msg.Height,
Time: msg.Msg.Time,
Position: msg.Msg.Position,
TxId: msg.Msg.TxId,
Type: msg.Msg.Type,
Data: msg.Msg.Data,
Tx: NewTxForAddress(msg.Tx),
}
return message
}