Skip to content

Commit

Permalink
fix: use prefixed store for certificates iterations
Browse files Browse the repository at this point in the history
Signed-off-by: Artur Troian <[email protected]>
  • Loading branch information
troian committed Jul 29, 2024
1 parent f859803 commit 7c08dc6
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
4 changes: 3 additions & 1 deletion x/cert/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/store/prefix"
sdk "github.com/cosmos/cosmos-sdk/types"

types "github.com/akash-network/akash-api/go/node/cert/v1beta3"
Expand Down Expand Up @@ -137,7 +138,8 @@ func (k keeper) WithCertificates(ctx sdk.Context, fn func(certificate types.Cert

// WithCertificates1 iterates all certificates
func (k keeper) WithCertificates1(ctx sdk.Context, fn func(id types.CertID, certificate types.CertificateResponse) bool) {
store := ctx.KVStore(k.skey)
store := prefix.NewStore(ctx.KVStore(k.skey), types.PrefixCertificateID())

iter := store.Iterator(nil, nil)

defer func() {
Expand Down
21 changes: 7 additions & 14 deletions x/cert/keeper/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,15 @@ func parseCertID(from []byte) (types.CertID, error) {
Serial: *big.NewInt(0),
}

// first byte is prefix id. skip it
from = from[1:]
addLen := from[0]
owner := make([]byte, from[0])
offset := copy(owner, from[1:])
offset++

from = from[1:]
res.Owner = sdk.AccAddress(owner)
res.Serial.SetBytes(from[offset:])

addr := from[:addLen-1]
serial := from[addLen:]

err := sdk.VerifyAddressFormat(addr)
if err != nil {
return res, err
}

res.Owner = sdk.AccAddress(addr)
res.Serial.SetBytes(serial)
strOwner := res.Owner.String()
_ = strOwner

return res, nil
}

0 comments on commit 7c08dc6

Please sign in to comment.