@@ -85,12 +85,7 @@ func (k Keeper) CalculatePrices(ctx sdk.Context) {
85
85
return false
86
86
}
87
87
// collect validator information
88
- validatorInfo := types.ValidatorInfo {
89
- Index : idx ,
90
- Address : val .GetOperator (),
91
- Power : val .GetTokens ().Uint64 (),
92
- Status : status ,
93
- }
88
+ validatorInfo := types .NewValidatorInfo (idx , val .GetOperator (), val .GetTokens ().Uint64 (), status )
94
89
validatorsByPower = append (validatorsByPower , validatorInfo )
95
90
return false
96
91
})
@@ -138,13 +133,13 @@ func (k Keeper) CalculatePrices(ctx sdk.Context) {
138
133
havePrice := checkHavePrice (feed , valPrice , ctx .BlockTime ())
139
134
if havePrice {
140
135
priceFeedInfos = append (
141
- priceFeedInfos , types.PriceFeedInfo {
142
- PriceStatus : valPrice .PriceStatus ,
143
- Price : valPrice . Price ,
144
- Power : valInfo . Power ,
145
- Timestamp : valPrice .Timestamp ,
146
- Index : valInfo .Index ,
147
- } ,
136
+ priceFeedInfos , types .NewPriceFeedInfo (
137
+ valPrice .PriceStatus ,
138
+ valInfo . Power ,
139
+ valPrice . Price ,
140
+ valPrice .Timestamp ,
141
+ valInfo .Index ,
142
+ ) ,
148
143
)
149
144
}
150
145
}
@@ -192,22 +187,22 @@ func (k Keeper) CalculatePrice(
192
187
193
188
// If more than half of the total have unsupported price status, it returns an unsupported price status.
194
189
if unsupportedPower > totalPower / 2 {
195
- return types.Price {
196
- PriceStatus : types .PriceStatusUnsupported ,
197
- SignalID : feed .SignalID ,
198
- Price : 0 ,
199
- Timestamp : ctx .BlockTime ().Unix (),
200
- } , nil
190
+ return types .NewPrice (
191
+ types .PriceStatusUnsupported ,
192
+ feed .SignalID ,
193
+ 0 ,
194
+ ctx .BlockTime ().Unix (),
195
+ ) , nil
201
196
}
202
197
203
198
// If less than half of total have available price status, it returns an unavailable price status.
204
199
if availablePower < totalPower / 2 {
205
- return types.Price {
206
- PriceStatus : types .PriceStatusUnavailable ,
207
- SignalID : feed .SignalID ,
208
- Price : 0 ,
209
- Timestamp : ctx .BlockTime ().Unix (),
210
- } , nil
200
+ return types .NewPrice (
201
+ types .PriceStatusUnavailable ,
202
+ feed .SignalID ,
203
+ 0 ,
204
+ ctx .BlockTime ().Unix (),
205
+ ) , nil
211
206
}
212
207
213
208
price , err := types .CalculateMedianPriceFeedInfo (
@@ -217,12 +212,12 @@ func (k Keeper) CalculatePrice(
217
212
return types.Price {}, err
218
213
}
219
214
220
- return types.Price {
221
- PriceStatus : types .PriceStatusAvailable ,
222
- SignalID : feed .SignalID ,
223
- Price : price ,
224
- Timestamp : ctx .BlockTime ().Unix (),
225
- } , nil
215
+ return types .NewPrice (
216
+ types .PriceStatusAvailable ,
217
+ feed .SignalID ,
218
+ price ,
219
+ ctx .BlockTime ().Unix (),
220
+ ) , nil
226
221
}
227
222
228
223
// checkMissReport checks if a validator has missed a report based on the given parameters.
@@ -296,10 +291,10 @@ func (k Keeper) SetValidatorPriceList(
296
291
valAddress sdk.ValAddress ,
297
292
valPrices []types.ValidatorPrice ,
298
293
) error {
299
- valPricesList := types.ValidatorPriceList {
300
- Validator : valAddress . String () ,
301
- ValidatorPrices : valPrices ,
302
- }
294
+ valPricesList := types .NewValidatorPriceList (
295
+ valAddress ,
296
+ valPrices ,
297
+ )
303
298
304
299
ctx .KVStore (k .storeKey ).Set (types .ValidatorPriceListStoreKey (valAddress ), k .cdc .MustMarshal (& valPricesList ))
305
300
0 commit comments