Skip to content

Commit

Permalink
refactor: reorginze imports and sdkmath
Browse files Browse the repository at this point in the history
  • Loading branch information
scorpioborn committed Sep 25, 2023
1 parent a8ac3d0 commit dd252bb
Show file tree
Hide file tree
Showing 49 changed files with 327 additions and 330 deletions.
26 changes: 13 additions & 13 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,32 +448,32 @@ func NewAppKeeper(
)
appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper)

appKeepers.SubaccountKeeper = subaccountmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[subaccountmoduletypes.StoreKey],
appKeepers.GetSubspace(subaccountmoduletypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.OVMKeeper,
appKeepers.BetKeeper,
appKeepers.OrderbookKeeper,
appKeepers.HouseKeeper,
)

appKeepers.RewardKeeper = rewardmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[rewardmoduletypes.StoreKey],
appKeepers.keys[rewardmoduletypes.MemStoreKey],
appKeepers.GetSubspace(rewardmoduletypes.ModuleName),
appKeepers.OVMKeeper,
appKeepers.SubaccountKeeper,
rewardmodulekeeper.SdkExpectedKeepers{
AuthzKeeper: appKeepers.AuthzKeeper,
BankKeeper: appKeepers.BankKeeper,
AccountKeeper: appKeepers.AccountKeeper,
},
)

//// SGE modules \\\\
appKeepers.SubaccountKeeper = subaccountmodulekeeper.NewKeeper(
appCodec,
appKeepers.keys[subaccountmoduletypes.StoreKey],
appKeepers.GetSubspace(subaccountmoduletypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.OVMKeeper,
appKeepers.BetKeeper,
appKeepers.OrderbookKeeper,
appKeepers.HouseKeeper,
)

// ** Hooks ** \\

appKeepers.OrderbookKeeper.SetHooks(
Expand Down
4 changes: 2 additions & 2 deletions proto/sge/reward/campaign.proto
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ message Campaign {
// Pool is the type for the campaign funding pool.
message Pool {
string total = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"total\""
];
string spent = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"spent\""
];
Expand Down
4 changes: 2 additions & 2 deletions proto/sge/reward/reward.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ message RewardCommon {
message Definition {
ReceiverType receiver_type = 1;
string amount = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\""
];
Expand All @@ -40,7 +40,7 @@ message Distribution {
// Allocation is the distribution allocation of the rewards.
message Allocation {
string amount = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"amount\""
];
Expand Down
2 changes: 1 addition & 1 deletion proto/sge/reward/ticket.proto
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ message CreateCampaignPayload {
RewardType type = 4;
repeated Definition reward_defs = 6 [ (gogoproto.nullable) = false ];
string pool_amount = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Int",
(gogoproto.customtype) = "cosmossdk.io/math.Int",
(gogoproto.nullable) = false,
(gogoproto.moretags) = "yaml:\"pool_amount\""
];
Expand Down
11 changes: 6 additions & 5 deletions utils/authorization.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ package utils
import (
"time"

cosmerrors "cosmossdk.io/errors"
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
sdkerrtypes "github.com/cosmos/cosmos-sdk/types/errors"

"github.com/cosmos/cosmos-sdk/x/authz"
)

Expand Down Expand Up @@ -40,7 +41,7 @@ func ValidateMsgAuthorization(
granteeAddr := sdk.MustAccAddressFromBech32(creator)
granterAddr, err := sdk.AccAddressFromBech32(depositor)
if err != nil {
return cosmerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid granter address (%s)", err)
return sdkerrors.Wrapf(sdkerrtypes.ErrInvalidAddress, "invalid granter address (%s)", err)
}
authorization, expiration := authzKeeper.GetAuthorization(
ctx,
Expand All @@ -49,7 +50,7 @@ func ValidateMsgAuthorization(
sdk.MsgTypeURL(msg),
)
if authorization == nil {
return cosmerrors.Wrapf(
return sdkerrors.Wrapf(
errAuthorizationNotFound,
"grantee: %s, granter: %s",
creator,
Expand All @@ -58,7 +59,7 @@ func ValidateMsgAuthorization(
}
authRes, err := authorization.Accept(ctx, msg)
if err != nil {
return cosmerrors.Wrapf(errAuthorizationNotAccepted, "%s", err)
return sdkerrors.Wrapf(errAuthorizationNotAccepted, "%s", err)
}

if authRes.Delete {
Expand Down
6 changes: 3 additions & 3 deletions utils/fund.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package utils

import (
cosmerrors "cosmossdk.io/errors"
sdkerrors "cosmossdk.io/errors"
sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

Expand Down Expand Up @@ -47,7 +47,7 @@ func (f *ModuleAccFunder) Fund(
// Transfer funds
err := f.bk.SendCoinsFromAccountToModule(ctx, senderAcc, mf.GetModuleAcc(), amt)
if err != nil {
return cosmerrors.Wrapf(f.bankError, ": %s", err)
return sdkerrors.Wrapf(f.bankError, ": %s", err)
}

return nil
Expand All @@ -67,7 +67,7 @@ func (f *ModuleAccFunder) Refund(
// Transfer funds
err := f.bk.SendCoinsFromModuleToAccount(ctx, mAcc, receiverAcc, amt)
if err != nil {
return cosmerrors.Wrapf(f.bankError, err.Error())
return sdkerrors.Wrapf(f.bankError, err.Error())
}

return nil
Expand Down
4 changes: 0 additions & 4 deletions x/reward/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,10 @@ package cli

import (
"fmt"
// "strings"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"
// sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -27,7 +24,6 @@ func GetQueryCmd(queryRoute string) *cobra.Command {
cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdListCampaign())
cmd.AddCommand(CmdShowCampaign())
// this line is used by starport scaffolding # 1

return cmd
}
4 changes: 3 additions & 1 deletion x/reward/client/cli/query_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package cli
import (
"context"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/sge-network/sge/x/reward/types"
"github.com/spf13/cobra"
)

func CmdListCampaign() *cobra.Command {
Expand Down
10 changes: 6 additions & 4 deletions x/reward/client/cli/query_campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ import (
"testing"
"time"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"
"github.com/google/uuid"
"github.com/stretchr/testify/require"
tmcli "github.com/tendermint/tendermint/libs/cli"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

tmcli "github.com/tendermint/tendermint/libs/cli"

sdkmath "cosmossdk.io/math"
"github.com/cosmos/cosmos-sdk/client/flags"
clitestutil "github.com/cosmos/cosmos-sdk/testutil/cli"

"github.com/sge-network/sge/testutil/network"
"github.com/sge-network/sge/testutil/nullify"
"github.com/sge-network/sge/testutil/sample"
Expand Down
4 changes: 3 additions & 1 deletion x/reward/client/cli/query_params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package cli
import (
"context"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/sge-network/sge/x/reward/types"
"github.com/spf13/cobra"
)

func CmdQueryParams() *cobra.Command {
Expand Down
3 changes: 1 addition & 2 deletions x/reward/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
// "github.com/cosmos/cosmos-sdk/client/flags"

"github.com/sge-network/sge/x/reward/types"
)

Expand All @@ -26,7 +26,6 @@ func GetTxCmd() *cobra.Command {
cmd.AddCommand(CmdCreateCampaign())
cmd.AddCommand(CmdUpdateCampaign())
cmd.AddCommand(CmdDeleteCampaign())
// this line is used by starport scaffolding # 1

return cmd
}
4 changes: 3 additions & 1 deletion x/reward/client/cli/tx_campaign.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package cli

import (
"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"

"github.com/sge-network/sge/x/reward/types"
"github.com/spf13/cobra"
)

func CmdCreateCampaign() *cobra.Command {
Expand Down
3 changes: 1 addition & 2 deletions x/reward/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package reward

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/x/reward/keeper"
"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -12,7 +13,6 @@ func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState)
for _, elem := range genState.CampaignList {
k.SetCampaign(ctx, elem)
}
// this line is used by starport scaffolding # genesis/module/init
k.SetParams(ctx, genState.Params)
}

Expand All @@ -22,7 +22,6 @@ func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState {
genesis.Params = k.GetParams(ctx)

genesis.CampaignList = k.GetAllCampaign(ctx)
// this line is used by starport scaffolding # genesis/module/export

return genesis
}
8 changes: 3 additions & 5 deletions x/reward/genesis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import (
"testing"

"github.com/google/uuid"
"github.com/sge-network/sge/testutil/nullify"
"github.com/stretchr/testify/require"

simappUtil "github.com/sge-network/sge/testutil/simapp"
"github.com/sge-network/sge/testutil/nullify"
"github.com/sge-network/sge/testutil/simapp"
"github.com/sge-network/sge/x/reward"
"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -24,10 +24,9 @@ func TestGenesis(t *testing.T) {
UID: uuid.NewString(),
},
},
// this line is used by starport scaffolding # genesis/test/state
}

tApp, ctx, err := simappUtil.GetTestObjects()
tApp, ctx, err := simapp.GetTestObjects()
require.NoError(t, err)
reward.InitGenesis(ctx, *tApp.RewardKeeper, genesisState)
got := reward.ExportGenesis(ctx, *tApp.RewardKeeper)
Expand All @@ -37,5 +36,4 @@ func TestGenesis(t *testing.T) {
nullify.Fill(got)

require.ElementsMatch(t, genesisState.CampaignList, got.CampaignList)
// this line is used by starport scaffolding # genesis/test/assert
}
1 change: 1 addition & 0 deletions x/reward/keeper/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/x/reward/types"
)

Expand Down
12 changes: 7 additions & 5 deletions x/reward/keeper/campaign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import (
"testing"
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/google/uuid"
"github.com/sge-network/sge/testutil/nullify"
"github.com/sge-network/sge/testutil/sample"
"github.com/stretchr/testify/require"

sdkmath "cosmossdk.io/math"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/testutil/nullify"
"github.com/sge-network/sge/testutil/sample"
"github.com/sge-network/sge/x/reward/keeper"
"github.com/sge-network/sge/x/reward/types"
)
Expand All @@ -29,10 +31,10 @@ func createNCampaign(keeper *keeper.Keeper, ctx sdk.Context, n int) []types.Camp
items[i].RewardType = types.RewardType_REWARD_TYPE_REFERRAL
items[i].RewardDefs = []types.Definition{{
ReceiverType: types.ReceiverType_RECEIVER_TYPE_SINGLE,
Amount: sdk.NewInt(100),
Amount: sdkmath.NewInt(100),
DstAccType: types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB,
}}
items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Total: sdk.NewInt(100)}
items[i].Pool = types.Pool{Spent: sdk.ZeroInt(), Total: sdkmath.NewInt(100)}

keeper.SetCampaign(ctx, items[i])
}
Expand Down
9 changes: 7 additions & 2 deletions x/reward/keeper/distribution.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package keeper

import (
sdkerrors "cosmossdk.io/errors"
sdk "github.com/cosmos/cosmos-sdk/types"

"github.com/sge-network/sge/x/reward/types"
)

Expand All @@ -19,8 +21,11 @@ func (k Keeper) DistributeRewards(ctx sdk.Context, distributions []types.Distrib
d.Allocation.Amount,
)
case types.ReceiverAccType_RECEIVER_ACC_TYPE_SUB:
// use subaccount module to create or topup
panic("subaccount distribution is not implemented")
_, found := k.subaccountKeeper.GetSubAccountByOwner(ctx, sdk.MustAccAddressFromBech32(d.AccAddr))
if !found {
return sdkerrors.Wrapf(types.ErrSubAccountNotfoundForTheOwner, "owner address %s", d.AccAddr)
}

default:
return types.ErrUnknownAccType
}
Expand Down
Loading

0 comments on commit dd252bb

Please sign in to comment.