Skip to content

Commit 1f49d75

Browse files
authored
Merge pull request #1585 from CosmWasm/rename_key
Rename key store key attribute to be more concrete
2 parents 78b5af2 + 0d3bfce commit 1f49d75

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

x/wasm/alias.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ var (
133133
// Deprecated: Do not use.
134134
ErrInvalidMsg = types.ErrInvalidMsg
135135
// Deprecated: Do not use.
136-
KeyLastCodeID = types.KeyLastCodeID
136+
KeyLastCodeID = types.KeySequenceCodeID
137137
// Deprecated: Do not use.
138-
KeyLastInstanceID = types.KeyLastInstanceID
138+
KeyLastInstanceID = types.KeySequenceInstanceID
139139
// Deprecated: Do not use.
140140
CodeKeyPrefix = types.CodeKeyPrefix
141141
// Deprecated: Do not use.

x/wasm/keeper/addresses.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type AddressGenerator func(ctx sdk.Context, codeID uint64, checksum []byte) sdk.
1616
// ClassicAddressGenerator generates a contract address using codeID and instanceID sequence
1717
func (k Keeper) ClassicAddressGenerator() AddressGenerator {
1818
return func(ctx sdk.Context, codeID uint64, _ []byte) sdk.AccAddress {
19-
instanceID := k.autoIncrementID(ctx, types.KeyLastInstanceID)
19+
instanceID := k.autoIncrementID(ctx, types.KeySequenceInstanceID)
2020
return BuildContractAddressClassic(codeID, instanceID)
2121
}
2222
}

x/wasm/keeper/genesis.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,13 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]ab
6262
}
6363

6464
// sanity check seq values
65-
seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID)
65+
seqVal := keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID)
6666
if seqVal <= maxCodeID {
67-
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID)
67+
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeySequenceCodeID), seqVal, maxCodeID)
6868
}
69-
seqVal = keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID)
69+
seqVal = keeper.PeekAutoIncrementID(ctx, types.KeySequenceInstanceID)
7070
if seqVal <= uint64(maxContractID) {
71-
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID)
71+
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeySequenceInstanceID), seqVal, maxContractID)
7272
}
7373
return nil, nil
7474
}
@@ -111,7 +111,7 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState {
111111
return false
112112
})
113113

114-
for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} {
114+
for _, k := range [][]byte{types.KeySequenceCodeID, types.KeySequenceInstanceID} {
115115
genState.Sequences = append(genState.Sequences, types.Sequence{
116116
IDKey: k,
117117
Value: keeper.PeekAutoIncrementID(ctx, k),

x/wasm/keeper/genesis_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,8 @@ func TestGenesisInit(t *testing.T) {
171171
CodeBytes: wasmCode,
172172
}},
173173
Sequences: []types.Sequence{
174-
{IDKey: types.KeyLastCodeID, Value: 2},
175-
{IDKey: types.KeyLastInstanceID, Value: 1},
174+
{IDKey: types.KeySequenceCodeID, Value: 2},
175+
{IDKey: types.KeySequenceInstanceID, Value: 1},
176176
},
177177
Params: types.DefaultParams(),
178178
},
@@ -190,8 +190,8 @@ func TestGenesisInit(t *testing.T) {
190190
CodeBytes: wasmCode,
191191
}},
192192
Sequences: []types.Sequence{
193-
{IDKey: types.KeyLastCodeID, Value: 10},
194-
{IDKey: types.KeyLastInstanceID, Value: 1},
193+
{IDKey: types.KeySequenceCodeID, Value: 10},
194+
{IDKey: types.KeySequenceInstanceID, Value: 1},
195195
},
196196
Params: types.DefaultParams(),
197197
},
@@ -210,8 +210,8 @@ func TestGenesisInit(t *testing.T) {
210210
}},
211211
Contracts: nil,
212212
Sequences: []types.Sequence{
213-
{IDKey: types.KeyLastCodeID, Value: 3},
214-
{IDKey: types.KeyLastInstanceID, Value: 1},
213+
{IDKey: types.KeySequenceCodeID, Value: 3},
214+
{IDKey: types.KeySequenceInstanceID, Value: 1},
215215
},
216216
Params: types.DefaultParams(),
217217
},
@@ -281,8 +281,8 @@ func TestGenesisInit(t *testing.T) {
281281
},
282282
},
283283
Sequences: []types.Sequence{
284-
{IDKey: types.KeyLastCodeID, Value: 2},
285-
{IDKey: types.KeyLastInstanceID, Value: 2},
284+
{IDKey: types.KeySequenceCodeID, Value: 2},
285+
{IDKey: types.KeySequenceInstanceID, Value: 2},
286286
},
287287
Params: types.DefaultParams(),
288288
},
@@ -321,8 +321,8 @@ func TestGenesisInit(t *testing.T) {
321321
},
322322
},
323323
Sequences: []types.Sequence{
324-
{IDKey: types.KeyLastCodeID, Value: 2},
325-
{IDKey: types.KeyLastInstanceID, Value: 3},
324+
{IDKey: types.KeySequenceCodeID, Value: 2},
325+
{IDKey: types.KeySequenceInstanceID, Value: 3},
326326
},
327327
Params: types.DefaultParams(),
328328
},
@@ -433,7 +433,7 @@ func TestGenesisInit(t *testing.T) {
433433
CodeBytes: wasmCode,
434434
}},
435435
Sequences: []types.Sequence{
436-
{IDKey: types.KeyLastCodeID, Value: 1},
436+
{IDKey: types.KeySequenceCodeID, Value: 1},
437437
},
438438
Params: types.DefaultParams(),
439439
},
@@ -460,8 +460,8 @@ func TestGenesisInit(t *testing.T) {
460460
},
461461
},
462462
Sequences: []types.Sequence{
463-
{IDKey: types.KeyLastCodeID, Value: 2},
464-
{IDKey: types.KeyLastInstanceID, Value: 1},
463+
{IDKey: types.KeySequenceCodeID, Value: 2},
464+
{IDKey: types.KeySequenceInstanceID, Value: 1},
465465
},
466466
Params: types.DefaultParams(),
467467
},
@@ -626,8 +626,8 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
626626
},
627627
}
628628
assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr))
629-
assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID))
630-
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID))
629+
assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID))
630+
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeySequenceInstanceID))
631631
}
632632

633633
func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {

x/wasm/keeper/keeper.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte,
181181
if err != nil {
182182
return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error())
183183
}
184-
codeID = k.autoIncrementID(ctx, types.KeyLastCodeID)
184+
codeID = k.autoIncrementID(ctx, types.KeySequenceCodeID)
185185
k.Logger(ctx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID)
186186
codeInfo := types.NewCodeInfo(checksum, creator, *instantiateAccess)
187187
k.storeCodeInfo(ctx, codeID, codeInfo)
@@ -1030,36 +1030,36 @@ func (k Keeper) consumeRuntimeGas(ctx sdk.Context, gas uint64) {
10301030
}
10311031
}
10321032

1033-
func (k Keeper) autoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
1033+
func (k Keeper) autoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 {
10341034
store := ctx.KVStore(k.storeKey)
1035-
bz := store.Get(lastIDKey)
1035+
bz := store.Get(sequenceKey)
10361036
id := uint64(1)
10371037
if bz != nil {
10381038
id = binary.BigEndian.Uint64(bz)
10391039
}
10401040
bz = sdk.Uint64ToBigEndian(id + 1)
1041-
store.Set(lastIDKey, bz)
1041+
store.Set(sequenceKey, bz)
10421042
return id
10431043
}
10441044

10451045
// PeekAutoIncrementID reads the current value without incrementing it.
1046-
func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
1046+
func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 {
10471047
store := ctx.KVStore(k.storeKey)
1048-
bz := store.Get(lastIDKey)
1048+
bz := store.Get(sequenceKey)
10491049
id := uint64(1)
10501050
if bz != nil {
10511051
id = binary.BigEndian.Uint64(bz)
10521052
}
10531053
return id
10541054
}
10551055

1056-
func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uint64) error {
1056+
func (k Keeper) importAutoIncrementID(ctx sdk.Context, sequenceKey []byte, val uint64) error {
10571057
store := ctx.KVStore(k.storeKey)
1058-
if store.Has(lastIDKey) {
1059-
return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey))
1058+
if store.Has(sequenceKey) {
1059+
return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(sequenceKey))
10601060
}
10611061
bz := sdk.Uint64ToBigEndian(val)
1062-
store.Set(lastIDKey, bz)
1062+
store.Set(sequenceKey, bz)
10631063
return nil
10641064
}
10651065

x/wasm/simulation/genesis.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func RandomizedGenState(simstate *module.SimulationState) {
1414
Codes: nil,
1515
Contracts: nil,
1616
Sequences: []types.Sequence{
17-
{IDKey: types.KeyLastCodeID, Value: simstate.Rand.Uint64()},
17+
{IDKey: types.KeySequenceCodeID, Value: simstate.Rand.Uint64()},
1818
},
1919
}
2020

x/wasm/types/keys.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ var (
3434
ContractsByCreatorPrefix = []byte{0x09}
3535
ParamsKey = []byte{0x10}
3636

37-
KeyLastCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...)
38-
KeyLastInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...)
37+
KeySequenceCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...)
38+
KeySequenceInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...)
3939
)
4040

4141
// GetCodeKey constructs the key for retreiving the ID for the WASM code

0 commit comments

Comments
 (0)