@@ -1165,13 +1165,8 @@ func (api *Server) getBlockMetas(start uint64, count uint64) (*iotexapi.GetBlock
1165
1165
}
1166
1166
var res []* iotextypes.BlockMeta
1167
1167
for height := start ; height <= tipHeight && count > 0 ; height ++ {
1168
- blockMeta , err := api .getBlockMetasByHeader (height )
1169
- if errors .Cause (err ) == db .ErrNotExist {
1170
- blockMeta , err = api .getBlockMetasByBlock (height )
1171
- if err != nil {
1172
- return nil , err
1173
- }
1174
- } else if err != nil {
1168
+ blockMeta , err := api .getBlockMetaByHeight (height )
1169
+ if err != nil {
1175
1170
return nil , err
1176
1171
}
1177
1172
res = append (res , blockMeta )
@@ -1189,13 +1184,8 @@ func (api *Server) getBlockMeta(blkHash string) (*iotexapi.GetBlockMetasResponse
1189
1184
if err != nil {
1190
1185
return nil , status .Error (codes .InvalidArgument , err .Error ())
1191
1186
}
1192
- blockMeta , err := api .getBlockMetaByHeader (hash )
1193
- if errors .Cause (err ) == db .ErrNotExist {
1194
- blockMeta , err = api .getBlockMetaByBlock (hash )
1195
- if err != nil {
1196
- return nil , err
1197
- }
1198
- } else if err != nil {
1187
+ blockMeta , err := api .getBlockMetaByHash (hash )
1188
+ if err != nil {
1199
1189
return nil , err
1200
1190
}
1201
1191
return & iotexapi.GetBlockMetasResponse {
@@ -1204,6 +1194,28 @@ func (api *Server) getBlockMeta(blkHash string) (*iotexapi.GetBlockMetasResponse
1204
1194
}, nil
1205
1195
}
1206
1196
1197
+ // getBlockMetaByHeight gets block meta by height
1198
+ func (api * Server ) getBlockMetaByHeight (height uint64 ) (* iotextypes.BlockMeta , error ) {
1199
+ if api .indexer != nil {
1200
+ blockMeta , err := api .getBlockMetasByHeader (height )
1201
+ if errors .Cause (err ) != db .ErrNotExist {
1202
+ return blockMeta , err
1203
+ }
1204
+ }
1205
+ return api .getBlockMetasByBlock (height )
1206
+ }
1207
+
1208
+ // getBlockMetaByHash gets block meta by hash
1209
+ func (api * Server ) getBlockMetaByHash (h hash.Hash256 ) (* iotextypes.BlockMeta , error ) {
1210
+ if api .indexer != nil {
1211
+ blockMeta , err := api .getBlockMetaByHeader (h )
1212
+ if errors .Cause (err ) != db .ErrNotExist {
1213
+ return blockMeta , err
1214
+ }
1215
+ }
1216
+ return api .getBlockMetaByBlock (h )
1217
+ }
1218
+
1207
1219
// putBlockMetaUpgradeByBlock puts numActions and transferAmount for blockmeta by block
1208
1220
func (api * Server ) putBlockMetaUpgradeByBlock (blk * block.Block , blockMeta * iotextypes.BlockMeta ) * iotextypes.BlockMeta {
1209
1221
blockMeta .NumActions = int64 (len (blk .Actions ))
0 commit comments