-
Notifications
You must be signed in to change notification settings - Fork 18
/
model.go
207 lines (181 loc) · 8.24 KB
/
model.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
// Package governor handle the request of governor data from governor endpoint defined in the api.
package governor
import (
"encoding/json"
"strconv"
"time"
"github.com/wormhole-foundation/wormhole-explorer/api/internal/mongo"
"github.com/wormhole-foundation/wormhole/sdk/vaa"
)
// GovConfigPage represent a governor configuration.
type GovConfig struct {
ID string `bson:"_id" json:"id"`
CreatedAt *time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
NodeName string `bson:"nodename" json:"nodeName"`
Counter int `bson:"counter" json:"counter"`
Chains []*GovConfigChains `bson:"chains" json:"chains"`
Tokens []*GovConfigfTokens `bson:"tokens" json:"tokens"`
}
type GovConfigChains struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
NotionalLimit mongo.Uint64 `bson:"notionallimit" json:"notionalLimit"`
BigTransactionSize mongo.Uint64 `bson:"bigtransactionsize" json:"bigTransactionSize"`
}
type GovConfigfTokens struct {
OriginChainID int `bson:"originchainid" json:"originChainId"`
OriginAddress string `bson:"originaddress" json:"originAddress"`
Price float32 `bson:"price" json:"price"`
}
// GovStatusPage represent a governor status.
type GovStatus struct {
ID string `bson:"_id" json:"id"`
CreatedAt *time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
NodeName string `bson:"nodename" json:"nodeName"`
Chains []*GovStatusChains `bson:"chains" json:"chains"`
}
type GovStatusChains struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
RemainingAvailableNotional mongo.Uint64 `bson:"remainingavailablenotional" json:"remainingAvailableNotional"`
Emitters []*GovStatusChainEmitter `bson:"emitters" json:"emitters"`
}
type GovStatusChainEmitter struct {
EmitterAddress string `bson:"emitteraddress" json:"emitterAddress"`
TotalEnqueuedVaas mongo.Uint64 `bson:"totalenqueuedvaas" json:"totalEnqueuedVaas"`
EnqueuedVass interface{} `bson:"enqueuedvaas" json:"enqueuedVaas"`
}
// NotionalLimit represent the notional limit value and maximun tranasction size for a chainID.
type NotionalLimit struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
NotionalLimit *mongo.Uint64 `bson:"notionalLimit" json:"notionalLimit"`
MaxTrasactionSize *mongo.Uint64 `bson:"maxTransactionSize" json:"maxTransactionSize"`
}
// NotionalLimitDetail represent a notional limit value
type NotionalLimitDetail struct {
ID string `bson:"_id" json:"id"`
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
NodeName string `bson:"nodename" json:"nodeName"`
NotionalLimit *mongo.Uint64 `bson:"notionalLimit" json:"notionalLimit"`
MaxTrasactionSize *mongo.Uint64 `bson:"maxTransactionSize" json:"maxTransactionSize"`
CreatedAt *time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
}
// NotionalAvailable represent the available notional for chainID.
type NotionalAvailable struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
AvailableNotional *mongo.Uint64 `bson:"availableNotional" json:"availableNotional"`
}
// NotionalAvailableDetail represent a notional available value.
type NotionalAvailableDetail struct {
ID string `bson:"_id" json:"id"`
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
NodeName string `bson:"nodeName" json:"nodeName"`
NotionalAvailable *mongo.Uint64 `bson:"availableNotional" json:"availableNotional"`
CreatedAt *time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
}
type Emitter struct {
Address string `bson:"emitteraddress" json:"emitterAddress"`
TotalEnqueuedVaas mongo.Uint64 `bson:"totalenqueuedvaas" json:"totalEnqueuedVaas"`
EnqueuedVaas []EnqueuedVAA `bson:"enqueuedvaas" json:"enqueuedVaas"`
}
// EnqueuedVAA definition.
type EnqueuedVAA struct {
Sequence string `bson:"sequence" json:"sequence"`
ReleaseTime *time.Time `bson:"releasetime" json:"releaseTime"`
Notional *mongo.Uint64 `bson:"notionalvalue" json:"notionalValue"`
TxHash string `bson:"txhash" json:"txHash"`
}
// MaxNotionalAvailableRecord definition.
type MaxNotionalAvailableRecord struct {
ID string `bson:"_id" json:"id"`
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
NodeName string `bson:"nodeName" json:"nodeName"`
NotionalAvailable *mongo.Uint64 `bson:"availableNotional" json:"availableNotional"`
Emitters []Emitter `bson:"emitters" json:"emitters"`
CreatedAt *time.Time `bson:"createdAt" json:"createdAt"`
UpdatedAt *time.Time `bson:"updatedAt" json:"updatedAt"`
}
// EnqueuedVaa definition.
type EnqueuedVaa struct {
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
EmitterAddress string `bson:"emitterAddress" json:"emitterAddress"`
Sequence string `bson:"sequence" json:"sequence"`
NotionalValue int64 `bson:"notionalValue" json:"notionalValue"`
TxHash string `bson:"txHash" json:"txHash"`
}
// MarshalJSON interface implementation.
func (v *EnqueuedVaa) MarshalJSON() ([]byte, error) {
sequence, err := strconv.ParseUint(v.Sequence, 10, 64)
if err != nil {
return []byte{}, err
}
type Alias EnqueuedVaa
return json.Marshal(&struct {
Sequence uint64 `json:"sequence"`
*Alias
}{
Sequence: sequence,
Alias: (*Alias)(v),
})
}
// EnqueuedVaas definition.
type EnqueuedVaas struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
EnqueuedVaa []*EnqueuedVaa `bson:"enqueuedVaas" json:"enqueuedVaas"`
}
// EnqueuedVaaDetail definition.
type EnqueuedVaaDetail struct {
ChainID vaa.ChainID `bson:"chainid" json:"chainId"`
EmitterAddress string `bson:"emitterAddress" json:"emitterAddress"`
Sequence string `bson:"sequence" json:"sequence"`
NotionalValue int64 `bson:"notionalValue" json:"notionalValue"`
TxHash string `bson:"txHash" json:"txHash"`
ReleaseTime int64 `bson:"releaseTime" json:"releaseTime"`
}
// MarshalJSON interface implementation.
func (v *EnqueuedVaaDetail) MarshalJSON() ([]byte, error) {
sequence, err := strconv.ParseUint(v.Sequence, 10, 64)
if err != nil {
return []byte{}, err
}
type Alias EnqueuedVaaDetail
return json.Marshal(&struct {
Sequence uint64 `json:"sequence"`
*Alias
}{
Sequence: sequence,
Alias: (*Alias)(v),
})
}
// GovernorLimit definition.
type GovernorLimit struct {
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
AvailableNotional mongo.Uint64 `bson:"availableNotional" json:"availableNotional"`
NotionalLimit mongo.Uint64 `bson:"notionalLimit" json:"notionalLimit"`
MaxTransactionSize mongo.Uint64 `bson:"maxTransactionSize" json:"maxTransactionSize"`
}
// AvailableNotionalByChain definition.
// This is the structure that is used in guardian api grpc api version.
type AvailableNotionalByChain struct {
ChainID vaa.ChainID `bson:"chainId" json:"chainId"`
AvailableNotional mongo.Uint64 `bson:"availableNotional" json:"remainingAvailableNotional"`
NotionalLimit mongo.Uint64 `bson:"notionalLimit" json:"notionalLimit"`
MaxTransactionSize mongo.Uint64 `bson:"maxTransactionSize" json:"bigTransactionSize"`
}
// TokenList definition
type TokenList struct {
OriginChainID vaa.ChainID `bson:"originchainid" json:"originChainId"`
OriginAddress string `bson:"originaddress" json:"originAddress"`
Price float32 `bson:"price" json:"price"`
}
// EnqueuedVaaItem definition
type EnqueuedVaaItem struct {
EmitterChain vaa.ChainID `bson:"chainid" json:"emitterChain"`
EmitterAddress string `bson:"emitteraddress" json:"emitterAddress"`
Sequence string `bson:"sequence" json:"sequence"`
ReleaseTime int64 `bson:"releasetime" json:"releaseTime"`
NotionalValue mongo.Uint64 `bson:"notionalvalue" json:"notionalValue"`
TxHash string `bson:"txhash" json:"txHash"`
}