Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
chixiaoxiao committed Mar 27, 2024
1 parent 6e9752e commit b42f646
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 49 deletions.
3 changes: 2 additions & 1 deletion collections/codec/time_test.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package codec

import (
"github.com/stretchr/testify/require"
"testing"
"time"

"github.com/stretchr/testify/require"
)

func TestTimeKey(t *testing.T) {
Expand Down
44 changes: 0 additions & 44 deletions types/collections.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package types
import (
"encoding/binary"
"fmt"
"time"

"cosmossdk.io/collections"
collcodec "cosmossdk.io/collections/codec"
Expand Down Expand Up @@ -239,49 +238,6 @@ func (i uintValueCodec) ValueType() string {
return Uint
}

type timeKeyCodec struct{}

func (timeKeyCodec) Encode(buffer []byte, key time.Time) (int, error) {
return copy(buffer, FormatTimeBytes(key)), nil
}

var timeSize = len(FormatTimeBytes(time.Time{}))

func (timeKeyCodec) Decode(buffer []byte) (int, time.Time, error) {
if len(buffer) != timeSize {
return 0, time.Time{}, fmt.Errorf("invalid time buffer buffer size")
}
t, err := ParseTimeBytes(buffer)
if err != nil {
return 0, time.Time{}, err
}
return timeSize, t, nil
}

func (timeKeyCodec) Size(key time.Time) int { return timeSize }

func (timeKeyCodec) EncodeJSON(value time.Time) ([]byte, error) { return value.MarshalJSON() }

func (timeKeyCodec) DecodeJSON(b []byte) (time.Time, error) {
t := time.Time{}
err := t.UnmarshalJSON(b)
return t, err
}

func (timeKeyCodec) Stringify(key time.Time) string { return key.String() }
func (timeKeyCodec) KeyType() string { return "sdk/time.Time" }
func (t timeKeyCodec) EncodeNonTerminal(buffer []byte, key time.Time) (int, error) {
return t.Encode(buffer, key)
}

func (t timeKeyCodec) DecodeNonTerminal(buffer []byte) (int, time.Time, error) {
if len(buffer) < timeSize {
return 0, time.Time{}, fmt.Errorf("invalid time buffer size, wanted: %d at least, got: %d", timeSize, len(buffer))
}
return t.Decode(buffer[:timeSize])
}
func (t timeKeyCodec) SizeNonTerminal(key time.Time) int { return t.Size(key) }

type leUint64Key struct{}

func (l leUint64Key) Encode(buffer []byte, key uint64) (int, error) {
Expand Down
5 changes: 3 additions & 2 deletions x/accounts/defaults/lockup/lockup.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"fmt"
"time"

"github.com/cosmos/gogoproto/proto"

"cosmossdk.io/collections"
collcodec "cosmossdk.io/collections/codec"
"cosmossdk.io/core/address"
Expand All @@ -15,9 +17,8 @@ import (
"cosmossdk.io/x/accounts/accountstd"
lockuptypes "cosmossdk.io/x/accounts/lockup/types"
banktypes "cosmossdk.io/x/bank/types"
codectypes "github.com/cosmos/cosmos-sdk/codec/types"
"github.com/cosmos/gogoproto/proto"

codectypes "github.com/cosmos/cosmos-sdk/codec/types"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
)
Expand Down
6 changes: 4 additions & 2 deletions x/accounts/defaults/lockup/protov2_wrapper.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package lockup

import (
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/runtime/protoiface"

bankv1beta1 "cosmossdk.io/api/cosmos/bank/v1beta1"
v1beta1 "cosmossdk.io/api/cosmos/base/v1beta1"
stakingv1beta1 "cosmossdk.io/api/cosmos/staking/v1beta1"

sdk "github.com/cosmos/cosmos-sdk/types"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/runtime/protoiface"
)

type ProtoMsg = protoiface.MessageV1
Expand Down

0 comments on commit b42f646

Please sign in to comment.