@@ -110,14 +110,14 @@ func readStateBucketCount(ctx context.Context, csr CandidateStateReader,
110
110
if err != nil {
111
111
return nil, 0, err
112
112
}
113
- active , err := getActiveBucketsCount (ctx , csr )
113
+ active, h, err := getActiveBucketsCount(ctx, csr)
114
114
if err != nil {
115
- return nil , 0 , err
115
+ return nil, h , err
116
116
}
117
117
return &iotextypes.BucketsCount{
118
118
Total: total,
119
119
Active: active,
120
- }, csr . Height () , nil
120
+ }, h , nil
121
121
}
122
122
123
123
func readStateCandidates(ctx context.Context, csr CandidateStateReader,
@@ -155,12 +155,12 @@ func readStateTotalStakingAmount(ctx context.Context, csr CandidateStateReader,
155
155
_ *iotexapi.ReadStakingDataRequest_TotalStakingAmount) (*iotextypes.AccountMeta, uint64, error) {
156
156
meta := iotextypes.AccountMeta{}
157
157
meta.Address = address.StakingBucketPoolAddr
158
- total , err := getTotalStakedAmount (ctx , csr )
158
+ total, h, err := getTotalStakedAmount(ctx, csr)
159
159
if err != nil {
160
- return nil , csr . Height () , err
160
+ return nil, h , err
161
161
}
162
162
meta.Balance = total.String()
163
- return & meta , csr . Height () , nil
163
+ return &meta, h , nil
164
164
}
165
165
166
166
func toIoTeXTypesVoteBucketList(buckets []*VoteBucket) (*iotextypes.VoteBucketList, error) {
@@ -219,35 +219,35 @@ func getPageOfCandidates(candidates CandidateList, offset, limit int) CandidateL
219
219
return res
220
220
}
221
221
222
- func getTotalStakedAmount (ctx context.Context , csr CandidateStateReader ) (* big.Int , error ) {
222
+ func getTotalStakedAmount(ctx context.Context, csr CandidateStateReader) (*big.Int, uint64, error) {
223
223
chainCtx := protocol.MustGetBlockchainCtx(ctx)
224
224
hu := config.NewHeightUpgrade(&chainCtx.Genesis)
225
225
if hu.IsPost(config.Greenland, csr.Height()) {
226
226
// after Greenland, read state from db
227
227
var total totalAmount
228
- _ , err := csr .SR ().State (& total , protocol .NamespaceOption (StakingNameSpace ), protocol .KeyOption (bucketPoolAddrKey ))
228
+ h , err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
229
229
if err != nil {
230
- return nil , err
230
+ return nil, h, err
231
231
}
232
- return total .amount , nil
232
+ return total.amount, h, nil
233
233
}
234
234
235
235
// otherwise read from bucket pool
236
- return csr .TotalStakedAmount (), nil
236
+ return csr.TotalStakedAmount(), csr.Height(), nil
237
237
}
238
238
239
- func getActiveBucketsCount (ctx context.Context , csr CandidateStateReader ) (uint64 , error ) {
239
+ func getActiveBucketsCount(ctx context.Context, csr CandidateStateReader) (uint64, uint64, error) {
240
240
chainCtx := protocol.MustGetBlockchainCtx(ctx)
241
241
hu := config.NewHeightUpgrade(&chainCtx.Genesis)
242
242
if hu.IsPost(config.Greenland, csr.Height()) {
243
243
// after Greenland, read state from db
244
244
var total totalAmount
245
- _ , err := csr .SR ().State (& total , protocol .NamespaceOption (StakingNameSpace ), protocol .KeyOption (bucketPoolAddrKey ))
245
+ h , err := csr.SR().State(&total, protocol.NamespaceOption(StakingNameSpace), protocol.KeyOption(bucketPoolAddrKey))
246
246
if err != nil {
247
- return 0 , err
247
+ return 0, h, err
248
248
}
249
- return total .count , nil
249
+ return total.count, h, nil
250
250
}
251
251
// otherwise read from bucket pool
252
- return csr .ActiveBucketsCount (), nil
252
+ return csr.ActiveBucketsCount(), csr.Height(), nil
253
253
}
0 commit comments