diff --git a/app/app.go b/app/app.go index bd7b00dc..daf307e3 100644 --- a/app/app.go +++ b/app/app.go @@ -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" @@ -73,6 +74,7 @@ var ( v1.Upgrade, v2.Upgrade, v3.Upgrade, + v4.Upgrade, } ) diff --git a/app/upgrades/v4/consts.go b/app/upgrades/v4/consts.go new file mode 100644 index 00000000..d9eb2fe4 --- /dev/null +++ b/app/upgrades/v4/consts.go @@ -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{}, + }, +} diff --git a/app/upgrades/v4/upgrades.go b/app/upgrades/v4/upgrades.go new file mode 100644 index 00000000..e26b3bcf --- /dev/null +++ b/app/upgrades/v4/upgrades.go @@ -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) + } +} diff --git a/proto/sge/subaccount/query.proto b/proto/sge/subaccount/query.proto index c74a9746..882953ae 100644 --- a/proto/sge/subaccount/query.proto +++ b/proto/sge/subaccount/query.proto @@ -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; } diff --git a/x/reward/keeper/msg_server_campaign.go b/x/reward/keeper/msg_server_campaign.go index cccbc582..9b97348a 100644 --- a/x/reward/keeper/msg_server_campaign.go +++ b/x/reward/keeper/msg_server_campaign.go @@ -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) diff --git a/x/reward/keeper/msg_server_reward.go b/x/reward/keeper/msg_server_reward.go index a6fbefda..109164ac 100644 --- a/x/reward/keeper/msg_server_reward.go +++ b/x/reward/keeper/msg_server_reward.go @@ -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 } diff --git a/x/reward/types/campaign.go b/x/reward/types/campaign.go index 83ca69d4..f9493c47 100644 --- a/x/reward/types/campaign.go +++ b/x/reward/types/campaign.go @@ -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 } diff --git a/x/reward/types/errors.go b/x/reward/types/errors.go index 7e431176..75818295 100644 --- a/x/reward/types/errors.go +++ b/x/reward/types/errors.go @@ -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") ) diff --git a/x/subaccount/client/cli/query.go b/x/subaccount/client/cli/query.go index e4d9468a..ff7c36d3 100644 --- a/x/subaccount/client/cli/query.go +++ b/x/subaccount/client/cli/query.go @@ -27,6 +27,7 @@ func GetQueryCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand(CmdQueryParams()) cmd.AddCommand(QuerySubaccount()) return cmd diff --git a/x/subaccount/client/cli/query_params.go b/x/subaccount/client/cli/query_params.go new file mode 100644 index 00000000..53eeb1fb --- /dev/null +++ b/x/subaccount/client/cli/query_params.go @@ -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 +} diff --git a/x/subaccount/client/cli/tx.go b/x/subaccount/client/cli/tx.go index b1dee66c..9800a700 100644 --- a/x/subaccount/client/cli/tx.go +++ b/x/subaccount/client/cli/tx.go @@ -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{ { @@ -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{ { @@ -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(), }) }, } diff --git a/x/subaccount/keeper/query_params.go b/x/subaccount/keeper/query_params.go new file mode 100644 index 00000000..022fa79d --- /dev/null +++ b/x/subaccount/keeper/query_params.go @@ -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 +} diff --git a/x/subaccount/keeper/query_server.go b/x/subaccount/keeper/query_server.go index 94b5b0e8..2384be1a 100644 --- a/x/subaccount/keeper/query_server.go +++ b/x/subaccount/keeper/query_server.go @@ -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: ¶ms}, nil + return &types.QueryParamsResponse{Params: params}, nil } diff --git a/x/subaccount/keeper/query_server_test.go b/x/subaccount/keeper/query_server_test.go index 4fedea4d..bdaa16f4 100644 --- a/x/subaccount/keeper/query_server_test.go +++ b/x/subaccount/keeper/query_server_test.go @@ -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) { diff --git a/x/subaccount/types/query.pb.go b/x/subaccount/types/query.pb.go index aad7559f..74a603cc 100644 --- a/x/subaccount/types/query.pb.go +++ b/x/subaccount/types/query.pb.go @@ -68,7 +68,7 @@ var xxx_messageInfo_QueryParamsRequest proto.InternalMessageInfo // QueryParamsResponse is the response type for the Query/Params RPC method type QueryParamsResponse struct { - Params *Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params,omitempty"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` } func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } @@ -104,11 +104,11 @@ func (m *QueryParamsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo -func (m *QueryParamsResponse) GetParams() *Params { +func (m *QueryParamsResponse) GetParams() Params { if m != nil { return m.Params } - return nil + return Params{} } // QuerySubaccountRequest is the request type for the Query/Subaccount RPC @@ -227,7 +227,7 @@ func init() { func init() { proto.RegisterFile("sge/subaccount/query.proto", fileDescriptor_e8576ea34550c199) } var fileDescriptor_e8576ea34550c199 = []byte{ - // 429 bytes of a gzipped FileDescriptorProto + // 431 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x2a, 0x4e, 0x4f, 0xd5, 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x2f, 0x2c, 0x4d, 0x2d, 0xaa, 0xd4, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x2c, 0x4e, 0x4f, 0xcd, 0x4b, 0x2d, 0x29, 0xcf, @@ -236,25 +236,25 @@ var fileDescriptor_e8576ea34550c199 = []byte{ 0x0b, 0x32, 0xf5, 0x13, 0xf3, 0xf2, 0xf2, 0x4b, 0x12, 0x4b, 0x32, 0xf3, 0xf3, 0x8a, 0x61, 0xb2, 0x68, 0x56, 0x25, 0x25, 0xe6, 0x24, 0xe6, 0x25, 0xa7, 0x42, 0x65, 0xa5, 0xd1, 0x64, 0x0b, 0x12, 0x8b, 0x12, 0x73, 0xa1, 0x5a, 0x95, 0x44, 0xb8, 0x84, 0x02, 0x41, 0x0e, 0x0b, 0x00, 0x0b, 0x06, - 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0x05, 0x70, 0x09, 0xa3, 0x88, 0x16, 0x17, 0xe4, 0xe7, - 0x15, 0xa7, 0x0a, 0x59, 0x72, 0xb1, 0x41, 0x34, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x29, - 0xea, 0xe1, 0xf4, 0x87, 0x1e, 0x54, 0x2b, 0x54, 0x83, 0x92, 0x11, 0x97, 0x18, 0xd8, 0xc4, 0x60, - 0xb8, 0x0a, 0xa8, 0x5d, 0x42, 0x12, 0x5c, 0xec, 0x89, 0x29, 0x29, 0x45, 0xa9, 0xc5, 0x10, 0x53, - 0x39, 0x83, 0x60, 0x5c, 0xa5, 0xab, 0x8c, 0x5c, 0xe2, 0x18, 0x9a, 0xa0, 0x4e, 0xc1, 0xa9, 0x4b, - 0xc8, 0x93, 0x8b, 0x1d, 0xea, 0x7f, 0x09, 0x26, 0xb0, 0x2b, 0x35, 0xf1, 0xb8, 0xd2, 0x11, 0x42, - 0x07, 0x97, 0xe6, 0xe6, 0x26, 0x16, 0x55, 0x3a, 0xb1, 0x9c, 0xb8, 0x27, 0xcf, 0x10, 0x04, 0xd3, - 0x2f, 0x14, 0xca, 0xc5, 0x97, 0x93, 0x9f, 0x9c, 0x9d, 0x9a, 0x12, 0x0f, 0x33, 0x91, 0x59, 0x81, - 0x59, 0x83, 0xdb, 0x48, 0x03, 0x8f, 0x89, 0x3e, 0x60, 0x0d, 0x4e, 0x10, 0xf5, 0x50, 0x03, 0x79, - 0x73, 0x90, 0x05, 0x8d, 0xb6, 0x32, 0x71, 0xb1, 0x82, 0xfd, 0x25, 0xb4, 0x90, 0x91, 0x8b, 0x0b, - 0xe1, 0x39, 0x21, 0x43, 0x3c, 0xe6, 0x62, 0x0f, 0x3d, 0x29, 0x23, 0x52, 0xb4, 0x40, 0xc2, 0x4e, - 0x49, 0xa7, 0xe9, 0xf2, 0x93, 0xc9, 0x4c, 0x6a, 0x42, 0x2a, 0xfa, 0x68, 0x29, 0x03, 0x89, 0x59, - 0x0d, 0x0d, 0xce, 0x5a, 0xa1, 0x76, 0x46, 0x2e, 0x36, 0x48, 0x64, 0x0a, 0xe9, 0x12, 0xb2, 0x0c, - 0x25, 0x15, 0x49, 0xe9, 0x11, 0xab, 0x1c, 0xea, 0x2e, 0x39, 0xb0, 0xbb, 0x24, 0x84, 0xc4, 0xf4, - 0xb1, 0xa6, 0x58, 0x27, 0xf7, 0x13, 0x8f, 0xe4, 0x18, 0x2f, 0x3c, 0x92, 0x63, 0x7c, 0xf0, 0x48, - 0x8e, 0x71, 0xc2, 0x63, 0x39, 0x86, 0x0b, 0x8f, 0xe5, 0x18, 0x6e, 0x3c, 0x96, 0x63, 0x88, 0xd2, - 0x4d, 0xcf, 0x2c, 0xc9, 0x28, 0x4d, 0xd2, 0x4b, 0xce, 0xcf, 0x05, 0xe9, 0xd5, 0x85, 0x5a, 0x0a, - 0x36, 0xa7, 0x02, 0xd9, 0xa4, 0x92, 0xca, 0x82, 0xd4, 0xe2, 0x24, 0x36, 0x70, 0xda, 0x37, 0x06, - 0x04, 0x00, 0x00, 0xff, 0xff, 0x56, 0x87, 0x3d, 0x64, 0xa3, 0x03, 0x00, 0x00, + 0xa5, 0x16, 0x96, 0xa6, 0x16, 0x97, 0x28, 0x85, 0x71, 0x09, 0xa3, 0x88, 0x16, 0x17, 0xe4, 0xe7, + 0x15, 0xa7, 0x0a, 0xd9, 0x73, 0xb1, 0x41, 0x34, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x29, + 0xea, 0xe1, 0xf4, 0x87, 0x1e, 0x44, 0xab, 0x13, 0xcb, 0x89, 0x7b, 0xf2, 0x0c, 0x41, 0x50, 0x6d, + 0x4a, 0x46, 0x5c, 0x62, 0x60, 0x73, 0x83, 0xe1, 0xea, 0xa0, 0x36, 0x0a, 0x49, 0x70, 0xb1, 0x27, + 0xa6, 0xa4, 0x14, 0xa5, 0x16, 0x43, 0xcc, 0xe6, 0x0c, 0x82, 0x71, 0x95, 0xae, 0x32, 0x72, 0x89, + 0x63, 0x68, 0x82, 0x3a, 0x08, 0xa7, 0x2e, 0x21, 0x4f, 0x2e, 0x76, 0x68, 0x28, 0x48, 0x30, 0x81, + 0xdd, 0xaa, 0x89, 0xc7, 0xad, 0x8e, 0x10, 0x3a, 0xb8, 0x34, 0x37, 0x37, 0xb1, 0xa8, 0x12, 0xea, + 0x66, 0x98, 0x7e, 0xa1, 0x50, 0x2e, 0xbe, 0x9c, 0xfc, 0xe4, 0xec, 0xd4, 0x94, 0x78, 0x98, 0x89, + 0xcc, 0x0a, 0xcc, 0x1a, 0xdc, 0x46, 0x1a, 0x78, 0x4c, 0xf4, 0x01, 0x6b, 0x70, 0x82, 0xa8, 0x87, + 0x1a, 0xc8, 0x9b, 0x83, 0x2c, 0x68, 0xb4, 0x95, 0x89, 0x8b, 0x15, 0xec, 0x2f, 0xa1, 0x85, 0x8c, + 0x5c, 0x5c, 0x08, 0xcf, 0x09, 0x19, 0xe2, 0x31, 0x17, 0x7b, 0xe8, 0x49, 0x19, 0x91, 0xa2, 0x05, + 0x12, 0x76, 0x4a, 0x3a, 0x4d, 0x97, 0x9f, 0x4c, 0x66, 0x52, 0x13, 0x52, 0xd1, 0x47, 0x4b, 0x1f, + 0x48, 0xcc, 0x6a, 0x68, 0x70, 0xd6, 0x0a, 0xb5, 0x33, 0x72, 0xb1, 0x41, 0xa2, 0x54, 0x48, 0x97, + 0x90, 0x65, 0x28, 0x69, 0x49, 0x4a, 0x8f, 0x58, 0xe5, 0x50, 0x77, 0xc9, 0x81, 0xdd, 0x25, 0x21, + 0x24, 0xa6, 0x8f, 0x35, 0xdd, 0x3a, 0xb9, 0x9f, 0x78, 0x24, 0xc7, 0x78, 0xe1, 0x91, 0x1c, 0xe3, + 0x83, 0x47, 0x72, 0x8c, 0x13, 0x1e, 0xcb, 0x31, 0x5c, 0x78, 0x2c, 0xc7, 0x70, 0xe3, 0xb1, 0x1c, + 0x43, 0x94, 0x6e, 0x7a, 0x66, 0x49, 0x46, 0x69, 0x92, 0x5e, 0x72, 0x7e, 0x2e, 0x48, 0xaf, 0x2e, + 0xd4, 0x52, 0xb0, 0x39, 0x15, 0xc8, 0x26, 0x95, 0x54, 0x16, 0xa4, 0x16, 0x27, 0xb1, 0x81, 0x73, + 0x80, 0x31, 0x20, 0x00, 0x00, 0xff, 0xff, 0xb3, 0x1e, 0x5b, 0x4e, 0xa9, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -420,18 +420,16 @@ func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Params != nil { - { - size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) - if err != nil { - return 0, err - } - i -= size - i = encodeVarintQuery(dAtA, i, uint64(size)) + { + size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err } - i-- - dAtA[i] = 0xa + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) } + i-- + dAtA[i] = 0xa return len(dAtA) - i, nil } @@ -545,10 +543,8 @@ func (m *QueryParamsResponse) Size() (n int) { } var l int _ = l - if m.Params != nil { - l = m.Params.Size() - n += 1 + l + sovQuery(uint64(l)) - } + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) return n } @@ -700,9 +696,6 @@ func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - if m.Params == nil { - m.Params = &Params{} - } if err := m.Params.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err }