diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 8c018d1..3a1f2ca 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -18,6 +18,18 @@ on: - main - development +env: + GO_VERSION: "1.21.3" + +permissions: + contents: read + +# Optional: allow read access to pull request. Use with `only-new-issues` option. +# pull-requests: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + # This workflow makes x86_64 binaries for mac, windows, and linux. jobs: @@ -29,11 +41,11 @@ jobs: targetos: [ darwin, linux ] name: streampayd ${{ matrix.arch }} for ${{ matrix.targetos }} steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Setup go - uses: actions/setup-go@v1 + uses: actions/setup-go@v4 with: - go-version: 1.20 + go-version: ${{env.GO_VERSION}} env: GOOS: ${{ matrix.targetos }} GOARCH: ${{ matrix.arch }} @@ -44,7 +56,7 @@ jobs: cd cmd/streampayd go build . - - uses: actions/upload-artifact@v2 + - uses: actions/upload-artifact@v3 with: name: streampayd ${{ matrix.targetos }} ${{ matrix.arch }} path: cmd/streampayd/streampayd diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index fa46ec8..a97fbf7 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -4,24 +4,34 @@ on: tags: - v* branches: + - master - main pull_request: + paths: + - '**.go' + +env: + GO_VERSION: '1.21.3' + permissions: contents: read # Optional: allow read access to pull request. Use with `only-new-issues` option. # pull-requests: read +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + jobs: golangci: name: lint runs-on: ubuntu-latest steps: - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: 1.20 - - uses: actions/checkout@v3.1.0 + go-version: ${{env.GO_VERSION}} + - uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@v3 with: - # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version version: latest - args: --timeout 5m0s \ No newline at end of file + args: --timeout 10m \ No newline at end of file diff --git a/app/ante_handler.go b/app/ante_handler.go index 9639260..c4bf210 100644 --- a/app/ante_handler.go +++ b/app/ante_handler.go @@ -1,6 +1,7 @@ package app import ( + errorsmod "cosmossdk.io/errors" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" @@ -26,13 +27,13 @@ type HandlerOptions struct { func NewAnteHandler(options HandlerOptions) (sdk.AnteHandler, error) { if options.AccountKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "account keeper is required for AnteHandler") } if options.BankKeeper == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "bank keeper is required for AnteHandler") } if options.SignModeHandler == nil { - return nil, sdkerrors.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") + return nil, errorsmod.Wrap(sdkerrors.ErrLogic, "sign mode handler is required for ante builder") } sigGasConsumer := options.SigGasConsumer diff --git a/app/apptesting/test_suite.go b/app/apptesting/test_suite.go index d8e1d59..b579471 100644 --- a/app/apptesting/test_suite.go +++ b/app/apptesting/test_suite.go @@ -4,6 +4,8 @@ import ( "fmt" "time" + sdkmath "cosmossdk.io/math" + "github.com/OmniFlix/streampay/v2/app" dbm "github.com/cometbft/cometbft-db" @@ -212,7 +214,7 @@ func (s *KeeperTestHelper) RunMsg(msg sdk.Msg) (*sdk.Result, error) { } // AllocateRewardsToValidator allocates reward tokens to a distribution module then allocates rewards to the validator address. -func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdk.Int) { +func (s *KeeperTestHelper) AllocateRewardsToValidator(valAddr sdk.ValAddress, rewardAmt sdkmath.Int) { validator, found := s.App.StakingKeeper.GetValidator(s.Ctx, valAddr) s.Require().True(found) diff --git a/x/streampay/keeper/keeper.go b/x/streampay/keeper/keeper.go index c1f09f4..9426b44 100644 --- a/x/streampay/keeper/keeper.go +++ b/x/streampay/keeper/keeper.go @@ -4,16 +4,14 @@ import ( "fmt" "time" - storetypes "github.com/cosmos/cosmos-sdk/store/types" - - authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" - - "github.com/cometbft/cometbft/libs/log" - + errorsmod "cosmossdk.io/errors" "github.com/OmniFlix/streampay/v2/x/streampay/types" + "github.com/cometbft/cometbft/libs/log" "github.com/cosmos/cosmos-sdk/codec" + storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" ) type ( @@ -72,13 +70,13 @@ func (k Keeper) CreateStreamPayment(ctx sdk.Context, cancellable bool, ) (string, error) { if duration <= 0 { - return "", sdkerrors.Wrapf( + return "", errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("duration %s is not valid, should be a possitive value", duration.String()), ) } if amount.IsNil() || amount.IsNegative() || amount.IsZero() { - return "", sdkerrors.Wrapf( + return "", errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("amount %s is not valid format", amount.String()), ) @@ -123,25 +121,25 @@ func (k Keeper) CreateStreamPayment(ctx sdk.Context, func (k Keeper) StopStreamPayment(ctx sdk.Context, streamId string, sender sdk.AccAddress) error { streamPayment, ok := k.GetStreamPayment(ctx, streamId) if !ok { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrNotFound, fmt.Sprintf("no stream payment found with id %s", streamId), ) } if sender.String() != streamPayment.Sender { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, fmt.Sprintf("address %s is not allowed to stop the stream payment", streamId), ) } if !streamPayment.Cancellable { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, fmt.Sprintf("stream payment %s is not cancellable", streamId), ) } if ctx.BlockTime().Unix() > streamPayment.EndTime.Unix() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, fmt.Sprintf("ended stream payment cannot be canceled, stream payment %s", streamId), ) @@ -185,26 +183,26 @@ func (k Keeper) StopStreamPayment(ctx sdk.Context, streamId string, sender sdk.A func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sdk.AccAddress) error { streamPayment, ok := k.GetStreamPayment(ctx, streamId) if !ok { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrNotFound, fmt.Sprintf("no stream payment found with id %s", streamId), ) } claimerAddr := claimer.String() if claimerAddr != streamPayment.Recipient { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( sdkerrors.ErrUnauthorized, fmt.Sprintf("address %s is not allowed to claim the stream payment", claimerAddr), ) } if ctx.BlockTime().Unix() < streamPayment.StartTime.Unix() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("stream payment %s is not started yet", streamId), ) } if streamPayment.StreamedAmount.IsGTE(streamPayment.TotalAmount) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("stream payment %s is already fully claimed", streamId), ) @@ -224,7 +222,7 @@ func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sd } default: - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidStreamPaymentType, fmt.Sprintf("stream payment %s has invalid type", streamId), ) @@ -234,7 +232,7 @@ func (k Keeper) ClaimStreamedAmount(ctx sdk.Context, streamId string, claimer sd func (k Keeper) claimDelayedStreamPayment(ctx sdk.Context, streamPayment types.StreamPayment, claimer sdk.AccAddress) error { if ctx.BlockTime().Unix() < streamPayment.EndTime.Unix() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("stream payment %s is delayed type and not ended yet", streamPayment.Id), ) @@ -258,7 +256,7 @@ func (k Keeper) claimContinuousStreamPayment(ctx sdk.Context, streamPayment type amount := sdk.NewCoin(streamPayment.TotalAmount.Denom, sdk.NewInt(amountToSend)) if amount.IsZero() || amount.IsNil() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("no valid amount to claim for stream payment %s ", streamPayment.Id), ) @@ -287,7 +285,7 @@ func (k Keeper) claimPeriodicStreamPayment(ctx sdk.Context, streamPayment types. amount := sdk.NewCoin(streamPayment.TotalAmount.Denom, sdk.NewInt(amountToSend)) if amount.IsZero() || amount.IsNil() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( types.ErrInvalidAmount, fmt.Sprintf("no valid amount to claim for stream payment %s ", streamPayment.Id), ) diff --git a/x/streampay/types/errors.go b/x/streampay/types/errors.go index 09602ea..6870f12 100644 --- a/x/streampay/types/errors.go +++ b/x/streampay/types/errors.go @@ -3,17 +3,17 @@ package types // DONTCOVER import ( - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" + errorsmod "cosmossdk.io/errors" ) // x/streampay module errors var ( - ErrInvalidAmount = sdkerrors.Register(ModuleName, 2, "invalid amount") - ErrInvalidStreamPaymentType = sdkerrors.Register(ModuleName, 3, "invalid stream payment type") - ErrInvalidNextPaymentNumber = sdkerrors.Register(ModuleName, 4, "invalid next payment number") - ErrInvalidTimestamp = sdkerrors.Register(ModuleName, 5, "invalid timestamp") - ErrInvalidStreamPaymentFee = sdkerrors.Register(ModuleName, 6, "invalid stream payment fee") - ErrInvalidFee = sdkerrors.Register(ModuleName, 7, "invalid fee") - ErrInvalidPeriods = sdkerrors.Register(ModuleName, 8, "invalid periods") - ErrInvalidDuration = sdkerrors.Register(ModuleName, 9, "invalid duration") + ErrInvalidAmount = errorsmod.Register(ModuleName, 2, "invalid amount") + ErrInvalidStreamPaymentType = errorsmod.Register(ModuleName, 3, "invalid stream payment type") + ErrInvalidNextPaymentNumber = errorsmod.Register(ModuleName, 4, "invalid next payment number") + ErrInvalidTimestamp = errorsmod.Register(ModuleName, 5, "invalid timestamp") + ErrInvalidStreamPaymentFee = errorsmod.Register(ModuleName, 6, "invalid stream payment fee") + ErrInvalidFee = errorsmod.Register(ModuleName, 7, "invalid fee") + ErrInvalidPeriods = errorsmod.Register(ModuleName, 8, "invalid periods") + ErrInvalidDuration = errorsmod.Register(ModuleName, 9, "invalid duration") ) diff --git a/x/streampay/types/params.go b/x/streampay/types/params.go index 0d9241d..3f2371f 100644 --- a/x/streampay/types/params.go +++ b/x/streampay/types/params.go @@ -3,8 +3,8 @@ package types import ( "fmt" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) var DefaultStreamPaymentFee = sdk.NewInt64Coin("uspay", 10_000_000) // 10SPAY @@ -39,7 +39,7 @@ func validateStreamPaymentFee(i interface{}) error { } if !fee.IsValid() || fee.IsZero() { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidStreamPaymentFee, "invalid fee amount %s, only accepts positive amounts", fee.String(), diff --git a/x/streampay/types/validation.go b/x/streampay/types/validation.go index d9db616..983eb5e 100644 --- a/x/streampay/types/validation.go +++ b/x/streampay/types/validation.go @@ -4,8 +4,8 @@ import ( "fmt" "time" + errorsmod "cosmossdk.io/errors" sdk "github.com/cosmos/cosmos-sdk/types" - sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" ) func validateStreamPayment(streamPayment StreamPayment) error { @@ -30,7 +30,7 @@ func validateStreamPayment(streamPayment StreamPayment) error { func validateAmount(amount sdk.Coin) error { if !amount.IsValid() || amount.IsNil() || amount.Amount.LTE(sdk.ZeroInt()) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidAmount, fmt.Sprintf("amount %s is not valid", amount.String()), ) @@ -40,7 +40,7 @@ func validateAmount(amount sdk.Coin) error { func validateStreamType(_type StreamType) error { if !(_type == TypeDelayed || _type == TypeContinuous || _type == TypePeriodic) { - return sdkerrors.Wrapf( + return errorsmod.Wrapf( ErrInvalidStreamPaymentType, fmt.Sprintf("stream payment type %s is not valid", _type), ) @@ -51,7 +51,7 @@ func validateStreamType(_type StreamType) error { func ValidateNextStreamPaymentNumber(n interface{}) error { _, ok := n.(uint64) if !ok { - return sdkerrors.Wrapf(ErrInvalidNextPaymentNumber, "invalid value for next payment number: %v", n) + return errorsmod.Wrapf(ErrInvalidNextPaymentNumber, "invalid value for next payment number: %v", n) } return nil } @@ -59,7 +59,7 @@ func ValidateNextStreamPaymentNumber(n interface{}) error { func ValidateTimestamp(t interface{}) error { _, ok := t.(time.Time) if !ok { - return sdkerrors.Wrapf(ErrInvalidTimestamp, "invalid timestamp: %T", t) + return errorsmod.Wrapf(ErrInvalidTimestamp, "invalid timestamp: %T", t) } return nil } @@ -67,35 +67,35 @@ func ValidateTimestamp(t interface{}) error { func ValidateDuration(d interface{}) error { duration, ok := d.(time.Duration) if !ok { - return sdkerrors.Wrapf(ErrInvalidDuration, "invalid duration: %v", d) + return errorsmod.Wrapf(ErrInvalidDuration, "invalid duration: %v", d) } if duration < 1 { - return sdkerrors.Wrapf(ErrInvalidDuration, "invalid duration: %v", duration) + return errorsmod.Wrapf(ErrInvalidDuration, "invalid duration: %v", duration) } return nil } func validatePeriods(periods []*Period, totalAmount sdk.Coin, totalDuration time.Duration) error { if len(periods) == 0 { - return sdkerrors.Wrapf(ErrInvalidPeriods, "periods cannot be empty") + return errorsmod.Wrapf(ErrInvalidPeriods, "periods cannot be empty") } totalAmt := int64(0) totalDur := int64(0) for _, period := range periods { if period.Amount < 1 { - return sdkerrors.Wrapf(ErrInvalidPeriods, "invalid period amount: %d", period.Amount) + return errorsmod.Wrapf(ErrInvalidPeriods, "invalid period amount: %d", period.Amount) } if period.Duration < 1 { - return sdkerrors.Wrapf(ErrInvalidPeriods, "invalid period duration: %d", period.Duration) + return errorsmod.Wrapf(ErrInvalidPeriods, "invalid period duration: %d", period.Duration) } totalAmt += period.Amount totalDur += period.Duration } if totalAmt != totalAmount.Amount.Int64() { - return sdkerrors.Wrapf(ErrInvalidPeriods, "period amounts do not add up to total amount") + return errorsmod.Wrapf(ErrInvalidPeriods, "period amounts do not add up to total amount") } if totalDur != int64(totalDuration.Seconds()) { - return sdkerrors.Wrapf(ErrInvalidPeriods, "period durations do not add up to total duration") + return errorsmod.Wrapf(ErrInvalidPeriods, "period durations do not add up to total duration") } return nil }