Skip to content

Commit

Permalink
fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
mossid committed Oct 7, 2018
1 parent 02082ee commit db4905a
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 51 deletions.
2 changes: 2 additions & 0 deletions store/cachemulti/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import (

// Store holds many cache-wrapped stores.
// Implements MultiStore.
// TODO: support recursive multistores,
// currently only using CacheKVStores
type Store struct {
db types.CacheKVStore
stores map[types.StoreKey]types.CacheKVStore
Expand Down
24 changes: 12 additions & 12 deletions store/gas/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,27 @@ import (
"github.com/cosmos/cosmos-sdk/store/types"
)

var _ types.KVStore = &gasKVStore{}
var _ types.KVStore = &Store{}

// gasKVStore applies gas tracking to an underlying KVStore. It implements the
// Store applies gas tracking to an underlying KVStore. It implements the
// KVStore interface.
type gasKVStore struct {
type Store struct {
tank *types.GasTank
parent types.KVStore
}

// NewGasKVStore returns a reference to a new GasKVStore.
// nolint
func NewStore(tank *types.GasTank, parent types.KVStore) *gasKVStore {
kvs := &gasKVStore{
func NewStore(tank *types.GasTank, parent types.KVStore) *Store {
kvs := &Store{
tank: tank,
parent: parent,
}
return kvs
}

// Implements types.KVStore.
func (gs *gasKVStore) Get(key []byte) (value []byte) {
func (gs *Store) Get(key []byte) (value []byte) {
gs.tank.ReadFlat()
value = gs.parent.Get(key)
// TODO overflow-safe math?
Expand All @@ -34,36 +34,36 @@ func (gs *gasKVStore) Get(key []byte) (value []byte) {
}

// Implements types.KVStore.
func (gs *gasKVStore) Set(key []byte, value []byte) {
func (gs *Store) Set(key []byte, value []byte) {
gs.tank.WriteFlat()
// TODO overflow-safe math?
gs.tank.WriteBytes(len(value))
gs.parent.Set(key, value)
}

// Implements types.KVStore.
func (gs *gasKVStore) Has(key []byte) bool {
func (gs *Store) Has(key []byte) bool {
gs.tank.HasFlat()
return gs.parent.Has(key)
}

// Implements types.KVStore.
func (gs *gasKVStore) Delete(key []byte) {
func (gs *Store) Delete(key []byte) {
gs.tank.DeleteFlat()
gs.parent.Delete(key)
}

// Implements types.KVStore.
func (gs *gasKVStore) Iterator(start, end []byte) types.Iterator {
func (gs *Store) Iterator(start, end []byte) types.Iterator {
return gs.iterator(start, end, true)
}

// Implements types.KVStore.
func (gs *gasKVStore) ReverseIterator(start, end []byte) types.Iterator {
func (gs *Store) ReverseIterator(start, end []byte) types.Iterator {
return gs.iterator(start, end, false)
}

func (gs *gasKVStore) iterator(start, end []byte, ascending bool) types.Iterator {
func (gs *Store) iterator(start, end []byte, ascending bool) types.Iterator {
var parent types.Iterator
if ascending {
parent = gs.parent.Iterator(start, end)
Expand Down
20 changes: 10 additions & 10 deletions store/iavl/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,33 @@ import (
"github.com/cosmos/cosmos-sdk/store/types"
)

var _ types.StoreKey = (*KVStoreKey)(nil)
var _ types.StoreKey = (*StoreKey)(nil)

// KVStoreKey is used for accessing substores.
// StoreKey is used for accessing substores.
// Only the pointer value should ever be used - it functions as a capabilities key.
type KVStoreKey struct {
type StoreKey struct {
name string
}

// NewKVStoreKey returns a new pointer to a KVStoreKey.
// NewStoreKey returns a new pointer to a StoreKey.
// Use a pointer so keys don't collide.
func NewKey(name string) *KVStoreKey {
return &KVStoreKey{
func NewKey(name string) *StoreKey {
return &StoreKey{
name: name,
}
}

// Implements StoreKey
func (key *KVStoreKey) Name() string {
func (key *StoreKey) Name() string {
return key.name
}

// Implements StoreKey
func (key *KVStoreKey) String() string {
return fmt.Sprintf("KVStoreKey{%p, %s}", key, key.name)
func (key *StoreKey) String() string {
return fmt.Sprintf("StoreKey{%p, %s}", key, key.name)
}

// Implements StoreKey
func (key *KVStoreKey) NewStore() types.CommitStore {
func (key *StoreKey) NewStore() types.CommitStore {
return &Store{}
}
6 changes: 6 additions & 0 deletions store/iavl/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
cmn "github.com/tendermint/tendermint/libs/common"
dbm "github.com/tendermint/tendermint/libs/db"

"github.com/cosmos/cosmos-sdk/store/cache"
"github.com/cosmos/cosmos-sdk/store/types"
)

Expand Down Expand Up @@ -120,6 +121,11 @@ func (st *Store) VersionExists(version int64) bool {
return st.tree.VersionExists(version)
}

// Implements types.KVStore
func (st *Store) CacheWrap() types.CacheKVStore {
return cache.NewStore(st)
}

// Implements types.KVStore.
func (st *Store) Set(key, value []byte) {
st.tree.Set(key, value)
Expand Down
20 changes: 10 additions & 10 deletions store/transient/key.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,32 +6,32 @@ import (
"github.com/cosmos/cosmos-sdk/store/types"
)

var _ types.StoreKey = (*TransientStoreKey)(nil)
var _ types.StoreKey = (*StoreKey)(nil)

// TransientStoreKey is used for indexing transient stores in a MultiStore
type TransientStoreKey struct {
// StoreKey is used for indexing transient stores in a MultiStore
type StoreKey struct {
name string
}

// Constructs new TransientStoreKey
// Constructs new StoreKey
// Must return a pointer according to the ocap principle
func NewKey(name string) *TransientStoreKey {
return &TransientStoreKey{
func NewKey(name string) *StoreKey {
return &StoreKey{
name: name,
}
}

// Implements StoreKey
func (key *TransientStoreKey) Name() string {
func (key *StoreKey) Name() string {
return key.name
}

// Implements StoreKey
func (key *TransientStoreKey) String() string {
return fmt.Sprintf("TransientStoreKey{%p, %s}", key, key.name)
func (key *StoreKey) String() string {
return fmt.Sprintf("StoreKey{%p, %s}", key, key.name)
}

// Implements StoreKey
func (key *TransientStoreKey) NewStore() types.CommitStore {
func (key *StoreKey) NewStore() types.CommitStore {
return &Store{}
}
20 changes: 8 additions & 12 deletions store/types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const (
PruneNothing PruningStrategy = iota
)

// Stores of MultiStore must implement CommitStore.
// Stores of MultiStore must implement commitStore.
type CommitStore interface {
// CONTRACT: return zero CommitID to skip writing
Commit() CommitID
Expand All @@ -50,13 +50,9 @@ type MultiStore interface { //nolint
// TODO: recursive multistore not yet supported
// GetMultiStore(StoreKey) MultiStore

// CacheWrap cache wraps
// Having this method here because there is currently no
// implementation of MultiStore that panics on CacheWrap().
// Move this method to CacheWrapperMultiStore when needed
CacheWrap() CacheMultiStore

GetTracer() *Tracer

CacheWrap() CacheMultiStore
}

// From MultiStore.CacheMultiStore()....
Expand Down Expand Up @@ -147,9 +143,7 @@ func KVStoreReversePrefixIterator(kvs KVStore, prefix []byte) Iterator {
return kvs.ReverseIterator(prefix, PrefixEndBytes(prefix))
}

type CacheWrapperKVStore interface {
KVStore

type cacheWrappableKVStore interface {
// CacheWrap cache wraps
CacheWrap() CacheKVStore
}
Expand All @@ -158,16 +152,18 @@ type CacheWrapperKVStore interface {
// the CacheKVStore, all previously created CacheKVStores on the
// object expire.
type CacheKVStore interface {
CacheWrapperKVStore
KVStore
cacheWrappableKVStore

// Writes operations to underlying KVStore
Write()
}

// Stores of MultiStore must implement CommitStore.
type CommitKVStore interface {
CommitStore
KVStore
CommitStore
cacheWrappableKVStore

// Load a specific persisted version. When you load an old
// version, or when the last commit attempt didn't complete,
Expand Down
1 change: 1 addition & 0 deletions store/types/trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
// every trace operation.
type TraceContext map[string]interface{}

// Tracer is pair of io.Writer and TraceContext
type Tracer struct {
Writer io.Writer
Context TraceContext
Expand Down
1 change: 1 addition & 0 deletions store/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ import (

func bz(s string) []byte { return []byte(s) }

// Used for tests - formats integer to bytes
func KeyFmt(i int) []byte { return bz(fmt.Sprintf("key%0.8d", i)) }
func ValFmt(i int) []byte { return bz(fmt.Sprintf("value%0.8d", i)) }
10 changes: 5 additions & 5 deletions types/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/cosmos/cosmos-sdk/store/types"
)

// nolint: reexport
// nolint - reexport
type (
PruningStrategy = types.PruningStrategy
CommitStore = types.CommitStore
Expand All @@ -23,8 +23,8 @@ type (
KVPair = types.KVPair

StoreKey = types.StoreKey
KVStoreKey = iavl.KVStoreKey
TransientStoreKey = transient.TransientStoreKey
KVStoreKey = iavl.StoreKey
TransientStoreKey = transient.StoreKey

Gas = types.Gas
GasTank = types.GasTank
Expand All @@ -37,14 +37,14 @@ type (
ErrorOutOfGas = types.ErrorOutOfGas
)

// nolint: reexport
// nolint - reexport
const (
PruneNothing = types.PruneNothing
PruneEverything = types.PruneEverything
PruneSyncable = types.PruneSyncable
)

// nolint: reexport
// nolint - reexport
func KVStorePrefixIterator(store KVStore, prefix []byte) Iterator {
return types.KVStorePrefixIterator(store, prefix)
}
Expand Down
4 changes: 3 additions & 1 deletion x/slashing/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ func createTestInput(t *testing.T) (sdk.Context, bank.Keeper, stake.Keeper, para
ms.MountStoreWithDB(keyParams, db)
err := ms.LoadLatestVersion()
require.Nil(t, err)
ctx := sdk.NewContext(ms, abci.Header{Time: time.Unix(0, 0)}, false, log.NewTMLogger(os.Stdout))

cms := ms.CacheWrap()
ctx := sdk.NewContext(cms, abci.Header{Time: time.Unix(0, 0)}, false, log.NewTMLogger(os.Stdout))
cdc := createTestCodec()
accountMapper := auth.NewAccountMapper(cdc, keyAcc, auth.ProtoBaseAccount)
ck := bank.NewBaseKeeper(accountMapper)
Expand Down
3 changes: 2 additions & 1 deletion x/stake/keeper/test_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ func CreateTestInput(t *testing.T, isCheckTx bool, initCoins int64) (sdk.Context
err := ms.LoadLatestVersion()
require.Nil(t, err)

ctx := sdk.NewContext(ms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger())
cms := ms.CacheWrap()
ctx := sdk.NewContext(cms, abci.Header{ChainID: "foochainid"}, isCheckTx, log.NewNopLogger())
cdc := MakeTestCodec()
accountMapper := auth.NewAccountMapper(
cdc, // amino codec
Expand Down

0 comments on commit db4905a

Please sign in to comment.