Skip to content

Commit

Permalink
Merge pull request #669 from CosmWasm/api-cleanup
Browse files Browse the repository at this point in the history
Open read access to sequences
  • Loading branch information
alpe authored Nov 8, 2021
2 parents 14e58bf + 445fbb7 commit 090b8e9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 17 deletions.
6 changes: 3 additions & 3 deletions x/wasm/keeper/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState, staki
}

// sanity check seq values
seqVal := keeper.peekAutoIncrementID(ctx, types.KeyLastCodeID)
seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID)
if seqVal <= maxCodeID {
return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID)
}
seqVal = keeper.peekAutoIncrementID(ctx, types.KeyLastInstanceID)
seqVal = keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID)
if seqVal <= uint64(maxContractID) {
return nil, sdkerrors.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID)
}
Expand Down Expand Up @@ -125,7 +125,7 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState {
for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} {
genState.Sequences = append(genState.Sequences, types.Sequence{
IDKey: k,
Value: keeper.peekAutoIncrementID(ctx, k),
Value: keeper.PeekAutoIncrementID(ctx, k),
})
}

Expand Down
16 changes: 2 additions & 14 deletions x/wasm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -911,18 +911,6 @@ func assertNil(err error) {
}
}

// GetNextCodeID reads the next sequence id used for storing wasm code.
// Read only operation.
func (k Keeper) GetNextCodeID(ctx sdk.Context) uint64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(types.KeyLastCodeID)
id := uint64(1)
if bz != nil {
id = binary.BigEndian.Uint64(bz)
}
return id
}

func (k Keeper) autoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(lastIDKey)
Expand All @@ -935,8 +923,8 @@ func (k Keeper) autoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
return id
}

// peekAutoIncrementID reads the current value without incrementing it.
func (k Keeper) peekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
// PeekAutoIncrementID reads the current value without incrementing it.
func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
store := ctx.KVStore(k.storeKey)
bz := store.Get(lastIDKey)
id := uint64(1)
Expand Down

0 comments on commit 090b8e9

Please sign in to comment.