added get_reissuances call body

Signed-off-by: Jürgen Eckel <juergen@riddleandcode.com>
This commit is contained in:
Jürgen Eckel 2023-10-06 13:08:23 +02:00
parent ef52e51ec8
commit dac2d96194
No known key found for this signature in database
2 changed files with 23 additions and 3 deletions

View File

@ -16,8 +16,9 @@ func (k Keeper) GetReissuances(goCtx context.Context, req *types.QueryGetReissua
ctx := sdk.UnwrapSDKContext(goCtx)
// TODO: Process the query
_ = ctx
reissuances := k.getReissuancesPage(ctx, req.Pagination.GetKey(),
req.Pagination.GetOffset(), req.Pagination.GetLimit(),
req.Pagination.GetCountTotal(), req.Pagination.GetReverse())
return &types.QueryGetReissuancesResponse{}, nil
return &types.QueryGetReissuancesResponse{Reissuance: &reissuances[0]}, nil
}

View File

@ -24,6 +24,25 @@ func (k Keeper) LookupReissuance(ctx sdk.Context, height uint64) (val types.Reis
return val, true
}
func (k Keeper) getReissuancesPage(ctx sdk.Context, key []byte, offset uint64, page_size uint64, all bool, reverse bool) (reissuances []types.Reissuance) {
store := prefix.NewStore(ctx.KVStore(k.storeKey), types.KeyPrefix(types.ReissuanceBlockHeightKey))
iterator := store.Iterator(nil, nil)
defer iterator.Close()
if reverse {
iterator = store.ReverseIterator(nil, nil)
defer iterator.Close()
}
for ; iterator.Valid(); iterator.Next() {
reissuance := iterator.Value()
var reissuance_org types.Reissuance
k.cdc.MustUnmarshal(reissuance, &reissuance_org)
reissuances = append(reissuances, reissuance_org)
}
return reissuances
}
func getReissuanceBytes(height uint64) []byte {
// Adding 1 because 0 will be interpreted as nil, which is an invalid key
return big.NewInt(int64(height + 1)).Bytes()