From 7c08dc6ec7ed6751f0e05f389f698c66e135f710 Mon Sep 17 00:00:00 2001 From: Artur Troian Date: Mon, 29 Jul 2024 11:50:07 -0500 Subject: [PATCH] fix: use prefixed store for certificates iterations Signed-off-by: Artur Troian --- x/cert/keeper/keeper.go | 4 +++- x/cert/keeper/key.go | 21 +++++++-------------- 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/x/cert/keeper/keeper.go b/x/cert/keeper/keeper.go index fdc7c2560..9b7a28548 100644 --- a/x/cert/keeper/keeper.go +++ b/x/cert/keeper/keeper.go @@ -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" @@ -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() { diff --git a/x/cert/keeper/key.go b/x/cert/keeper/key.go index b75ccefad..0c4573ccd 100644 --- a/x/cert/keeper/key.go +++ b/x/cert/keeper/key.go @@ -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 }