Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature / Upgrade Handler v1.3.0 #325

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
v1 "github.com/sge-network/sge/app/upgrades/v1"
v2 "github.com/sge-network/sge/app/upgrades/v2"
v3 "github.com/sge-network/sge/app/upgrades/v3"
v4 "github.com/sge-network/sge/app/upgrades/v4"
abci "github.com/tendermint/tendermint/abci/types"
tmjson "github.com/tendermint/tendermint/libs/json"
"github.com/tendermint/tendermint/libs/log"
Expand Down Expand Up @@ -73,6 +74,7 @@ var (
v1.Upgrade,
v2.Upgrade,
v3.Upgrade,
v4.Upgrade,
}
)

Expand Down
24 changes: 24 additions & 0 deletions app/upgrades/v4/consts.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v3

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

"github.com/sge-network/sge/app/upgrades"
rewardmoduletypes "github.com/sge-network/sge/x/reward/types"
subaccountmoduletypes "github.com/sge-network/sge/x/subaccount/types"
)

// UpgradeName defines the on-chain upgrade name for the v1.3.0 upgrade.
const UpgradeName = "v1.3.0"

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{
subaccountmoduletypes.ModuleName,
rewardmoduletypes.ModuleName,
},
Deleted: []string{},
},
}
22 changes: 22 additions & 0 deletions app/upgrades/v4/upgrades.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package v3

import (
"time"

sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"
"github.com/sge-network/sge/app/keepers"
)

const DefaultExpeditedPeriod time.Duration = time.Hour * 24

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, fromVM module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, fromVM)
}
}
4 changes: 3 additions & 1 deletion proto/sge/subaccount/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ service Query {
// QueryParamsRequest is the request type for the Query/Params RPC method
message QueryParamsRequest {}
// QueryParamsResponse is the response type for the Query/Params RPC method
message QueryParamsResponse { sge.subaccount.Params params = 1; }
message QueryParamsResponse {
sge.subaccount.Params params = 1 [ (gogoproto.nullable) = false ];
}

// QuerySubaccountRequest is the request type for the Query/Subaccount RPC
message QuerySubaccountRequest { string address = 1; }
Expand Down
3 changes: 3 additions & 0 deletions x/reward/keeper/msg_server_campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,12 @@ func (k msgServer) UpdateCampaign(goCtx context.Context, msg *types.MsgUpdateCam
); err != nil {
return nil, sdkerrors.Wrapf(types.ErrInFundingCampaignPool, "%s", err)
}

campaign.Pool.Total = campaign.Pool.Total.Add(msg.TopupFunds)
}

campaign.EndTS = payload.EndTs
campaign.IsActive = payload.IsActive

k.SetCampaign(ctx, campaign)

Expand Down
2 changes: 1 addition & 1 deletion x/reward/keeper/msg_server_reward.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func (k msgServer) GrantReward(goCtx context.Context, msg *types.MsgGrantReward)
return nil, sdkerrors.Wrapf(sdkerrtypes.ErrInvalidRequest, "campaign with uid: %s not active", msg.CampaignUid)
}

if err := campaign.CheckExpiration(cast.ToUint64(ctx.BlockTime().Unix())); err != nil {
if err := campaign.CheckTS(cast.ToUint64(ctx.BlockTime().Unix())); err != nil {
return nil, err
}

Expand Down
5 changes: 4 additions & 1 deletion x/reward/types/campaign.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,13 @@ func (c *Campaign) GetRewardsFactory() (IRewardFactory, error) {
}
}

func (c *Campaign) CheckExpiration(blockTime uint64) error {
func (c *Campaign) CheckTS(blockTime uint64) error {
if blockTime > c.EndTS {
return sdkerrors.Wrapf(ErrCampaignEnded, "end timestamp %d, block time %d", c.EndTS, blockTime)
}
if blockTime < c.StartTS {
return sdkerrors.Wrapf(ErrCampaignHasNotStarted, "start timestamp %d, block time %d", c.EndTS, blockTime)
}
return nil
}

Expand Down
1 change: 1 addition & 0 deletions x/reward/types/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ var (
ErrUnknownAccType = sdkerrors.Register(ModuleName, 7124, "unknown account type")
ErrReceiverAddrCanNotBeSubAcc = sdkerrors.Register(ModuleName, 7125, "receiver account can not be sub account address")
ErrInvalidFunds = sdkerrors.Register(ModuleName, 7126, "invalid funds")
ErrCampaignHasNotStarted = sdkerrors.Register(ModuleName, 7127, "campaign validity period is not started yet")
)
1 change: 1 addition & 0 deletions x/subaccount/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ func GetQueryCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(QuerySubaccount())

return cmd
Expand Down
36 changes: 36 additions & 0 deletions x/subaccount/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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/subaccount/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
6 changes: 3 additions & 3 deletions x/subaccount/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TxCreate() *cobra.Command {
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgCreate{
Creator: clientCtx.From,
Creator: clientCtx.GetFromAddress().String(),
Owner: subaccountOwner.String(),
LockedBalances: []types.LockedBalance{
{
Expand Down Expand Up @@ -128,7 +128,7 @@ func TxTopup() *cobra.Command {
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgTopUp{
Creator: clientCtx.From,
Creator: clientCtx.GetFromAddress().String(),
Address: subaccountAddress.String(),
LockedBalances: []types.LockedBalance{
{
Expand Down Expand Up @@ -159,7 +159,7 @@ func TxWithdraw() *cobra.Command {
return err
}
return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgWithdrawUnlockedBalances{
Creator: clientCtx.From,
Creator: clientCtx.GetFromAddress().String(),
})
},
}
Expand Down
21 changes: 21 additions & 0 deletions x/subaccount/keeper/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package keeper

import (
"context"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"

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

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

func (k Keeper) Params(goCtx context.Context, req *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "invalid request")
}
ctx := sdk.UnwrapSDKContext(goCtx)

return &types.QueryParamsResponse{Params: k.GetParams(ctx)}, nil
}
2 changes: 1 addition & 1 deletion x/subaccount/keeper/query_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ func (q queryServer) Subaccount(goCtx context.Context, request *types.QuerySubac

func (q queryServer) Params(ctx context.Context, _ *types.QueryParamsRequest) (*types.QueryParamsResponse, error) {
params := q.keeper.GetParams(sdk.UnwrapSDKContext(ctx))
return &types.QueryParamsResponse{Params: &params}, nil
return &types.QueryParamsResponse{Params: params}, nil
}
2 changes: 1 addition & 1 deletion x/subaccount/keeper/query_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestQueryServer(t *testing.T) {
t.Run("Params", func(t *testing.T) {
gotParams, err := queryServer.Params(sdk.WrapSDKContext(ctx), &types.QueryParamsRequest{})
require.NoError(t, err)
require.Equal(t, wantParams, *gotParams.Params)
require.Equal(t, wantParams, gotParams.Params)
})

t.Run("Subaccount", func(t *testing.T) {
Expand Down
73 changes: 33 additions & 40 deletions x/subaccount/types/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading