Rename key store key attribute to be more concrete
Please enter the commit message for your changes. Lines starting
This commit is contained in:
@@ -133,9 +133,9 @@ var (
|
||||
// Deprecated: Do not use.
|
||||
ErrInvalidMsg = types.ErrInvalidMsg
|
||||
// Deprecated: Do not use.
|
||||
KeyLastCodeID = types.KeyLastCodeID
|
||||
KeyLastCodeID = types.KeySequenceCodeID
|
||||
// Deprecated: Do not use.
|
||||
KeyLastInstanceID = types.KeyLastInstanceID
|
||||
KeyLastInstanceID = types.KeySequenceInstanceID
|
||||
// Deprecated: Do not use.
|
||||
CodeKeyPrefix = types.CodeKeyPrefix
|
||||
// Deprecated: Do not use.
|
||||
|
||||
@@ -16,7 +16,7 @@ type AddressGenerator func(ctx sdk.Context, codeID uint64, checksum []byte) sdk.
|
||||
// ClassicAddressGenerator generates a contract address using codeID and instanceID sequence
|
||||
func (k Keeper) ClassicAddressGenerator() AddressGenerator {
|
||||
return func(ctx sdk.Context, codeID uint64, _ []byte) sdk.AccAddress {
|
||||
instanceID := k.autoIncrementID(ctx, types.KeyLastInstanceID)
|
||||
instanceID := k.autoIncrementID(ctx, types.KeySequenceInstanceID)
|
||||
return BuildContractAddressClassic(codeID, instanceID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,13 +62,13 @@ func InitGenesis(ctx sdk.Context, keeper *Keeper, data types.GenesisState) ([]ab
|
||||
}
|
||||
|
||||
// sanity check seq values
|
||||
seqVal := keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID)
|
||||
seqVal := keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID)
|
||||
if seqVal <= maxCodeID {
|
||||
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastCodeID), seqVal, maxCodeID)
|
||||
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeySequenceCodeID), seqVal, maxCodeID)
|
||||
}
|
||||
seqVal = keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID)
|
||||
seqVal = keeper.PeekAutoIncrementID(ctx, types.KeySequenceInstanceID)
|
||||
if seqVal <= uint64(maxContractID) {
|
||||
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeyLastInstanceID), seqVal, maxContractID)
|
||||
return nil, errorsmod.Wrapf(types.ErrInvalid, "seq %s with value: %d must be greater than: %d ", string(types.KeySequenceInstanceID), seqVal, maxContractID)
|
||||
}
|
||||
return nil, nil
|
||||
}
|
||||
@@ -111,7 +111,7 @@ func ExportGenesis(ctx sdk.Context, keeper *Keeper) *types.GenesisState {
|
||||
return false
|
||||
})
|
||||
|
||||
for _, k := range [][]byte{types.KeyLastCodeID, types.KeyLastInstanceID} {
|
||||
for _, k := range [][]byte{types.KeySequenceCodeID, types.KeySequenceInstanceID} {
|
||||
genState.Sequences = append(genState.Sequences, types.Sequence{
|
||||
IDKey: k,
|
||||
Value: keeper.PeekAutoIncrementID(ctx, k),
|
||||
|
||||
@@ -171,8 +171,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
CodeBytes: wasmCode,
|
||||
}},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 2},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 1},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 2},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 1},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -190,8 +190,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
CodeBytes: wasmCode,
|
||||
}},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 10},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 1},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 10},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 1},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -210,8 +210,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
}},
|
||||
Contracts: nil,
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 3},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 1},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 3},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 1},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -281,8 +281,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 2},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 2},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 2},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 2},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -321,8 +321,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 2},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 3},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 2},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 3},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -433,7 +433,7 @@ func TestGenesisInit(t *testing.T) {
|
||||
CodeBytes: wasmCode,
|
||||
}},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 1},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 1},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -460,8 +460,8 @@ func TestGenesisInit(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: 2},
|
||||
{IDKey: types.KeyLastInstanceID, Value: 1},
|
||||
{IDKey: types.KeySequenceCodeID, Value: 2},
|
||||
{IDKey: types.KeySequenceInstanceID, Value: 1},
|
||||
},
|
||||
Params: types.DefaultParams(),
|
||||
},
|
||||
@@ -626,8 +626,8 @@ func TestImportContractWithCodeHistoryPreserved(t *testing.T) {
|
||||
},
|
||||
}
|
||||
assert.Equal(t, expHistory, keeper.GetContractHistory(ctx, contractAddr))
|
||||
assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeyLastCodeID))
|
||||
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeyLastInstanceID))
|
||||
assert.Equal(t, uint64(2), keeper.PeekAutoIncrementID(ctx, types.KeySequenceCodeID))
|
||||
assert.Equal(t, uint64(3), keeper.PeekAutoIncrementID(ctx, types.KeySequenceInstanceID))
|
||||
}
|
||||
|
||||
func setupKeeper(t *testing.T) (*Keeper, sdk.Context) {
|
||||
|
||||
@@ -181,7 +181,7 @@ func (k Keeper) create(ctx sdk.Context, creator sdk.AccAddress, wasmCode []byte,
|
||||
if err != nil {
|
||||
return 0, checksum, errorsmod.Wrap(types.ErrCreateFailed, err.Error())
|
||||
}
|
||||
codeID = k.autoIncrementID(ctx, types.KeyLastCodeID)
|
||||
codeID = k.autoIncrementID(ctx, types.KeySequenceCodeID)
|
||||
k.Logger(ctx).Debug("storing new contract", "capabilities", report.RequiredCapabilities, "code_id", codeID)
|
||||
codeInfo := types.NewCodeInfo(checksum, creator, *instantiateAccess)
|
||||
k.storeCodeInfo(ctx, codeID, codeInfo)
|
||||
@@ -1030,22 +1030,22 @@ func (k Keeper) consumeRuntimeGas(ctx sdk.Context, gas uint64) {
|
||||
}
|
||||
}
|
||||
|
||||
func (k Keeper) autoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
|
||||
func (k Keeper) autoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(lastIDKey)
|
||||
bz := store.Get(sequenceKey)
|
||||
id := uint64(1)
|
||||
if bz != nil {
|
||||
id = binary.BigEndian.Uint64(bz)
|
||||
}
|
||||
bz = sdk.Uint64ToBigEndian(id + 1)
|
||||
store.Set(lastIDKey, bz)
|
||||
store.Set(sequenceKey, bz)
|
||||
return id
|
||||
}
|
||||
|
||||
// PeekAutoIncrementID reads the current value without incrementing it.
|
||||
func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
|
||||
func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, sequenceKey []byte) uint64 {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
bz := store.Get(lastIDKey)
|
||||
bz := store.Get(sequenceKey)
|
||||
id := uint64(1)
|
||||
if bz != nil {
|
||||
id = binary.BigEndian.Uint64(bz)
|
||||
@@ -1053,13 +1053,13 @@ func (k Keeper) PeekAutoIncrementID(ctx sdk.Context, lastIDKey []byte) uint64 {
|
||||
return id
|
||||
}
|
||||
|
||||
func (k Keeper) importAutoIncrementID(ctx sdk.Context, lastIDKey []byte, val uint64) error {
|
||||
func (k Keeper) importAutoIncrementID(ctx sdk.Context, sequenceKey []byte, val uint64) error {
|
||||
store := ctx.KVStore(k.storeKey)
|
||||
if store.Has(lastIDKey) {
|
||||
return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(lastIDKey))
|
||||
if store.Has(sequenceKey) {
|
||||
return errorsmod.Wrapf(types.ErrDuplicate, "autoincrement id: %s", string(sequenceKey))
|
||||
}
|
||||
bz := sdk.Uint64ToBigEndian(val)
|
||||
store.Set(lastIDKey, bz)
|
||||
store.Set(sequenceKey, bz)
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ func RandomizedGenState(simstate *module.SimulationState) {
|
||||
Codes: nil,
|
||||
Contracts: nil,
|
||||
Sequences: []types.Sequence{
|
||||
{IDKey: types.KeyLastCodeID, Value: simstate.Rand.Uint64()},
|
||||
{IDKey: types.KeySequenceCodeID, Value: simstate.Rand.Uint64()},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,8 @@ var (
|
||||
ContractsByCreatorPrefix = []byte{0x09}
|
||||
ParamsKey = []byte{0x10}
|
||||
|
||||
KeyLastCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...)
|
||||
KeyLastInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...)
|
||||
KeySequenceCodeID = append(SequenceKeyPrefix, []byte("lastCodeId")...)
|
||||
KeySequenceInstanceID = append(SequenceKeyPrefix, []byte("lastContractId")...)
|
||||
)
|
||||
|
||||
// GetCodeKey constructs the key for retreiving the ID for the WASM code
|
||||
|
||||
Reference in New Issue
Block a user