diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 8b07d264..7ca9ec6e 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -102,7 +102,6 @@ type AppKeepers struct { TransferKeeper ibctransferkeeper.Keeper FeeGrantKeeper feegrantkeeper.Keeper AuthzKeeper authzkeeper.Keeper - SubaccountKeeper subaccountkeeper.Keeper // // SGE keepers \\\\ BetKeeper *betmodulekeeper.Keeper @@ -111,14 +110,15 @@ type AppKeepers struct { HouseKeeper *housemodulekeeper.Keeper OrderbookKeeper *orderbookmodulekeeper.Keeper OVMKeeper *ovmmodulekeeper.Keeper - SubaccountModule subaccount.AppModule + SubaccountKeeper *subaccountkeeper.Keeper // // SGE modules \\\\ - BetModule betmodule.AppModule - MarketModule marketmodule.AppModule - HouseModule housemodule.AppModule - OrderbookModule orderbookmodule.AppModule - OVMModule ovmmodule.AppModule + BetModule betmodule.AppModule + MarketModule marketmodule.AppModule + HouseModule housemodule.AppModule + OrderbookModule orderbookmodule.AppModule + OVMModule ovmmodule.AppModule + SubaccountModule subaccount.AppModule // make scoped keepers public for test purposes ScopedIBCKeeper capabilitykeeper.ScopedKeeper @@ -399,6 +399,18 @@ func NewAppKeeper( ) appKeepers.OrderbookKeeper.SetHouseKeeper(appKeepers.HouseKeeper) + appKeepers.SubaccountKeeper = subaccountkeeper.NewKeeper( + appCodec, + appKeepers.keys[subaccounttypes.StoreKey], + appKeepers.GetSubspace(subaccounttypes.ModuleName), + appKeepers.AccountKeeper, + appKeepers.BankKeeper, + appKeepers.OVMKeeper, + appKeepers.BetKeeper, + appKeepers.OrderbookKeeper, + appKeepers.HouseKeeper, + ) + // // SGE modules \\\\ appKeepers.BetModule = betmodule.NewAppModule( @@ -431,17 +443,8 @@ func NewAppKeeper( appKeepers.AccountKeeper, appKeepers.BankKeeper, ) - appKeepers.SubaccountKeeper = subaccountkeeper.NewKeeper( - appCodec, - appKeepers.keys[subaccounttypes.StoreKey], - appKeepers.GetSubspace(subaccounttypes.ModuleName), - appKeepers.BankKeeper, - appKeepers.OVMKeeper, - appKeepers.BetKeeper, - appKeepers.OrderbookKeeper, - appKeepers.HouseKeeper, - ) - appKeepers.SubaccountModule = subaccount.NewAppModule(appKeepers.SubaccountKeeper) + + appKeepers.SubaccountModule = subaccount.NewAppModule(*appKeepers.SubaccountKeeper) // Create static IBC router, add transfer route, then set and seal it ibcRouter := ibcporttypes.NewRouter() diff --git a/proto/sge/subaccount/genesis.proto b/proto/sge/subaccount/genesis.proto index 9aa1fe17..3eb7cb86 100644 --- a/proto/sge/subaccount/genesis.proto +++ b/proto/sge/subaccount/genesis.proto @@ -3,6 +3,7 @@ package sgenetwork.sge.subaccount; import "gogoproto/gogo.proto"; import "sge/subaccount/params.proto"; +import "sge/subaccount/subaccount.proto"; option go_package = "github.com/sge-network/sge/x/subaccount/types"; @@ -10,4 +11,24 @@ option go_package = "github.com/sge-network/sge/x/subaccount/types"; message GenesisState { // params contains the subaccount parameters. Params params = 1 [ (gogoproto.nullable) = false ]; + + uint64 subaccount_id = 2; + + // subaccounts contains all the subaccounts. + repeated GenesisSubaccount subaccounts = 3 [ (gogoproto.nullable) = false ]; } + +// GenesisSubaccount defines the genesis subaccount containing owner, address and balance information. +message GenesisSubaccount { + // address is the address of the subaccount. + string address = 1; + + // owner is the owner of the subaccount. + string owner = 2; + + // balance defines the balance status of a subaccount + Balance balance = 3 [ (gogoproto.nullable) = false ]; + + // locked_balances defines the lockup of balances history of a subaccount + repeated LockedBalance locked_balances = 4 [ (gogoproto.nullable) = false ]; +} \ No newline at end of file diff --git a/proto/sge/subaccount/query.proto b/proto/sge/subaccount/query.proto index 4f48668b..d83b9713 100644 --- a/proto/sge/subaccount/query.proto +++ b/proto/sge/subaccount/query.proto @@ -3,5 +3,40 @@ package sgenetwork.sge.subaccount; option go_package = "github.com/sge-network/sge/x/subaccount/types"; +import "gogoproto/gogo.proto"; +import "google/api/annotations.proto"; +import "sge/subaccount/subaccount.proto"; +import "sge/subaccount/params.proto"; + // Query defines the gRPC querier service. -service Query {} +service Query { + // Subaccount fetches a subaccount given the owner. + rpc Subaccount(QuerySubaccountRequest) returns (QuerySubaccountResponse) { + option (google.api.http).get = "/sge/subaccount/subaccount"; + }; + // Params returns the subaccount module parameters. + rpc Params(QueryParamsRequest) returns (QueryParamsResponse) { + option (google.api.http).get = "/sge/subaccount/params"; + }; +} + +// 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; +} + +// QuerySubaccountRequest is the request type for the Query/Subaccount RPC +message QuerySubaccountRequest { + string subaccount_owner = 1; +} + +// QuerySubaccountResponse is the response type for the Query/Subaccount RPC +message QuerySubaccountResponse { + string subaccount_address = 1; + sge.subaccount.Balance balance = 2 [(gogoproto.nullable) = false ]; + repeated sge.subaccount.LockedBalance locked_balance = 3 [(gogoproto.nullable) = false ]; +} + + diff --git a/proto/sge/subaccount/tx.proto b/proto/sge/subaccount/tx.proto index 2ad48976..fe0259cc 100644 --- a/proto/sge/subaccount/tx.proto +++ b/proto/sge/subaccount/tx.proto @@ -4,6 +4,7 @@ package sgenetwork.sge.subaccount; import "sge/subaccount/subaccount.proto"; import "sge/bet/tx.proto"; import "sge/house/tx.proto"; +import "gogoproto/gogo.proto"; option go_package = "github.com/sge-network/sge/x/subaccount/types"; @@ -37,7 +38,7 @@ message MsgCreateSubAccount { string sub_account_owner = 2; // locked_balances is the list of balance locks. - repeated LockedBalance locked_balances = 3; + repeated LockedBalance locked_balances = 3 [(gogoproto.nullable) = false]; } // MsgCreateAccountResponse defines the Msg/CreateAccount response type. @@ -52,7 +53,7 @@ message MsgTopUp { string sub_account = 2; // locked_balances is the list of balance locks. - repeated LockedBalance locked_balances = 3; + repeated LockedBalance locked_balances = 3 [(gogoproto.nullable) = false]; } // MsgTopUpResponse defines the Msg/TopUp response type. diff --git a/x/orderbook/keeper/hooks.go b/x/orderbook/keeper/hooks.go index 2a1e9805..dc969159 100644 --- a/x/orderbook/keeper/hooks.go +++ b/x/orderbook/keeper/hooks.go @@ -6,9 +6,11 @@ type Hook interface { AfterBettorWin(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, profit sdk.Int) AfterBettorLoss(ctx sdk.Context, bettor sdk.AccAddress, originalAmount sdk.Int) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, originalAmount, fee sdk.Int) - AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) - AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) - AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) + + AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int) + AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int) + AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int) + AfterHouseFeeRefund(ctx sdk.Context, house sdk.AccAddress, fee sdk.Int) } func (k *Keeper) RegisterHook(hook Hook) { diff --git a/x/orderbook/keeper/orderbook_settle.go b/x/orderbook/keeper/orderbook_settle.go index ff483833..0924afc3 100644 --- a/x/orderbook/keeper/orderbook_settle.go +++ b/x/orderbook/keeper/orderbook_settle.go @@ -2,6 +2,7 @@ package keeper import ( "fmt" + "log" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -108,16 +109,10 @@ func (k Keeper) settleParticipation( refundHouseDepositFeeToDepositor := false - var ( - profit sdk.Int - originalAmount sdk.Int - feeRefund *sdk.Int - cancelled bool - ) - switch market.Status { case markettypes.MarketStatus_MARKET_STATUS_RESULT_DECLARED: depositPlusProfit := bp.Liquidity.Add(bp.ActualProfit) + log.Printf("orderbook_settle.goL115: market status declared") // refund participant's account from orderbook liquidity pool. if err := k.refund(types.OrderBookLiquidityFunder{}, ctx, depositorAddress, depositPlusProfit); err != nil { return err @@ -125,9 +120,19 @@ func (k Keeper) settleParticipation( if bp.NotParticipatedInBetFulfillment() { refundHouseDepositFeeToDepositor = true } - // prepare hook variables. - profit = bp.ActualProfit - originalAmount = bp.Liquidity + if bp.ActualProfit.IsNegative() { + log.Printf("orderbook_settle.goL123: market declared loss") + for _, h := range k.hooks { + log.Printf("orderbook_settle.goL125: market declared loss hook call") + h.AfterHouseLoss(ctx, depositorAddress, bp.Liquidity, bp.ActualProfit.Abs()) + } + } else { + log.Printf("orderbook_settle.goL129: market declared win") + for _, h := range k.hooks { + log.Printf("orderbook_settle.goL130: market declared win hook call") + h.AfterHouseWin(ctx, depositorAddress, bp.Liquidity, bp.ActualProfit) + } + } case markettypes.MarketStatus_MARKET_STATUS_CANCELED, markettypes.MarketStatus_MARKET_STATUS_ABORTED: @@ -136,9 +141,11 @@ func (k Keeper) settleParticipation( return err } refundHouseDepositFeeToDepositor = true - profit = sdk.ZeroInt() - originalAmount = bp.Liquidity - cancelled = true + log.Printf("orderbook_settle.goL139: market cancelled, hooks to execute: %d", len(k.hooks)) + for _, h := range k.hooks { + log.Printf("orderbook_settle.goL141: market cancelled hook call") + h.AfterHouseRefund(ctx, depositorAddress, bp.Liquidity) + } default: return sdkerrors.Wrapf( types.ErrUnknownMarketStatus, @@ -153,7 +160,9 @@ func (k Keeper) settleParticipation( if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, depositorAddress, bp.Fee); err != nil { return err } - feeRefund = &bp.Fee + for _, h := range k.hooks { + h.AfterHouseFeeRefund(ctx, depositorAddress, bp.Fee) + } } else { // refund participant's account from house fee collector. if err := k.refund(housetypes.HouseFeeCollectorFunder{}, ctx, sdk.MustAccAddressFromBech32(market.Creator), bp.Fee); err != nil { @@ -164,20 +173,5 @@ func (k Keeper) settleParticipation( bp.IsSettled = true k.SetOrderBookParticipation(ctx, bp) - // call hooks - switch { - case cancelled: - for _, h := range k.hooks { - h.AfterHouseRefund(ctx, depositorAddress, originalAmount, *feeRefund) - } - case profit.IsNegative(): - for _, h := range k.hooks { - h.AfterHouseLoss(ctx, depositorAddress, originalAmount, profit.Abs(), feeRefund) - } - case profit.IsPositive(), profit.IsZero(): - for _, h := range k.hooks { - h.AfterHouseWin(ctx, depositorAddress, originalAmount, profit, feeRefund) - } - } return nil } diff --git a/x/subaccount/client/cli/query.go b/x/subaccount/client/cli/query.go index e114f37a..4c150533 100644 --- a/x/subaccount/client/cli/query.go +++ b/x/subaccount/client/cli/query.go @@ -1,13 +1,16 @@ package cli import ( + "context" "fmt" + "github.com/cosmos/cosmos-sdk/client/flags" + sdk "github.com/cosmos/cosmos-sdk/types" "github.com/spf13/cobra" "github.com/cosmos/cosmos-sdk/client" - "github.com/sge-network/sge/x/bet/types" + "github.com/sge-network/sge/x/subaccount/types" ) // GetQueryCmd returns the cli query commands for this module @@ -24,7 +27,36 @@ func GetQueryCmd() *cobra.Command { RunE: client.ValidateCmd, } - cmd.AddCommand() + cmd.AddCommand(QuerySubaccount()) + + return cmd +} + +func QuerySubaccount() *cobra.Command { + cmd := &cobra.Command{ + Use: "subaccount [owner-address]", + Short: "queries the subaccount of an owner", + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx := client.GetClientContextFromCmd(cmd) + + queryClient := types.NewQueryClient(clientCtx) + + _, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + + res, err := queryClient.Subaccount(context.Background(), &types.QuerySubaccountRequest{SubaccountOwner: args[0]}) + 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 6c69778b..5d610f6d 100644 --- a/x/subaccount/client/cli/tx.go +++ b/x/subaccount/client/cli/tx.go @@ -2,9 +2,18 @@ package cli import ( "fmt" + "strings" + "time" "github.com/cosmos/cosmos-sdk/client" + "github.com/cosmos/cosmos-sdk/client/flags" + "github.com/cosmos/cosmos-sdk/client/tx" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/cosmos/cosmos-sdk/version" + bettypes "github.com/sge-network/sge/x/bet/types" + housetypes "github.com/sge-network/sge/x/house/types" "github.com/sge-network/sge/x/subaccount/types" + "github.com/spf13/cast" "github.com/spf13/cobra" ) @@ -18,5 +27,286 @@ func GetTxCmd() *cobra.Command { RunE: client.ValidateCmd, } + cmd.AddCommand( + TxCreateSubaccount(), + TxTopupSubaccount(), + TxWager(), + TxHouseDeposit(), + TxHouseWithdraw(), + TxWithdraw(), + ) + + return cmd +} + +func TxCreateSubaccount() *cobra.Command { + const ( + flagFunds = "funds" + flagLockDuration = "lock-duration" + ) + + cmd := &cobra.Command{ + Use: "create-subaccount [subaccount-owner]", + Short: "Create a new subaccount", + Long: `Create a new subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount create-subaccount sge123456 --funds 1000000000 --lock-duration 8760h --from subaccount-funder-key`, version.AppName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + subaccountOwner, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + fundsStr, err := cmd.Flags().GetString(flagFunds) + if err != nil { + return err + } + funds, ok := sdk.NewIntFromString(fundsStr) + if !ok { + return fmt.Errorf("invalid funds amount: %s", fundsStr) + } + unlocksAfter, err := cmd.Flags().GetDuration(flagLockDuration) + if err != nil { + return err + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgCreateSubAccount{ + Sender: clientCtx.From, + SubAccountOwner: subaccountOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTime: time.Now().Add(unlocksAfter), + Amount: funds, + }, + }, + }) + }, + } + cmd.Flags().String(flagFunds, "", "Funds to lock in the subaccount") + cmd.Flags().Duration(flagLockDuration, 12*30*24*time.Hour, "duration for which the funds will be locked") + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func TxTopupSubaccount() *cobra.Command { + const ( + flagFunds = "funds" + flagLockDuration = "lock-duration" + ) + cmd := &cobra.Command{ + Use: "topup-subaccount [subaccount-owner]", + Short: "Topup a subaccount", + Long: `Topup a subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount topup-subaccount sge123456 --funds 1000000000 --lock-duration 8760h --from funder-address-key`, version.AppName), + Args: cobra.ExactArgs(1), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + subaccountAddress, err := sdk.AccAddressFromBech32(args[0]) + if err != nil { + return err + } + fundsStr, err := cmd.Flags().GetString(flagFunds) + if err != nil { + return err + } + funds, ok := sdk.NewIntFromString(fundsStr) + if !ok { + return fmt.Errorf("invalid funds amount: %s", fundsStr) + } + unlocksAfter, err := cmd.Flags().GetDuration(flagLockDuration) + if err != nil { + return err + } + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgTopUp{ + Sender: clientCtx.From, + SubAccount: subaccountAddress.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTime: time.Now().Add(unlocksAfter), + Amount: funds, + }, + }, + }) + }, + } + + cmd.Flags().String(flagFunds, "", "Funds to lock in the subaccount") + cmd.Flags().Duration(flagLockDuration, 12*30*24*time.Hour, "duration for which the funds will be locked") + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +func TxWithdraw() *cobra.Command { + cmd := &cobra.Command{ + Use: "withdraw --from subaccount-owner-key", + Short: "Withdraw unlocked funds from a subaccount", + Long: `Withdraw unlocked funds from a subaccount.`, + Example: fmt.Sprintf(`$ %s tx subaccount withdraw --from subaccount-owner-key`, version.AppName), + Args: cobra.NoArgs, + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgWithdrawUnlockedBalances{ + Sender: clientCtx.From, + }) + }, + } + flags.AddTxFlagsToCmd(cmd) + return cmd +} + +// TxWager implements a command to place and store a single bet +func TxWager() *cobra.Command { + cmd := &cobra.Command{ + Use: "wager [uid] [amount] [ticket] --from subaccount-owner-key", + Short: "Wager on an odds", + Long: "Wager on an odds. the uuid, amount and ticket required.", + Args: cobra.ExactArgs(3), + RunE: func(cmd *cobra.Command, args []string) (err error) { + // Get value arguments + uid := args[0] + argAmount := args[1] + argTicket := args[2] + + argAmountCosmosInt, ok := sdk.NewIntFromString(argAmount) + if !ok { + return fmt.Errorf("invalid amount: %s", argAmount) + } + + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + msg := bettypes.NewMsgWager( + clientCtx.GetFromAddress().String(), + bettypes.WagerProps{ + UID: uid, + Amount: argAmountCosmosInt, + Ticket: argTicket, + }, + ) + if err := msg.ValidateBasic(); err != nil { + return err + } + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgWager{Msg: msg}) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func TxHouseDeposit() *cobra.Command { + cmd := &cobra.Command{ + Use: "house-deposit [market_uid] [amount] [ticket] --from subaccount-owner-key", + Args: cobra.ExactArgs(3), + Short: "Deposit tokens in a market order book to be the house", + Long: strings.TrimSpace( + fmt.Sprintf(`Deposit tokens in a market order book to be the house. + + Example: + $ %s tx subaccount deposit bc79a72c-ad7e-4cf5-91a2-98af2751e812 1000usge {ticket string} --from mykey + `, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + argMarketUID := args[0] + + argAmountCosmosInt, ok := sdk.NewIntFromString(args[1]) + if !ok { + return fmt.Errorf("invalid amount: %s", args[1]) + } + + argTicket := args[2] + + depAddr := clientCtx.GetFromAddress() + + msg := &types.MsgHouseDeposit{Msg: housetypes.NewMsgDeposit(depAddr.String(), argMarketUID, argAmountCosmosInt, argTicket)} + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg) + }, + } + + flags.AddTxFlagsToCmd(cmd) + + return cmd +} + +func TxHouseWithdraw() *cobra.Command { + cmd := &cobra.Command{ + Use: "house-withdraw [market_uid] [participation_index] [ticket] [mode] [amount]", + Args: cobra.RangeArgs(4, 5), + Short: "Withdraw tokens from a deposit", + Long: strings.TrimSpace( + fmt.Sprintf(`Withdraw coins of unused amount corresponding to a deposit. + + Example: + $ %s tx subaccount withdraw bc79a72c-ad7e-4cf5-91a2-98af2751e812 1 {ticket string} 1 1000 --from mykey + `, + version.AppName, + ), + ), + RunE: func(cmd *cobra.Command, args []string) error { + clientCtx, err := client.GetClientTxContext(cmd) + if err != nil { + return err + } + + argMarketUID := args[0] + + particiapntIndex, err := cast.ToUint64E(args[1]) + if err != nil || particiapntIndex < 1 { + return fmt.Errorf("participant number should be a positive number") + } + + argTicket := args[2] + + mode, err := cast.ToInt64E(args[3]) + if err != nil { + return fmt.Errorf("mode provided must be a non-negative-integer: %v", mode) + } + + var argAmountCosmosInt sdk.Int + if mode == int64(housetypes.WithdrawalMode_WITHDRAWAL_MODE_PARTIAL) { + if len(args) != 5 { + return fmt.Errorf("amount is mandatory for partial mode") + } + + var ok bool + argAmountCosmosInt, ok = sdk.NewIntFromString(args[4]) + if !ok { + return fmt.Errorf("invalid amount: %s", args[4]) + } + } + + depAddr := clientCtx.GetFromAddress() + + msg := housetypes.NewMsgWithdraw(depAddr.String(), argMarketUID, argAmountCosmosInt, + particiapntIndex, housetypes.WithdrawalMode(mode), argTicket) + + return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), &types.MsgHouseWithdraw{Msg: msg}) + }, + } + + flags.AddTxFlagsToCmd(cmd) + return cmd } diff --git a/x/subaccount/genesis.go b/x/subaccount/genesis.go index cc53f741..928148c5 100644 --- a/x/subaccount/genesis.go +++ b/x/subaccount/genesis.go @@ -10,11 +10,23 @@ import ( // state. func InitGenesis(ctx sdk.Context, k keeper.Keeper, genState types.GenesisState) { k.SetParams(ctx, genState.Params) + if genState.SubaccountId != 0 { + k.SetID(ctx, genState.SubaccountId) + } + for _, acc := range genState.Subaccounts { + owner := sdk.MustAccAddressFromBech32(acc.Owner) + addr := sdk.MustAccAddressFromBech32(acc.Address) + k.SetSubAccountOwner(ctx, addr, owner) + k.SetLockedBalances(ctx, addr, acc.LockedBalances) + k.SetBalance(ctx, addr, acc.Balance) + } } // ExportGenesis returns the module's exported genesis. -func ExportGenesis(_ sdk.Context, _ keeper.Keeper) *types.GenesisState { - genesis := types.DefaultGenesis() - - return genesis +func ExportGenesis(ctx sdk.Context, k keeper.Keeper) *types.GenesisState { + return &types.GenesisState{ + Params: k.GetParams(ctx), + SubaccountId: k.Peek(ctx), + Subaccounts: k.GetAllSubaccounts(ctx), + } } diff --git a/x/subaccount/genesis_test.go b/x/subaccount/genesis_test.go new file mode 100644 index 00000000..a9ef8c71 --- /dev/null +++ b/x/subaccount/genesis_test.go @@ -0,0 +1,60 @@ +package subaccount_test + +import ( + "testing" + "time" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/testutil/sample" + simappUtil "github.com/sge-network/sge/testutil/simapp" + "github.com/sge-network/sge/x/subaccount" + "github.com/sge-network/sge/x/subaccount/types" + "github.com/stretchr/testify/require" +) + +var ( + subAccOwner = sample.NativeAccAddress() + micro = sdk.NewInt(1_000_000) + subAccFunds = sdk.NewInt(10_000).Mul(micro) + subAccAddr = types.NewAddressFromSubaccount(1) +) + +func TestGenesis(t *testing.T) { + app, ctx, err := simappUtil.GetTestObjects() + require.NoError(t, err) + + k := app.SubaccountKeeper + + wantGenesis := types.GenesisState{ + Params: types.DefaultParams(), + Subaccounts: []types.GenesisSubaccount{ + { + Address: subAccAddr.String(), + Owner: subAccOwner.String(), + Balance: types.Balance{ + DepositedAmount: subAccFunds, + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.ZeroInt(), + }, + LockedBalances: []types.LockedBalance{ + { + UnlockTime: time.Now().Add(24 * time.Hour).UTC(), + Amount: subAccFunds, + }, + }, + }, + }, + SubaccountId: 2, // next subaccount id + } + + subaccount.InitGenesis(ctx, *k, wantGenesis) + + require.Equal(t, wantGenesis.SubaccountId, k.Peek(ctx)) + require.Equal(t, wantGenesis.Params, k.GetParams(ctx)) + require.Len(t, wantGenesis.Subaccounts, 1) + require.Equal(t, wantGenesis.Subaccounts[0], k.GetAllSubaccounts(ctx)[0]) + + exportedGenesis := subaccount.ExportGenesis(ctx, *k) + require.Equal(t, wantGenesis, *exportedGenesis) +} diff --git a/x/subaccount/handler.go b/x/subaccount/handler.go index 2e7bd255..0cfcb853 100644 --- a/x/subaccount/handler.go +++ b/x/subaccount/handler.go @@ -1,25 +1,14 @@ package subaccount import ( + "fmt" + sdk "github.com/cosmos/cosmos-sdk/types" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/sge-network/sge/x/subaccount/keeper" ) // NewHandler initialize a new sdk.handler instance for registered messages -func NewHandler(k keeper.Keeper, accountKeeper authkeeper.AccountKeeper, bankKeeper bankkeeper.Keeper) sdk.Handler { - keeper.NewMsgServerImpl(k, accountKeeper, bankKeeper) - +func NewHandler() sdk.Handler { return func(ctx sdk.Context, msg sdk.Msg) (*sdk.Result, error) { - // ctx = ctx.WithEventManager(sdk.NewEventManager()) - - // switch msg := msg.(type) { - // default: - // errMsg := fmt.Sprintf("unrecognized %s message type: %T", types.ModuleName, msg) - // return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) - // } - - return nil, nil + return nil, fmt.Errorf("legacy handler not supported") } } diff --git a/x/subaccount/keeper/balance.go b/x/subaccount/keeper/balance.go new file mode 100644 index 00000000..a31f214e --- /dev/null +++ b/x/subaccount/keeper/balance.go @@ -0,0 +1,103 @@ +package keeper + +import ( + "github.com/cosmos/cosmos-sdk/store/prefix" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +// SetLockedBalances saves the locked balances of an account. +func (k Keeper) SetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress, lockedBalances []types.LockedBalance) { + store := ctx.KVStore(k.storeKey) + + for _, lockedBalance := range lockedBalances { + amountBytes, err := lockedBalance.Amount.Marshal() + if err != nil { + panic(err) + } + store.Set( + types.LockedBalanceKey(subAccountAddress, lockedBalance.UnlockTime), + amountBytes, + ) + } +} + +// GetLockedBalances returns the locked balances of an account. +func (k Keeper) GetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress) []types.LockedBalance { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), types.LockedBalancePrefixKey(subAccountAddress)).Iterator(nil, nil) + defer iterator.Close() + + var lockedBalances []types.LockedBalance + for ; iterator.Valid(); iterator.Next() { + unlockTime, err := sdk.ParseTimeBytes(iterator.Key()) + if err != nil { + panic(err) + } + + amount := new(sdk.Int) + err = amount.Unmarshal(iterator.Value()) + if err != nil { + panic(err) + } + lockedBalances = append(lockedBalances, types.LockedBalance{ + UnlockTime: unlockTime, + Amount: *amount, + }) + } + + return lockedBalances +} + +// GetUnlockedBalance returns the unlocked balance of an account. +func (k Keeper) GetUnlockedBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) sdk.Int { + iterator := prefix.NewStore(ctx.KVStore(k.storeKey), types.LockedBalancePrefixKey(subAccountAddress)). + Iterator(nil, sdk.FormatTimeBytes(ctx.BlockTime())) + + unlockedBalance := sdk.ZeroInt() + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + amount := new(sdk.Int) + err := amount.Unmarshal(iterator.Value()) + if err != nil { + panic(err) + } + unlockedBalance = unlockedBalance.Add(*amount) + } + + return unlockedBalance +} + +// SetBalance saves the balance of an account. +func (k Keeper) SetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress, balance types.Balance) { + store := ctx.KVStore(k.storeKey) + + bz := k.cdc.MustMarshal(&balance) + store.Set(types.BalanceKey(subAccountAddress), bz) +} + +// GetBalance returns the balance of an account. +func (k Keeper) GetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) (types.Balance, bool) { + store := ctx.KVStore(k.storeKey) + bz := store.Get(types.BalanceKey(subAccountAddress)) + if bz == nil { + return types.Balance{}, false + } + + balance := types.Balance{} + k.cdc.MustUnmarshal(bz, &balance) + + return balance, true +} + +// getBalances returns the balance, unlocked balance and bank balance of a subaccount +func (k Keeper) getBalances(sdkContext sdk.Context, subaccountAddr sdk.AccAddress, params types.Params) (types.Balance, sdk.Int, sdk.Coin) { + balance, exists := k.GetBalance(sdkContext, subaccountAddr) + if !exists { + panic("data corruption: subaccount exists but balance does not") + } + unlockedBalance := k.GetUnlockedBalance(sdkContext, subaccountAddr) + bankBalance := k.bankKeeper.GetBalance(sdkContext, subaccountAddr, params.LockedBalanceDenom) + + return balance, unlockedBalance, bankBalance +} diff --git a/x/subaccount/keeper/orderbook_hooks.go b/x/subaccount/keeper/hooks.go similarity index 75% rename from x/subaccount/keeper/orderbook_hooks.go rename to x/subaccount/keeper/hooks.go index 1f0a7169..ce66355b 100644 --- a/x/subaccount/keeper/orderbook_hooks.go +++ b/x/subaccount/keeper/hooks.go @@ -1,6 +1,8 @@ package keeper import ( + "log" + sdk "github.com/cosmos/cosmos-sdk/types" orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" ) @@ -57,7 +59,7 @@ func (k Keeper) AfterBettorRefund(ctx sdk.Context, bettor sdk.AccAddress, origin k.SetBalance(ctx, bettor, balance) } -func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int, fee *sdk.Int) { +func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmount, profit sdk.Int) { // update balance balance, exists := k.GetBalance(ctx, house) if !exists { @@ -68,12 +70,6 @@ func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmo if err != nil { panic(err) } - if fee != nil { - err = balance.Unspend(*fee) - if err != nil { - panic(err) - } - } k.SetBalance(ctx, house, balance) // send profits @@ -85,9 +81,11 @@ func (k Keeper) AfterHouseWin(ctx sdk.Context, house sdk.AccAddress, originalAmo if err != nil { panic(err) } + + log.Printf("AfterHouseWin: HOUSE ADDR %s – originalAmount: %s, profit: %s", house.String(), originalAmount.String(), profit.String()) } -func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int, fee *sdk.Int) { +func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int, lostAmt sdk.Int) { balance, exists := k.GetBalance(ctx, house) if !exists { return @@ -101,17 +99,13 @@ func (k Keeper) AfterHouseLoss(ctx sdk.Context, house sdk.AccAddress, originalAm if err != nil { panic(err) } - if fee != nil { - err = balance.Unspend(*fee) - if err != nil { - panic(err) - } - } k.SetBalance(ctx, house, balance) + + log.Printf("AfterHouseLoss: HOUSE ADDR %s – originalAmount: %s, lostAmt: %s", house.String(), originalAmount.String(), lostAmt.String()) } -func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount, fee sdk.Int) { +func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, originalAmount sdk.Int) { balance, exists := k.GetBalance(ctx, house) if !exists { return @@ -121,10 +115,24 @@ func (k Keeper) AfterHouseRefund(ctx sdk.Context, house sdk.AccAddress, original if err != nil { panic(err) } - err = balance.Unspend(fee) + + k.SetBalance(ctx, house, balance) + + log.Printf("AfterHouseRefund: HOUSE ADDR %s – originalAmount: %s", house.String(), originalAmount.String()) +} + +func (k Keeper) AfterHouseFeeRefund(ctx sdk.Context, house sdk.AccAddress, fee sdk.Int) { + balance, exists := k.GetBalance(ctx, house) + if !exists { + return + } + + err := balance.Unspend(fee) if err != nil { panic(err) } k.SetBalance(ctx, house, balance) + + log.Printf("AfterHouseFeeRefund: HOUSE ADDR %s – fee: %s", house.String(), fee.String()) } diff --git a/x/subaccount/keeper/keeper.go b/x/subaccount/keeper/keeper.go index 1904b78f..bce5af73 100644 --- a/x/subaccount/keeper/keeper.go +++ b/x/subaccount/keeper/keeper.go @@ -5,67 +5,48 @@ import ( sdk "github.com/cosmos/cosmos-sdk/types" paramtypes "github.com/cosmos/cosmos-sdk/x/params/types" bettypes "github.com/sge-network/sge/x/bet/types" - housetypes "github.com/sge-network/sge/x/house/types" - orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" "github.com/sge-network/sge/x/subaccount/types" ) -type BetKeeper interface { - GetBetID(ctx sdk.Context, uid string) (bettypes.UID2ID, bool) - Wager(ctx sdk.Context, bet *bettypes.Bet) error -} - -type BankKeeper interface { - SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error -} - -type HouseKeeper interface { - GetParams(ctx sdk.Context) housetypes.Params - Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdk.Int) (participationIndex uint64, err error) - GetDeposit(ctx sdk.Context, depositorAddr, marketUID string, participationIndex uint64) (housetypes.Deposit, bool) - Withdraw(ctx sdk.Context, deposit housetypes.Deposit, creator, depositorAddr string, marketUID string, participationIndex uint64, mode housetypes.WithdrawalMode, withdrawableAmount sdk.Int) (uint64, error) -} - -type OrderBookKeeper interface { - RegisterHook(hooks orderbookmodulekeeper.Hook) - CalcWithdrawalAmount( - ctx sdk.Context, - depositorAddress string, - marketUID string, - participationIndex uint64, - mode housetypes.WithdrawalMode, - totalWithdrawnAmount sdk.Int, - amount sdk.Int, - ) (sdk.Int, error) -} - type Keeper struct { cdc codec.Codec storeKey sdk.StoreKey paramstore paramtypes.Subspace - bankKeeper BankKeeper - ovmKeeper bettypes.OVMKeeper - betKeeper BetKeeper - houseKeeper HouseKeeper - obKeeper OrderBookKeeper + accountKeeper types.AccountKeeper + bankKeeper types.BankKeeper + ovmKeeper bettypes.OVMKeeper + betKeeper types.BetKeeper + houseKeeper types.HouseKeeper + obKeeper types.OrderBookKeeper } -func NewKeeper(cdc codec.Codec, storeKey sdk.StoreKey, ps paramtypes.Subspace, bankKeeper BankKeeper, ovmKeeper bettypes.OVMKeeper, betKeeper BetKeeper, obKeeper OrderBookKeeper, hk HouseKeeper) Keeper { +func NewKeeper( + cdc codec.Codec, + storeKey sdk.StoreKey, + ps paramtypes.Subspace, + accountKeeper types.AccountKeeper, + bankKeeper types.BankKeeper, + ovmKeeper bettypes.OVMKeeper, + betKeeper types.BetKeeper, + obKeeper types.OrderBookKeeper, + hk types.HouseKeeper, +) *Keeper { // set KeyTable if it is not already set if !ps.HasKeyTable() { ps = ps.WithKeyTable(types.ParamKeyTable()) } - k := Keeper{ - cdc: cdc, - storeKey: storeKey, - paramstore: ps, - bankKeeper: bankKeeper, - ovmKeeper: ovmKeeper, - betKeeper: betKeeper, - houseKeeper: hk, - obKeeper: obKeeper, + k := &Keeper{ + cdc: cdc, + storeKey: storeKey, + paramstore: ps, + accountKeeper: accountKeeper, + bankKeeper: bankKeeper, + ovmKeeper: ovmKeeper, + betKeeper: betKeeper, + houseKeeper: hk, + obKeeper: obKeeper, } obKeeper.RegisterHook(k) return k diff --git a/x/subaccount/keeper/keeper_test.go b/x/subaccount/keeper/keeper_test.go index dd85381a..e74d0dba 100644 --- a/x/subaccount/keeper/keeper_test.go +++ b/x/subaccount/keeper/keeper_test.go @@ -11,7 +11,7 @@ import ( "github.com/stretchr/testify/require" ) -func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, keeper.Keeper, sdk.Context) { +func setupKeeperAndApp(t testing.TB) (*simappUtil.TestApp, *keeper.Keeper, sdk.Context) { tApp, ctx, err := simappUtil.GetTestObjects() require.NoError(t, err) diff --git a/x/subaccount/keeper/msg_server.go b/x/subaccount/keeper/msg_server.go index fb3684d6..48699f9d 100644 --- a/x/subaccount/keeper/msg_server.go +++ b/x/subaccount/keeper/msg_server.go @@ -1,55 +1,19 @@ package keeper import ( - sdk "github.com/cosmos/cosmos-sdk/types" - "github.com/cosmos/cosmos-sdk/types/errors" - "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" "github.com/sge-network/sge/x/subaccount/types" ) type msgServer struct { - keeper Keeper - - accountKeeper keeper.AccountKeeper - bankKeeper bankkeeper.Keeper + keeper *Keeper } // NewMsgServerImpl returns an implementation of the MsgServer interface // for the provided Keeper. -func NewMsgServerImpl(keeper Keeper, accountKeeper keeper.AccountKeeper, bankKeeper bankkeeper.Keeper) types.MsgServer { +func NewMsgServerImpl(keeper *Keeper) types.MsgServer { return &msgServer{ - keeper: keeper, - accountKeeper: accountKeeper, - bankKeeper: bankKeeper, + keeper: keeper, } } var _ types.MsgServer = msgServer{} - -// sumBalanceUnlocks sums all the balances to unlock and returns the total amount. It -// returns an error if any of the unlock times is expired. -func sumBalanceUnlocks(ctx sdk.Context, balanceUnlocks []*types.LockedBalance) (sdk.Int, error) { - moneyToSend := sdk.NewInt(0) - - for _, balanceUnlock := range balanceUnlocks { - if balanceUnlock.UnlockTime.Unix() < ctx.BlockTime().Unix() { - return sdk.Int{}, types.ErrUnlockTokenTimeExpired - } - - moneyToSend = moneyToSend.Add(balanceUnlock.Amount) - } - - return moneyToSend, nil -} - -// sendCoinsToSubaccount sends the coins to the subaccount. -func (m msgServer) sendCoinsToSubaccount(ctx sdk.Context, senderAccount sdk.AccAddress, subAccountAddress sdk.AccAddress, moneyToSend sdk.Int) error { - denom := m.keeper.GetParams(ctx).LockedBalanceDenom - err := m.bankKeeper.SendCoins(ctx, senderAccount, subAccountAddress, sdk.NewCoins(sdk.NewCoin(denom, moneyToSend))) - if err != nil { - return errors.Wrap(err, "unable to send coins") - } - - return nil -} diff --git a/x/subaccount/keeper/msg_server_bet_test.go b/x/subaccount/keeper/msg_server_bet_test.go index 8e4440b1..9c7462b1 100644 --- a/x/subaccount/keeper/msg_server_bet_test.go +++ b/x/subaccount/keeper/msg_server_bet_test.go @@ -62,7 +62,7 @@ func TestMsgServer_Bet(t *testing.T) { _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ Sender: subAccFunder.String(), SubAccountOwner: subAccOwner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: time.Now().Add(24 * time.Hour), Amount: subAccFunds, diff --git a/x/subaccount/keeper/create_subaccount.go b/x/subaccount/keeper/msg_server_create_subaccount.go similarity index 85% rename from x/subaccount/keeper/create_subaccount.go rename to x/subaccount/keeper/msg_server_create_subaccount.go index 03656376..d3b95cd2 100644 --- a/x/subaccount/keeper/create_subaccount.go +++ b/x/subaccount/keeper/msg_server_create_subaccount.go @@ -33,10 +33,10 @@ func (m msgServer) CreateSubAccount( // ALERT: If someone frontruns the account creation, will be overwritten here subaccountAddress := types.NewAddressFromSubaccount(subaccountID) - subaccountAccount := m.accountKeeper.NewAccountWithAddress(sdkContext, subaccountAddress) - m.accountKeeper.SetAccount(sdkContext, subaccountAccount) + subaccountAccount := m.keeper.accountKeeper.NewAccountWithAddress(sdkContext, subaccountAddress) + m.keeper.accountKeeper.SetAccount(sdkContext, subaccountAccount) - err = m.sendCoinsToSubaccount(sdkContext, senderAccount, subaccountAddress, moneyToSend) + err = m.keeper.sendCoinsToSubaccount(sdkContext, senderAccount, subaccountAddress, moneyToSend) if err != nil { return nil, errors.Wrap(err, "unable to send coins") } diff --git a/x/subaccount/keeper/create_subaccount_test.go b/x/subaccount/keeper/msg_server_create_subaccount_test.go similarity index 90% rename from x/subaccount/keeper/create_subaccount_test.go rename to x/subaccount/keeper/msg_server_create_subaccount_test.go index 555ec1d8..5b29e1d0 100644 --- a/x/subaccount/keeper/create_subaccount_test.go +++ b/x/subaccount/keeper/msg_server_create_subaccount_test.go @@ -29,7 +29,7 @@ func TestMsgServer_CreateSubAccount(t *testing.T) { msg := &types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: account.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: someTime, Amount: sdk.NewInt(123), @@ -76,7 +76,7 @@ func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { tests := []struct { name string msg types.MsgCreateSubAccount - prepare func(ctx sdk.Context, keeper keeper.Keeper) + prepare func(ctx sdk.Context, keeper *keeper.Keeper) expectedErr string }{ { @@ -84,14 +84,14 @@ func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: account.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: beforeTime, Amount: sdk.NewInt(123), }, }, }, - prepare: func(ctx sdk.Context, k keeper.Keeper) {}, + prepare: func(ctx sdk.Context, k *keeper.Keeper) {}, expectedErr: types.ErrUnlockTokenTimeExpired.Error(), }, { @@ -99,14 +99,14 @@ func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: account.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: afterTime, Amount: sdk.NewInt(123), }, }, }, - prepare: func(ctx sdk.Context, k keeper.Keeper) { + prepare: func(ctx sdk.Context, k *keeper.Keeper) { k.SetSubAccountOwner(ctx, types.NewAddressFromSubaccount(1), account) }, expectedErr: types.ErrSubaccountAlreadyExist.Error(), @@ -116,14 +116,14 @@ func TestMsgServer_CreateSubAccount_Errors(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: account.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: afterTime, Amount: sdk.Int{}, }, }, }, - prepare: func(ctx sdk.Context, k keeper.Keeper) {}, + prepare: func(ctx sdk.Context, k *keeper.Keeper) {}, expectedErr: "invalid request", }, } diff --git a/x/subaccount/keeper/msg_server_house_test.go b/x/subaccount/keeper/msg_server_house_test.go index 04b20e62..cfc5ccbc 100644 --- a/x/subaccount/keeper/msg_server_house_test.go +++ b/x/subaccount/keeper/msg_server_house_test.go @@ -39,7 +39,7 @@ func TestMsgServer(t *testing.T) { _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ Sender: subAccFunder.String(), SubAccountOwner: subAccOwner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: time.Now().Add(24 * time.Hour), Amount: subAccFunds, @@ -165,6 +165,121 @@ func TestMsgServer(t *testing.T) { require.Equal(t, subBalance.SpentAmount.String(), sdk.NewInt(131999680).String()) // NOTE: there was a match in the bet + participate fee require.Equal(t, subBalance.LostAmount.String(), sdk.ZeroInt().String()) }) + + t.Run("withdrawal and market refund with bet fulfillment", func(t *testing.T) { + ctx, _ := ctx.CacheContext() + + _, err := msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err = app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + // check profits were forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) + }) +} + +func TestHouseWithdrawal_MarketRefund(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + + // do subaccount creation + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ + Sender: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTime: time.Now().Add(24 * time.Hour), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + // fund a bettor + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + bettor1, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + // add market + market := addTestMarket(t, app, ctx, false) + + // do house deposit + deposit := sdk.NewInt(1000).Mul(micro) + depResp, err := msgServer.HouseDeposit(sdk.WrapSDKContext(ctx), houseDepositMsg(t, subAccOwner, market.UID, deposit)) + require.NoError(t, err) + // check spend + subBalance, exists := k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, deposit) + + // do house withdrawal + _, err = msgServer.HouseWithdraw(sdk.WrapSDKContext(ctx), &types.MsgHouseWithdraw{Msg: houseWithdrawMsg(t, subAccOwner, deposit, depResp.Response.ParticipationIndex)}) + require.NoError(t, err) + + // we expect the balance to be the original one minus participation fee + subBalance, exists = k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.Equal(t, subBalance.SpentAmount, sdk.NewInt(100).Mul(micro)) // all minus participation fee + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.DepositedAmount, subAccFunds) + subBankBalance := app.BankKeeper.GetAllBalances(ctx, subAccAddr) + require.Equal(t, subBankBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), subAccFunds.Sub(sdk.NewInt(100).Mul(micro))) // original funds - fee + + // resolve market with refund + app.MarketKeeper.Resolve(ctx, *market, &markettypes.MarketResolutionTicketPayload{ + UID: market.UID, + ResolutionTS: uint64(ctx.BlockTime().Unix()) + 10000, + WinnerOddsUIDs: []string{testOddsUID1}, + Status: markettypes.MarketStatus_MARKET_STATUS_CANCELED, + }) + err = app.BetKeeper.BatchMarketSettlements(ctx) + require.NoError(t, err) + err = app.OrderbookKeeper.BatchOrderBookSettlements(ctx) + require.NoError(t, err) + + subBalance, exists = k.GetBalance(ctx, subAccAddr) + require.True(t, exists) + require.NoError(t, err) + + require.Equal(t, subBalance.SpentAmount, sdk.ZeroInt()) + require.Equal(t, subBalance.LostAmount, sdk.ZeroInt()) + subBankBalance = app.BankKeeper.GetAllBalances(ctx, subAccAddr) + require.Equal(t, subBankBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), subAccFunds) // original funds - fee was refunded + // check profits were not forwarded to subacc owner + ownerBalance := app.BankKeeper.GetAllBalances(ctx, subAccOwner) + require.Equal(t, ownerBalance.AmountOf(k.GetParams(ctx).LockedBalanceDenom), sdk.ZeroInt()) } func houseWithdrawMsg(t testing.TB, owner sdk.AccAddress, amt sdk.Int, partecipationIndex uint64) *housetypes.MsgWithdraw { diff --git a/x/subaccount/keeper/msg_server_test.go b/x/subaccount/keeper/msg_server_test.go index 951e1f3b..f2214dab 100644 --- a/x/subaccount/keeper/msg_server_test.go +++ b/x/subaccount/keeper/msg_server_test.go @@ -12,7 +12,7 @@ import ( func setupMsgServerAndApp( t testing.TB, -) (*simappUtil.TestApp, keeper.Keeper, types.MsgServer, sdk.Context) { +) (*simappUtil.TestApp, *keeper.Keeper, types.MsgServer, sdk.Context) { tApp, k, ctx := setupKeeperAndApp(t) - return tApp, k, keeper.NewMsgServerImpl(k, tApp.AccountKeeper, tApp.BankKeeper), ctx + return tApp, k, keeper.NewMsgServerImpl(k), ctx } diff --git a/x/subaccount/keeper/topup.go b/x/subaccount/keeper/msg_server_topup.go similarity index 92% rename from x/subaccount/keeper/topup.go rename to x/subaccount/keeper/msg_server_topup.go index 065e0595..df52b837 100644 --- a/x/subaccount/keeper/topup.go +++ b/x/subaccount/keeper/msg_server_topup.go @@ -32,7 +32,7 @@ func (m msgServer) TopUp(ctx context.Context, msg *types.MsgTopUp) (*types.MsgTo m.keeper.SetBalance(sdkContext, subAccAddress, balance) m.keeper.SetLockedBalances(sdkContext, subAccAddress, msg.LockedBalances) - err = m.sendCoinsToSubaccount(sdkContext, sender, subAccAddress, moneyToAdd) + err = m.keeper.sendCoinsToSubaccount(sdkContext, sender, subAccAddress, moneyToAdd) if err != nil { return nil, fmt.Errorf("unable to send coins: %w", err) } diff --git a/x/subaccount/keeper/topup_test.go b/x/subaccount/keeper/msg_server_topup_test.go similarity index 93% rename from x/subaccount/keeper/topup_test.go rename to x/subaccount/keeper/msg_server_topup_test.go index c0261042..8e04709f 100644 --- a/x/subaccount/keeper/topup_test.go +++ b/x/subaccount/keeper/msg_server_topup_test.go @@ -27,7 +27,7 @@ func TestMsgServerTopUp_HappyPath(t *testing.T) { msg := &types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: subaccount, - LockedBalances: []*types.LockedBalance{}, + LockedBalances: []types.LockedBalance{}, } _, err = msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) @@ -43,7 +43,7 @@ func TestMsgServerTopUp_HappyPath(t *testing.T) { msgTopUp := &types.MsgTopUp{ Sender: sender.String(), SubAccount: subaccount, - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: afterTime, Amount: sdk.NewInt(123), @@ -81,7 +81,7 @@ func TestNewMsgServerTopUp_Errors(t *testing.T) { msg: types.MsgTopUp{ Sender: sender, SubAccount: subaccount, - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: beforeTime, Amount: sdk.NewInt(123), @@ -96,7 +96,7 @@ func TestNewMsgServerTopUp_Errors(t *testing.T) { msg: types.MsgTopUp{ Sender: sender, SubAccount: subaccount, - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: afterTime, Amount: sdk.NewInt(123), @@ -111,7 +111,7 @@ func TestNewMsgServerTopUp_Errors(t *testing.T) { msg: types.MsgTopUp{ Sender: sender, SubAccount: subaccount, - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: afterTime, Amount: sdk.NewInt(123), @@ -123,7 +123,7 @@ func TestNewMsgServerTopUp_Errors(t *testing.T) { msg := &types.MsgCreateSubAccount{ Sender: sender, SubAccountOwner: subaccount, - LockedBalances: []*types.LockedBalance{}, + LockedBalances: []types.LockedBalance{}, } _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), msg) require.NoError(t, err) diff --git a/x/subaccount/keeper/withdraw.go b/x/subaccount/keeper/msg_server_withdraw.go similarity index 60% rename from x/subaccount/keeper/withdraw.go rename to x/subaccount/keeper/msg_server_withdraw.go index 59fc8379..a02f6460 100644 --- a/x/subaccount/keeper/withdraw.go +++ b/x/subaccount/keeper/msg_server_withdraw.go @@ -18,7 +18,7 @@ func (m msgServer) WithdrawUnlockedBalances(ctx context.Context, balances *types params := m.keeper.GetParams(sdkContext) - balance, unlockedBalance, bankBalance := m.getBalances(sdkContext, subAccountAddress, params) + balance, unlockedBalance, bankBalance := m.keeper.getBalances(sdkContext, subAccountAddress, params) // calculate withdrawable balance, which is the minimum between the available balance, and // what has been unlocked so far. Also, it cannot be greater than the bank balance. @@ -31,22 +31,10 @@ func (m msgServer) WithdrawUnlockedBalances(ctx context.Context, balances *types balance.WithdrawmAmount = balance.WithdrawmAmount.Add(withdrawableBalance) m.keeper.SetBalance(sdkContext, subAccountAddress, balance) - err := m.bankKeeper.SendCoins(sdkContext, subAccountAddress, sender, sdk.NewCoins(sdk.NewCoin(params.LockedBalanceDenom, withdrawableBalance))) + err := m.keeper.bankKeeper.SendCoins(sdkContext, subAccountAddress, sender, sdk.NewCoins(sdk.NewCoin(params.LockedBalanceDenom, withdrawableBalance))) if err != nil { return nil, err } return &types.MsgWithdrawUnlockedBalancesResponse{}, nil } - -// getBalances returns the balance, unlocked balance and bank balance of a subaccount -func (m msgServer) getBalances(sdkContext sdk.Context, subaccountAddr sdk.AccAddress, params types.Params) (types.Balance, sdk.Int, sdk.Coin) { - balance, exists := m.keeper.GetBalance(sdkContext, subaccountAddr) - if !exists { - panic("data corruption: subaccount exists but balance does not") - } - unlockedBalance := m.keeper.GetUnlockedBalance(sdkContext, subaccountAddr) - bankBalance := m.bankKeeper.GetBalance(sdkContext, subaccountAddr, params.LockedBalanceDenom) - - return balance, unlockedBalance, bankBalance -} diff --git a/x/subaccount/keeper/withdraw_test.go b/x/subaccount/keeper/msg_server_withdraw_test.go similarity index 98% rename from x/subaccount/keeper/withdraw_test.go rename to x/subaccount/keeper/msg_server_withdraw_test.go index 50734aa8..db9c4e9c 100644 --- a/x/subaccount/keeper/withdraw_test.go +++ b/x/subaccount/keeper/msg_server_withdraw_test.go @@ -28,7 +28,7 @@ func TestMsgServer_WithdrawUnlockedBalances(t *testing.T) { _, err = msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: subaccountOwner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { Amount: sdk.NewInt(100), UnlockTime: lockedTime, @@ -147,7 +147,7 @@ func TestMsgServer_WithdrawUnlockedBalances_Errors(t *testing.T) { t.Run(tt.name, func(t *testing.T) { _, k, msgServer, ctx := setupMsgServerAndApp(t) - tt.prepare(ctx, k) + tt.prepare(ctx, *k) _, err := msgServer.WithdrawUnlockedBalances(sdk.WrapSDKContext(ctx), &tt.msg) require.ErrorContains(t, err, tt.expectedErr) diff --git a/x/subaccount/keeper/query_server.go b/x/subaccount/keeper/query_server.go new file mode 100644 index 00000000..5d427c62 --- /dev/null +++ b/x/subaccount/keeper/query_server.go @@ -0,0 +1,46 @@ +package keeper + +import ( + "context" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/subaccount/types" +) + +func NewQueryServer(keeper Keeper) types.QueryServer { + return queryServer{keeper: keeper} +} + +type queryServer struct { + keeper Keeper +} + +func (q queryServer) Subaccount(goCtx context.Context, request *types.QuerySubaccountRequest) (*types.QuerySubaccountResponse, error) { + addr, err := sdk.AccAddressFromBech32(request.SubaccountOwner) + if err != nil { + return nil, err + } + + ctx := sdk.UnwrapSDKContext(goCtx) + subaccountAddr, exists := q.keeper.GetSubAccountByOwner(ctx, addr) + if !exists { + return nil, types.ErrSubaccountDoesNotExist + } + + balance, exists := q.keeper.GetBalance(ctx, subaccountAddr) + if !exists { + panic("subaccount exists but balance not found") + } + + balanceLocks := q.keeper.GetLockedBalances(ctx, subaccountAddr) + return &types.QuerySubaccountResponse{ + SubaccountAddress: subaccountAddr.String(), + Balance: balance, + LockedBalance: balanceLocks, + }, nil +} + +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 +} diff --git a/x/subaccount/keeper/query_server_test.go b/x/subaccount/keeper/query_server_test.go new file mode 100644 index 00000000..f8523897 --- /dev/null +++ b/x/subaccount/keeper/query_server_test.go @@ -0,0 +1,66 @@ +package keeper_test + +import ( + "testing" + "time" + + "github.com/cosmos/cosmos-sdk/simapp" + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/sge-network/sge/x/subaccount/keeper" + "github.com/sge-network/sge/x/subaccount/types" + "github.com/stretchr/testify/require" +) + +func TestQueryServer(t *testing.T) { + app, k, msgServer, ctx := setupMsgServerAndApp(t) + queryServer := keeper.NewQueryServer(*k) + + // setup + wantParams := types.DefaultParams() + k.SetParams(ctx, wantParams) + + // do subaccount creation + require.NoError( + t, + simapp.FundAccount( + app.BankKeeper, + ctx, + subAccFunder, + sdk.NewCoins(sdk.NewCoin(k.GetParams(ctx).LockedBalanceDenom, subAccFunds)), + ), + ) + + _, err := msgServer.CreateSubAccount(sdk.WrapSDKContext(ctx), &types.MsgCreateSubAccount{ + Sender: subAccFunder.String(), + SubAccountOwner: subAccOwner.String(), + LockedBalances: []types.LockedBalance{ + { + UnlockTime: time.Now().Add(24 * time.Hour), + Amount: subAccFunds, + }, + }, + }) + require.NoError(t, err) + + 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) + }) + + t.Run("Subaccount", func(t *testing.T) { + gotSubaccount, err := queryServer.Subaccount(sdk.WrapSDKContext(ctx), &types.QuerySubaccountRequest{ + SubaccountOwner: subAccOwner.String(), + }) + require.NoError(t, err) + require.Equal(t, subAccAddr.String(), gotSubaccount.SubaccountAddress) + require.Equal(t, types.Balance{ + DepositedAmount: subAccFunds, + SpentAmount: sdk.ZeroInt(), + WithdrawmAmount: sdk.ZeroInt(), + LostAmount: sdk.ZeroInt(), + }, gotSubaccount.Balance) + require.Len(t, gotSubaccount.LockedBalance, 1) + require.Equal(t, subAccFunds, gotSubaccount.LockedBalance[0].Amount) + }) +} diff --git a/x/subaccount/keeper/subaccount.go b/x/subaccount/keeper/subaccount.go index a3b44d04..b67aea88 100644 --- a/x/subaccount/keeper/subaccount.go +++ b/x/subaccount/keeper/subaccount.go @@ -1,14 +1,14 @@ package keeper import ( - "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - subaccounttypes "github.com/sge-network/sge/x/subaccount/types" + "github.com/cosmos/cosmos-sdk/types/errors" + "github.com/sge-network/sge/x/subaccount/types" ) // Peek returns the next value without advancing the subaccount ID. func (k Keeper) Peek(ctx sdk.Context) uint64 { - key := ctx.KVStore(k.storeKey).Get(subaccounttypes.SubaccountIDPrefix) + key := ctx.KVStore(k.storeKey).Get(types.SubaccountIDPrefix) if key == nil { return 1 } @@ -20,118 +20,92 @@ func (k Keeper) Peek(ctx sdk.Context) uint64 { func (k Keeper) NextID(ctx sdk.Context) uint64 { actualID := k.Peek(ctx) - ctx.KVStore(k.storeKey).Set(subaccounttypes.SubaccountIDPrefix, sdk.Uint64ToBigEndian(actualID+1)) + ctx.KVStore(k.storeKey).Set(types.SubaccountIDPrefix, sdk.Uint64ToBigEndian(actualID+1)) return actualID } // SetID sets the ID to a given value. func (k Keeper) SetID(ctx sdk.Context, id uint64) { - ctx.KVStore(k.storeKey).Set(subaccounttypes.SubaccountIDPrefix, sdk.Uint64ToBigEndian(id)) + ctx.KVStore(k.storeKey).Set(types.SubaccountIDPrefix, sdk.Uint64ToBigEndian(id)) } // SetSubAccountOwner sets the owner of a subaccount. func (k Keeper) SetSubAccountOwner(ctx sdk.Context, subAccountAddress, ownerAddress sdk.AccAddress) { store := ctx.KVStore(k.storeKey) - store.Set(subaccounttypes.SubAccountOwnerKey(ownerAddress), subAccountAddress) + store.Set(types.SubAccountOwnerKey(ownerAddress), subAccountAddress) // and reverse mapping - store.Set(subaccounttypes.SubAccountKey(subAccountAddress), ownerAddress) + store.Set(types.SubAccountKey(subAccountAddress), ownerAddress) } // GetSubAccountByOwner returns the subaccount ID of an owner. func (k Keeper) GetSubAccountByOwner(ctx sdk.Context, address sdk.AccAddress) (sdk.AccAddress, bool) { store := ctx.KVStore(k.storeKey) - addr := store.Get(subaccounttypes.SubAccountOwnerKey(address)) + addr := store.Get(types.SubAccountOwnerKey(address)) return addr, addr != nil } -// GetSubAccountOwner returns the owner of a subaccount. -func (k Keeper) GetSubAccountOwner(ctx sdk.Context, subAccountOwner sdk.AccAddress) (sdk.AccAddress, bool) { +// GetSubAccountOwner returns the owner of a subaccount given the subaccount address. +func (k Keeper) GetSubAccountOwner(ctx sdk.Context, subaccountAddr sdk.AccAddress) (sdk.AccAddress, bool) { store := ctx.KVStore(k.storeKey) - addr := store.Get(subaccounttypes.SubAccountKey(subAccountOwner)) + addr := store.Get(types.SubAccountKey(subaccountAddr)) return addr, addr != nil } -// SetLockedBalances saves the locked balances of an account. -func (k Keeper) SetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress, lockedBalances []*subaccounttypes.LockedBalance) { +func (k Keeper) IterateSubaccounts(ctx sdk.Context, cb func(subAccountAddress, subaccountOwner sdk.AccAddress) (stop bool)) { store := ctx.KVStore(k.storeKey) - - for _, lockedBalance := range lockedBalances { - amountBytes, err := lockedBalance.Amount.Marshal() - if err != nil { - panic(err) - } - store.Set( - subaccounttypes.LockedBalanceKey(subAccountAddress, lockedBalance.UnlockTime), - amountBytes, - ) - } -} - -// GetLockedBalances returns the locked balances of an account. -func (k Keeper) GetLockedBalances(ctx sdk.Context, subAccountAddress sdk.AccAddress) []subaccounttypes.LockedBalance { - iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(subAccountAddress)).Iterator(nil, nil) + iterator := sdk.KVStorePrefixIterator(store, types.SubAccountOwnerReversePrefix) defer iterator.Close() - var lockedBalances []subaccounttypes.LockedBalance for ; iterator.Valid(); iterator.Next() { - unlockTime, err := sdk.ParseTimeBytes(iterator.Key()) - if err != nil { - panic(err) + if cb(iterator.Key()[len(types.SubAccountOwnerReversePrefix):], iterator.Value()) { + break } + } +} - amount := new(sdk.Int) - err = amount.Unmarshal(iterator.Value()) - if err != nil { - panic(err) +func (k Keeper) GetAllSubaccounts(ctx sdk.Context) []types.GenesisSubaccount { + var subaccounts []types.GenesisSubaccount + k.IterateSubaccounts(ctx, func(subAccountAddress sdk.AccAddress, ownerAddress sdk.AccAddress) (stop bool) { + balance, exists := k.GetBalance(ctx, subAccountAddress) + if !exists { + panic("subaccount balance does not exist") } - lockedBalances = append(lockedBalances, subaccounttypes.LockedBalance{ - UnlockTime: unlockTime, - Amount: *amount, + lockedBalances := k.GetLockedBalances(ctx, subAccountAddress) + subaccounts = append(subaccounts, types.GenesisSubaccount{ + Address: subAccountAddress.String(), + Owner: ownerAddress.String(), + Balance: balance, + LockedBalances: lockedBalances, }) - } - - return lockedBalances + return false + }) + return subaccounts } -// GetUnlockedBalance returns the unlocked balance of an account. -func (k Keeper) GetUnlockedBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) sdk.Int { - iterator := prefix.NewStore(ctx.KVStore(k.storeKey), subaccounttypes.LockedBalancePrefixKey(subAccountAddress)). - Iterator(nil, sdk.FormatTimeBytes(ctx.BlockTime())) - - unlockedBalance := sdk.ZeroInt() - defer iterator.Close() - - for ; iterator.Valid(); iterator.Next() { - amount := new(sdk.Int) - err := amount.Unmarshal(iterator.Value()) - if err != nil { - panic(err) - } - unlockedBalance = unlockedBalance.Add(*amount) +// sendCoinsToSubaccount sends the coins to the subaccount. +func (k Keeper) sendCoinsToSubaccount(ctx sdk.Context, senderAccount sdk.AccAddress, subAccountAddress sdk.AccAddress, moneyToSend sdk.Int) error { + denom := k.GetParams(ctx).LockedBalanceDenom + err := k.bankKeeper.SendCoins(ctx, senderAccount, subAccountAddress, sdk.NewCoins(sdk.NewCoin(denom, moneyToSend))) + if err != nil { + return errors.Wrap(err, "unable to send coins") } - return unlockedBalance + return nil } -// SetBalance saves the balance of an account. -func (k Keeper) SetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress, balance subaccounttypes.Balance) { - store := ctx.KVStore(k.storeKey) +// sumBalanceUnlocks sums all the balances to unlock and returns the total amount. It +// returns an error if any of the unlock times is expired. +func sumBalanceUnlocks(ctx sdk.Context, balanceUnlocks []types.LockedBalance) (sdk.Int, error) { + moneyToSend := sdk.NewInt(0) - bz := k.cdc.MustMarshal(&balance) - store.Set(subaccounttypes.BalanceKey(subAccountAddress), bz) -} + for _, balanceUnlock := range balanceUnlocks { + if balanceUnlock.UnlockTime.Unix() < ctx.BlockTime().Unix() { + return sdk.Int{}, types.ErrUnlockTokenTimeExpired + } -// GetBalance returns the balance of an account. -func (k Keeper) GetBalance(ctx sdk.Context, subAccountAddress sdk.AccAddress) (subaccounttypes.Balance, bool) { - store := ctx.KVStore(k.storeKey) - bz := store.Get(subaccounttypes.BalanceKey(subAccountAddress)) - if bz == nil { - return subaccounttypes.Balance{}, false + moneyToSend = moneyToSend.Add(balanceUnlock.Amount) } - balance := subaccounttypes.Balance{} - k.cdc.MustUnmarshal(bz, &balance) - - return balance, true + return moneyToSend, nil } diff --git a/x/subaccount/keeper/subaccount_test.go b/x/subaccount/keeper/subaccount_test.go index 35b8329e..0b0858f8 100644 --- a/x/subaccount/keeper/subaccount_test.go +++ b/x/subaccount/keeper/subaccount_test.go @@ -64,7 +64,7 @@ func TestSetLockedBalances(t *testing.T) { someUnlockTime := time.Now().Add(time.Hour * 24 * 365) otherUnlockTime := time.Now().Add(time.Hour * 24 * 365 * 2) - balanceUnlocks := []*types.LockedBalance{ + balanceUnlocks := []types.LockedBalance{ { Amount: sdk.NewInt(10000), UnlockTime: someUnlockTime, @@ -116,7 +116,7 @@ func TestKeeper_GetLockedBalances(t *testing.T) { afterUnlockTime2 := time.Now().Add(time.Hour * 24 * 365 * 2) // I added them unordered to make sure they are sorted - balanceUnlocks := []*types.LockedBalance{ + balanceUnlocks := []types.LockedBalance{ { Amount: sdk.NewInt(10000), UnlockTime: beforeUnlockTime1, diff --git a/x/subaccount/module.go b/x/subaccount/module.go index 1a7ea677..4a0adaa5 100644 --- a/x/subaccount/module.go +++ b/x/subaccount/module.go @@ -4,9 +4,6 @@ import ( "encoding/json" "fmt" - authkeeper "github.com/cosmos/cosmos-sdk/x/auth/keeper" - bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper" - "github.com/cosmos/cosmos-sdk/client" "github.com/cosmos/cosmos-sdk/codec" cdctypes "github.com/cosmos/cosmos-sdk/codec/types" @@ -83,9 +80,7 @@ func (AppModuleBasic) GetQueryCmd() *cobra.Command { return cli.GetQueryCmd() } type AppModule struct { AppModuleBasic - keeper keeper.Keeper - accountKeeper authkeeper.AccountKeeper - bankKeeper bankkeeper.Keeper + keeper keeper.Keeper } // NewAppModule creates new app module object @@ -101,7 +96,7 @@ func (am AppModule) Name() string { return am.AppModuleBasic.Name() } // Route returns the module's message routing key. func (am AppModule) Route() sdk.Route { - return sdk.NewRoute(types.RouterKey, NewHandler(am.keeper, am.accountKeeper, am.bankKeeper)) + return sdk.NewRoute(types.RouterKey, NewHandler()) } // QuerierRoute returns the module's query routing key. @@ -113,8 +108,8 @@ func (AppModule) LegacyQuerierHandler(*codec.LegacyAmino) sdk.Querier { return n // RegisterServices registers a GRPC query service to respond to the // module-specific GRPC queries. func (am AppModule) RegisterServices(cfg module.Configurator) { - types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(am.keeper, am.accountKeeper, am.bankKeeper)) - types.RegisterQueryServer(cfg.QueryServer(), am.keeper) + types.RegisterMsgServer(cfg.MsgServer(), keeper.NewMsgServerImpl(&am.keeper)) + types.RegisterQueryServer(cfg.QueryServer(), keeper.NewQueryServer(am.keeper)) } // RegisterInvariants registers the module's invariants. diff --git a/x/subaccount/types/expected_keepers.go b/x/subaccount/types/expected_keepers.go new file mode 100644 index 00000000..676060b4 --- /dev/null +++ b/x/subaccount/types/expected_keepers.go @@ -0,0 +1,44 @@ +package types + +import ( + sdk "github.com/cosmos/cosmos-sdk/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" + bettypes "github.com/sge-network/sge/x/bet/types" + housetypes "github.com/sge-network/sge/x/house/types" + orderbookmodulekeeper "github.com/sge-network/sge/x/orderbook/keeper" +) + +type BetKeeper interface { + GetBetID(ctx sdk.Context, uid string) (bettypes.UID2ID, bool) + Wager(ctx sdk.Context, bet *bettypes.Bet) error +} + +type AccountKeeper interface { + NewAccountWithAddress(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI + SetAccount(ctx sdk.Context, acc authtypes.AccountI) +} + +type BankKeeper interface { + SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error + GetBalance(ctx sdk.Context, addr sdk.AccAddress, denom string) sdk.Coin +} + +type HouseKeeper interface { + GetParams(ctx sdk.Context) housetypes.Params + Deposit(ctx sdk.Context, creator, depositor, marketUID string, amount sdk.Int) (participationIndex uint64, err error) + GetDeposit(ctx sdk.Context, depositorAddr, marketUID string, participationIndex uint64) (housetypes.Deposit, bool) + Withdraw(ctx sdk.Context, deposit housetypes.Deposit, creator, depositorAddr string, marketUID string, participationIndex uint64, mode housetypes.WithdrawalMode, withdrawableAmount sdk.Int) (uint64, error) +} + +type OrderBookKeeper interface { + RegisterHook(hooks orderbookmodulekeeper.Hook) + CalcWithdrawalAmount( + ctx sdk.Context, + depositorAddress string, + marketUID string, + participationIndex uint64, + mode housetypes.WithdrawalMode, + totalWithdrawnAmount sdk.Int, + amount sdk.Int, + ) (sdk.Int, error) +} diff --git a/x/subaccount/types/genesis.pb.go b/x/subaccount/types/genesis.pb.go index e61b6d7e..efa6c9ab 100644 --- a/x/subaccount/types/genesis.pb.go +++ b/x/subaccount/types/genesis.pb.go @@ -26,7 +26,10 @@ const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package // GenesisState defines the subaccount module's genesis state. type GenesisState struct { // params contains the subaccount parameters. - Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + Params Params `protobuf:"bytes,1,opt,name=params,proto3" json:"params"` + SubaccountId uint64 `protobuf:"varint,2,opt,name=subaccount_id,json=subaccountId,proto3" json:"subaccount_id,omitempty"` + // subaccounts contains all the subaccounts. + Subaccounts []GenesisSubaccount `protobuf:"bytes,3,rep,name=subaccounts,proto3" json:"subaccounts"` } func (m *GenesisState) Reset() { *m = GenesisState{} } @@ -69,27 +72,123 @@ func (m *GenesisState) GetParams() Params { return Params{} } +func (m *GenesisState) GetSubaccountId() uint64 { + if m != nil { + return m.SubaccountId + } + return 0 +} + +func (m *GenesisState) GetSubaccounts() []GenesisSubaccount { + if m != nil { + return m.Subaccounts + } + return nil +} + +type GenesisSubaccount struct { + // address is the address of the subaccount. + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + // owner is the owner of the subaccount. + Owner string `protobuf:"bytes,2,opt,name=owner,proto3" json:"owner,omitempty"` + // balance defines the balance status of a subaccount + Balance Balance `protobuf:"bytes,3,opt,name=balance,proto3" json:"balance"` + // locked_balances defines the lockup of balances history of a subaccount + LockedBalances []LockedBalance `protobuf:"bytes,4,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` +} + +func (m *GenesisSubaccount) Reset() { *m = GenesisSubaccount{} } +func (m *GenesisSubaccount) String() string { return proto.CompactTextString(m) } +func (*GenesisSubaccount) ProtoMessage() {} +func (*GenesisSubaccount) Descriptor() ([]byte, []int) { + return fileDescriptor_021997686c533a34, []int{1} +} +func (m *GenesisSubaccount) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *GenesisSubaccount) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_GenesisSubaccount.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *GenesisSubaccount) XXX_Merge(src proto.Message) { + xxx_messageInfo_GenesisSubaccount.Merge(m, src) +} +func (m *GenesisSubaccount) XXX_Size() int { + return m.Size() +} +func (m *GenesisSubaccount) XXX_DiscardUnknown() { + xxx_messageInfo_GenesisSubaccount.DiscardUnknown(m) +} + +var xxx_messageInfo_GenesisSubaccount proto.InternalMessageInfo + +func (m *GenesisSubaccount) GetAddress() string { + if m != nil { + return m.Address + } + return "" +} + +func (m *GenesisSubaccount) GetOwner() string { + if m != nil { + return m.Owner + } + return "" +} + +func (m *GenesisSubaccount) GetBalance() Balance { + if m != nil { + return m.Balance + } + return Balance{} +} + +func (m *GenesisSubaccount) GetLockedBalances() []LockedBalance { + if m != nil { + return m.LockedBalances + } + return nil +} + func init() { proto.RegisterType((*GenesisState)(nil), "sgenetwork.sge.subaccount.GenesisState") + proto.RegisterType((*GenesisSubaccount)(nil), "sgenetwork.sge.subaccount.GenesisSubaccount") } func init() { proto.RegisterFile("sge/subaccount/genesis.proto", fileDescriptor_021997686c533a34) } var fileDescriptor_021997686c533a34 = []byte{ - // 201 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x92, 0x29, 0x4e, 0x4f, 0xd5, - 0x2f, 0x2e, 0x4d, 0x4a, 0x4c, 0x4e, 0xce, 0x2f, 0xcd, 0x2b, 0xd1, 0x4f, 0x4f, 0xcd, 0x4b, 0x2d, - 0xce, 0x2c, 0xd6, 0x2b, 0x28, 0xca, 0x2f, 0xc9, 0x17, 0x92, 0x2c, 0x06, 0xf1, 0x4b, 0xca, 0xf3, - 0x8b, 0xb2, 0xf5, 0x8a, 0xd3, 0x53, 0xf5, 0x10, 0x0a, 0xa5, 0x44, 0xd2, 0xf3, 0xd3, 0xf3, 0xc1, - 0xaa, 0xf4, 0x41, 0x2c, 0x88, 0x06, 0x29, 0x69, 0x34, 0xe3, 0x0a, 0x12, 0x8b, 0x12, 0x73, 0xa1, - 0xa6, 0x29, 0xf9, 0x73, 0xf1, 0xb8, 0x43, 0x8c, 0x0f, 0x2e, 0x49, 0x2c, 0x49, 0x15, 0xb2, 0xe7, - 0x62, 0x83, 0xc8, 0x4b, 0x30, 0x2a, 0x30, 0x6a, 0x70, 0x1b, 0x29, 0xea, 0xe1, 0xb4, 0x4e, 0x2f, - 0x00, 0xac, 0xd0, 0x89, 0xe5, 0xc4, 0x3d, 0x79, 0x86, 0x20, 0xa8, 0x36, 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, 0xd5, 0x2f, 0x4e, 0x4f, 0xd5, 0x85, 0x9a, 0x0a, 0x62, 0xeb, 0x57, 0x20, 0x3b, - 0xb0, 0xa4, 0xb2, 0x20, 0xb5, 0x38, 0x89, 0x0d, 0xec, 0x40, 0x63, 0x40, 0x00, 0x00, 0x00, 0xff, - 0xff, 0x16, 0x92, 0xf1, 0x17, 0x0e, 0x01, 0x00, 0x00, + // 350 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x7c, 0x52, 0xc1, 0x4e, 0xf2, 0x40, + 0x18, 0xec, 0xfe, 0xf0, 0x43, 0x58, 0x50, 0xe3, 0x86, 0x43, 0x45, 0x53, 0x10, 0x2f, 0x3d, 0x48, + 0x9b, 0xe0, 0x03, 0x98, 0xf4, 0x42, 0x4c, 0x3c, 0x98, 0x6a, 0x62, 0xe2, 0x85, 0x6c, 0xdb, 0xcd, + 0x4a, 0x80, 0x2e, 0xe9, 0xb7, 0x04, 0x7d, 0x0b, 0x1f, 0x8b, 0x78, 0xe2, 0xe8, 0xc9, 0x10, 0x78, + 0x11, 0xc3, 0x6e, 0xb1, 0x88, 0xb1, 0xb7, 0x6f, 0xa6, 0x33, 0xf3, 0xcd, 0xd7, 0x16, 0x9f, 0x01, + 0x67, 0x2e, 0x4c, 0x03, 0x1a, 0x86, 0x62, 0x1a, 0x4b, 0x97, 0xb3, 0x98, 0xc1, 0x00, 0x9c, 0x49, + 0x22, 0xa4, 0x20, 0x27, 0xb0, 0xc1, 0x72, 0x26, 0x92, 0xa1, 0x03, 0x9c, 0x39, 0x99, 0xb0, 0x51, + 0xe7, 0x82, 0x0b, 0xa5, 0x72, 0x37, 0x93, 0x36, 0x34, 0x4e, 0xf7, 0xe2, 0x26, 0x34, 0xa1, 0xe3, + 0x34, 0xad, 0xd1, 0xdc, 0x7b, 0x98, 0x8d, 0x5a, 0xd0, 0x7e, 0x47, 0xb8, 0xd6, 0xd3, 0x05, 0xee, + 0x25, 0x95, 0x8c, 0x5c, 0xe3, 0x92, 0x4e, 0x30, 0x51, 0x0b, 0xd9, 0xd5, 0xee, 0xb9, 0xf3, 0x67, + 0x21, 0xe7, 0x4e, 0x09, 0xbd, 0xe2, 0xfc, 0xb3, 0x69, 0xf8, 0xa9, 0x8d, 0x5c, 0xe0, 0x83, 0x4c, + 0xd2, 0x1f, 0x44, 0xe6, 0xbf, 0x16, 0xb2, 0x8b, 0x7e, 0x2d, 0x23, 0x6f, 0x22, 0xf2, 0x80, 0xab, + 0x19, 0x06, 0xb3, 0xd0, 0x2a, 0xd8, 0xd5, 0xee, 0x65, 0xce, 0xaa, 0x6d, 0xc7, 0x6f, 0x26, 0xdd, + 0xba, 0x1b, 0xd3, 0x5e, 0x22, 0x7c, 0xfc, 0x4b, 0x48, 0x4c, 0x5c, 0xa6, 0x51, 0x94, 0x30, 0xd0, + 0x27, 0x55, 0xfc, 0x2d, 0x24, 0x75, 0xfc, 0x5f, 0xcc, 0x62, 0x96, 0xa8, 0x8a, 0x15, 0x5f, 0x03, + 0xe2, 0xe1, 0x72, 0x40, 0x47, 0x34, 0x0e, 0x99, 0x59, 0x50, 0xaf, 0xa0, 0x9d, 0xd3, 0xcb, 0xd3, + 0xca, 0xb4, 0xcd, 0xd6, 0x48, 0x1e, 0xf1, 0xd1, 0x48, 0x84, 0x43, 0x16, 0xf5, 0x53, 0x06, 0xcc, + 0xa2, 0xba, 0xd1, 0xce, 0xc9, 0xba, 0x55, 0x8e, 0x9f, 0x89, 0x87, 0xa3, 0x5d, 0x12, 0xbc, 0xde, + 0x7c, 0x65, 0xa1, 0xc5, 0xca, 0x42, 0xcb, 0x95, 0x85, 0xde, 0xd6, 0x96, 0xb1, 0x58, 0x5b, 0xc6, + 0xc7, 0xda, 0x32, 0x9e, 0x3a, 0x7c, 0x20, 0x9f, 0xa7, 0x81, 0x13, 0x8a, 0xb1, 0x0b, 0x9c, 0x75, + 0xd2, 0x25, 0x9b, 0xd9, 0x7d, 0xd9, 0xfd, 0x07, 0xe4, 0xeb, 0x84, 0x41, 0x50, 0x52, 0xdf, 0xff, + 0xea, 0x2b, 0x00, 0x00, 0xff, 0xff, 0x49, 0x3d, 0x9e, 0x33, 0x8e, 0x02, 0x00, 0x00, } func (m *GenesisState) Marshal() (dAtA []byte, err error) { @@ -112,6 +211,25 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l + if len(m.Subaccounts) > 0 { + for iNdEx := len(m.Subaccounts) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.Subaccounts[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + if m.SubaccountId != 0 { + i = encodeVarintGenesis(dAtA, i, uint64(m.SubaccountId)) + i-- + dAtA[i] = 0x10 + } { size, err := m.Params.MarshalToSizedBuffer(dAtA[:i]) if err != nil { @@ -125,6 +243,67 @@ func (m *GenesisState) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *GenesisSubaccount) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *GenesisSubaccount) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *GenesisSubaccount) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalances) > 0 { + for iNdEx := len(m.LockedBalances) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalances[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x22 + } + } + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintGenesis(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + if len(m.Owner) > 0 { + i -= len(m.Owner) + copy(dAtA[i:], m.Owner) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Owner))) + i-- + dAtA[i] = 0x12 + } + if len(m.Address) > 0 { + i -= len(m.Address) + copy(dAtA[i:], m.Address) + i = encodeVarintGenesis(dAtA, i, uint64(len(m.Address))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + func encodeVarintGenesis(dAtA []byte, offset int, v uint64) int { offset -= sovGenesis(v) base := offset @@ -144,6 +323,40 @@ func (m *GenesisState) Size() (n int) { _ = l l = m.Params.Size() n += 1 + l + sovGenesis(uint64(l)) + if m.SubaccountId != 0 { + n += 1 + sovGenesis(uint64(m.SubaccountId)) + } + if len(m.Subaccounts) > 0 { + for _, e := range m.Subaccounts { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } + return n +} + +func (m *GenesisSubaccount) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.Address) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = len(m.Owner) + if l > 0 { + n += 1 + l + sovGenesis(uint64(l)) + } + l = m.Balance.Size() + n += 1 + l + sovGenesis(uint64(l)) + if len(m.LockedBalances) > 0 { + for _, e := range m.LockedBalances { + l = e.Size() + n += 1 + l + sovGenesis(uint64(l)) + } + } return n } @@ -215,6 +428,240 @@ func (m *GenesisState) Unmarshal(dAtA []byte) error { return err } iNdEx = postIndex + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountId", wireType) + } + m.SubaccountId = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SubaccountId |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Subaccounts", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Subaccounts = append(m.Subaccounts, GenesisSubaccount{}) + if err := m.Subaccounts[len(m.Subaccounts)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipGenesis(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthGenesis + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *GenesisSubaccount) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: GenesisSubaccount: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: GenesisSubaccount: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Address", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Address = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Owner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Owner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 4: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalances", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowGenesis + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthGenesis + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthGenesis + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalances = append(m.LockedBalances, LockedBalance{}) + if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipGenesis(dAtA[iNdEx:]) diff --git a/x/subaccount/types/msg_test.go b/x/subaccount/types/msg_test.go index c0e8fd18..7095e483 100644 --- a/x/subaccount/types/msg_test.go +++ b/x/subaccount/types/msg_test.go @@ -28,7 +28,7 @@ func TestMsgCreateSubAccount_Validate(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: "someInvalidAddress", SubAccountOwner: owner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: someTime, Amount: sdk.NewInt(123), @@ -42,7 +42,7 @@ func TestMsgCreateSubAccount_Validate(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: "someInvalidAddress", - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: someTime, Amount: sdk.NewInt(123), @@ -56,7 +56,7 @@ func TestMsgCreateSubAccount_Validate(t *testing.T) { msg: types.MsgCreateSubAccount{ Sender: sender.String(), SubAccountOwner: owner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: time.Time{}, Amount: sdk.NewInt(123), @@ -90,7 +90,7 @@ func TestMsgTopUp_Validate(t *testing.T) { msg: types.MsgTopUp{ Sender: "someInvalidAddress", SubAccount: owner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: someTime, Amount: sdk.NewInt(123), @@ -104,7 +104,7 @@ func TestMsgTopUp_Validate(t *testing.T) { msg: types.MsgTopUp{ Sender: sender.String(), SubAccount: "someInvalidAddress", - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: someTime, Amount: sdk.NewInt(123), @@ -118,7 +118,7 @@ func TestMsgTopUp_Validate(t *testing.T) { msg: types.MsgTopUp{ Sender: sender.String(), SubAccount: owner.String(), - LockedBalances: []*types.LockedBalance{ + LockedBalances: []types.LockedBalance{ { UnlockTime: time.Time{}, Amount: sdk.NewInt(123), diff --git a/x/subaccount/types/query.pb.go b/x/subaccount/types/query.pb.go index 0a338d47..6d3a1495 100644 --- a/x/subaccount/types/query.pb.go +++ b/x/subaccount/types/query.pb.go @@ -6,10 +6,16 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" + _ "google.golang.org/genproto/googleapis/api/annotations" grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + io "io" math "math" + math_bits "math/bits" ) // Reference imports to suppress errors if they are not otherwise used. @@ -23,19 +29,232 @@ var _ = math.Inf // proto package needs to be updated. const _ = proto.GoGoProtoPackageIsVersion3 // please upgrade the proto package +// QueryParamsRequest is the request type for the Query/Params RPC method +type QueryParamsRequest struct { +} + +func (m *QueryParamsRequest) Reset() { *m = QueryParamsRequest{} } +func (m *QueryParamsRequest) String() string { return proto.CompactTextString(m) } +func (*QueryParamsRequest) ProtoMessage() {} +func (*QueryParamsRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{0} +} +func (m *QueryParamsRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsRequest.Merge(m, src) +} +func (m *QueryParamsRequest) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsRequest.DiscardUnknown(m) +} + +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"` +} + +func (m *QueryParamsResponse) Reset() { *m = QueryParamsResponse{} } +func (m *QueryParamsResponse) String() string { return proto.CompactTextString(m) } +func (*QueryParamsResponse) ProtoMessage() {} +func (*QueryParamsResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{1} +} +func (m *QueryParamsResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QueryParamsResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QueryParamsResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QueryParamsResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QueryParamsResponse.Merge(m, src) +} +func (m *QueryParamsResponse) XXX_Size() int { + return m.Size() +} +func (m *QueryParamsResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QueryParamsResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QueryParamsResponse proto.InternalMessageInfo + +func (m *QueryParamsResponse) GetParams() *Params { + if m != nil { + return m.Params + } + return nil +} + +// QuerySubaccountRequest is the request type for the Query/Subaccount RPC +type QuerySubaccountRequest struct { + SubaccountOwner string `protobuf:"bytes,1,opt,name=subaccount_owner,json=subaccountOwner,proto3" json:"subaccount_owner,omitempty"` +} + +func (m *QuerySubaccountRequest) Reset() { *m = QuerySubaccountRequest{} } +func (m *QuerySubaccountRequest) String() string { return proto.CompactTextString(m) } +func (*QuerySubaccountRequest) ProtoMessage() {} +func (*QuerySubaccountRequest) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{2} +} +func (m *QuerySubaccountRequest) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySubaccountRequest) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySubaccountRequest.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySubaccountRequest) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySubaccountRequest.Merge(m, src) +} +func (m *QuerySubaccountRequest) XXX_Size() int { + return m.Size() +} +func (m *QuerySubaccountRequest) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySubaccountRequest.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySubaccountRequest proto.InternalMessageInfo + +func (m *QuerySubaccountRequest) GetSubaccountOwner() string { + if m != nil { + return m.SubaccountOwner + } + return "" +} + +// QuerySubaccountResponse is the response type for the Query/Subaccount RPC +type QuerySubaccountResponse struct { + SubaccountAddress string `protobuf:"bytes,1,opt,name=subaccount_address,json=subaccountAddress,proto3" json:"subaccount_address,omitempty"` + Balance Balance `protobuf:"bytes,2,opt,name=balance,proto3" json:"balance"` + LockedBalance []LockedBalance `protobuf:"bytes,3,rep,name=locked_balance,json=lockedBalance,proto3" json:"locked_balance"` +} + +func (m *QuerySubaccountResponse) Reset() { *m = QuerySubaccountResponse{} } +func (m *QuerySubaccountResponse) String() string { return proto.CompactTextString(m) } +func (*QuerySubaccountResponse) ProtoMessage() {} +func (*QuerySubaccountResponse) Descriptor() ([]byte, []int) { + return fileDescriptor_e8576ea34550c199, []int{3} +} +func (m *QuerySubaccountResponse) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *QuerySubaccountResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_QuerySubaccountResponse.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *QuerySubaccountResponse) XXX_Merge(src proto.Message) { + xxx_messageInfo_QuerySubaccountResponse.Merge(m, src) +} +func (m *QuerySubaccountResponse) XXX_Size() int { + return m.Size() +} +func (m *QuerySubaccountResponse) XXX_DiscardUnknown() { + xxx_messageInfo_QuerySubaccountResponse.DiscardUnknown(m) +} + +var xxx_messageInfo_QuerySubaccountResponse proto.InternalMessageInfo + +func (m *QuerySubaccountResponse) GetSubaccountAddress() string { + if m != nil { + return m.SubaccountAddress + } + return "" +} + +func (m *QuerySubaccountResponse) GetBalance() Balance { + if m != nil { + return m.Balance + } + return Balance{} +} + +func (m *QuerySubaccountResponse) GetLockedBalance() []LockedBalance { + if m != nil { + return m.LockedBalance + } + return nil +} + +func init() { + proto.RegisterType((*QueryParamsRequest)(nil), "sgenetwork.sge.subaccount.QueryParamsRequest") + proto.RegisterType((*QueryParamsResponse)(nil), "sgenetwork.sge.subaccount.QueryParamsResponse") + proto.RegisterType((*QuerySubaccountRequest)(nil), "sgenetwork.sge.subaccount.QuerySubaccountRequest") + proto.RegisterType((*QuerySubaccountResponse)(nil), "sgenetwork.sge.subaccount.QuerySubaccountResponse") +} + func init() { proto.RegisterFile("sge/subaccount/query.proto", fileDescriptor_e8576ea34550c199) } var fileDescriptor_e8576ea34550c199 = []byte{ - // 141 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, - 0x2f, 0xca, 0xd6, 0x2b, 0x4e, 0x4f, 0xd5, 0x43, 0x28, 0x33, 0x62, 0xe7, 0x62, 0x0d, 0x04, 0xa9, - 0x74, 0x72, 0x3f, 0xf1, 0x48, 0x8e, 0xf1, 0xc2, 0x23, 0x39, 0xc6, 0x07, 0x8f, 0xe4, 0x18, 0x27, - 0x3c, 0x96, 0x63, 0xb8, 0xf0, 0x58, 0x8e, 0xe1, 0xc6, 0x63, 0x39, 0x86, 0x28, 0xdd, 0xf4, 0xcc, - 0x92, 0x8c, 0xd2, 0x24, 0xbd, 0xe4, 0xfc, 0x5c, 0xfd, 0xe2, 0xf4, 0x54, 0x5d, 0xa8, 0x49, 0x20, - 0xb6, 0x7e, 0x05, 0xb2, 0x95, 0x25, 0x95, 0x05, 0xa9, 0xc5, 0x49, 0x6c, 0x60, 0x3b, 0x8d, 0x01, - 0x01, 0x00, 0x00, 0xff, 0xff, 0x85, 0xf6, 0x6a, 0x36, 0x91, 0x00, 0x00, 0x00, + // 430 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x93, 0x3f, 0xef, 0xd2, 0x40, + 0x18, 0xc7, 0x7b, 0xfc, 0x14, 0xe3, 0x11, 0xff, 0x9d, 0x04, 0xb1, 0x92, 0x82, 0x9d, 0x70, 0x68, + 0x1b, 0xeb, 0xe4, 0x68, 0x1d, 0x5c, 0x4c, 0x44, 0x8c, 0x8b, 0x0b, 0xb9, 0x96, 0xcb, 0x49, 0x28, + 0x77, 0xa5, 0x77, 0x0d, 0xb2, 0xba, 0xb8, 0x9a, 0x38, 0xf8, 0x22, 0x7c, 0x23, 0x8c, 0x24, 0x2e, + 0x4e, 0xc6, 0x50, 0x5f, 0x88, 0xe9, 0xf5, 0xb0, 0x80, 0x80, 0xba, 0x5d, 0x9e, 0xfb, 0x7e, 0x3f, + 0xcf, 0xf3, 0xbd, 0x3e, 0x85, 0xa6, 0xa0, 0xc4, 0x13, 0x59, 0x88, 0xa3, 0x88, 0x67, 0x4c, 0x7a, + 0xf3, 0x8c, 0xa4, 0x4b, 0x37, 0x49, 0xb9, 0xe4, 0xe8, 0xae, 0xa0, 0x84, 0x11, 0xb9, 0xe0, 0xe9, + 0xd4, 0x15, 0x94, 0xb8, 0x95, 0xcc, 0x6c, 0x52, 0x4e, 0xb9, 0x52, 0x79, 0xc5, 0xa9, 0x34, 0x98, + 0x1d, 0xca, 0x39, 0x8d, 0x89, 0x87, 0x93, 0x89, 0x87, 0x19, 0xe3, 0x12, 0xcb, 0x09, 0x67, 0x42, + 0xdf, 0x76, 0x0f, 0x5a, 0x55, 0x47, 0x2d, 0xb8, 0x77, 0x20, 0x48, 0x70, 0x8a, 0x67, 0xda, 0x6d, + 0x37, 0x21, 0x7a, 0x59, 0xcc, 0x36, 0x50, 0xc5, 0x21, 0x99, 0x67, 0x44, 0x48, 0x7b, 0x00, 0x6f, + 0xef, 0x55, 0x45, 0xc2, 0x99, 0x20, 0xe8, 0x31, 0xac, 0x97, 0xe6, 0x36, 0xe8, 0x81, 0x7e, 0xc3, + 0xbf, 0xef, 0x9e, 0x8c, 0xe2, 0x6a, 0xab, 0x36, 0xd8, 0x4f, 0x61, 0x4b, 0x11, 0x5f, 0xfd, 0x56, + 0xe8, 0x5e, 0xe8, 0x01, 0xbc, 0x59, 0xd9, 0x46, 0x7c, 0xc1, 0x48, 0xaa, 0xf0, 0x57, 0x87, 0x37, + 0xaa, 0xfa, 0x8b, 0xa2, 0x6c, 0xe7, 0x00, 0xde, 0xf9, 0x83, 0xa2, 0x67, 0x73, 0x20, 0xda, 0xc1, + 0xe0, 0xf1, 0x38, 0x25, 0x42, 0x68, 0xd0, 0xad, 0xea, 0xe6, 0x49, 0x79, 0x81, 0x02, 0x78, 0x25, + 0xc4, 0x31, 0x66, 0x11, 0x69, 0xd7, 0x54, 0x16, 0xfb, 0x4c, 0x96, 0xa0, 0x54, 0x06, 0x97, 0x56, + 0xdf, 0xbb, 0xc6, 0x70, 0x6b, 0x44, 0xaf, 0xe1, 0xf5, 0x98, 0x47, 0x53, 0x32, 0x1e, 0x6d, 0x51, + 0x17, 0xbd, 0x8b, 0x7e, 0xc3, 0xef, 0x9f, 0x41, 0x3d, 0x57, 0x86, 0x7d, 0xe0, 0xb5, 0x78, 0xb7, + 0xe8, 0x7f, 0xa9, 0xc1, 0xcb, 0x2a, 0x25, 0xfa, 0x0c, 0x20, 0xac, 0xa2, 0xa2, 0x87, 0x67, 0xb8, + 0xc7, 0x1f, 0xd7, 0xf4, 0xff, 0xc7, 0x52, 0xbe, 0xa4, 0x6d, 0xbf, 0xff, 0xfa, 0xf3, 0x53, 0xad, + 0x83, 0x4c, 0xef, 0xe4, 0x66, 0xa1, 0x0f, 0x00, 0xd6, 0xcb, 0x2f, 0x8c, 0x9c, 0xbf, 0xb5, 0xd8, + 0x5b, 0x2d, 0xd3, 0xfd, 0x57, 0xb9, 0x9e, 0xc6, 0x52, 0xd3, 0xb4, 0x51, 0xcb, 0x3b, 0xba, 0xc6, + 0xc1, 0xb3, 0xd5, 0xc6, 0x02, 0xeb, 0x8d, 0x05, 0x7e, 0x6c, 0x2c, 0xf0, 0x31, 0xb7, 0x8c, 0x75, + 0x6e, 0x19, 0xdf, 0x72, 0xcb, 0x78, 0xe3, 0xd0, 0x89, 0x7c, 0x9b, 0x85, 0x6e, 0xc4, 0x67, 0x85, + 0xd7, 0xd1, 0x4d, 0x15, 0xe7, 0xdd, 0x2e, 0x49, 0x2e, 0x13, 0x22, 0xc2, 0xba, 0xfa, 0x21, 0x1e, + 0xfd, 0x0a, 0x00, 0x00, 0xff, 0xff, 0x68, 0x47, 0x8c, 0xd2, 0xbb, 0x03, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -50,6 +269,8 @@ const _ = grpc.SupportPackageIsVersion4 // // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream. type QueryClient interface { + Subaccount(ctx context.Context, in *QuerySubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error) + Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) } type queryClient struct { @@ -60,22 +281,761 @@ func NewQueryClient(cc grpc1.ClientConn) QueryClient { return &queryClient{cc} } +func (c *queryClient) Subaccount(ctx context.Context, in *QuerySubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error) { + out := new(QuerySubaccountResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Query/Subaccount", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *queryClient) Params(ctx context.Context, in *QueryParamsRequest, opts ...grpc.CallOption) (*QueryParamsResponse, error) { + out := new(QueryParamsResponse) + err := c.cc.Invoke(ctx, "/sgenetwork.sge.subaccount.Query/Params", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // QueryServer is the server API for Query service. type QueryServer interface { + Subaccount(context.Context, *QuerySubaccountRequest) (*QuerySubaccountResponse, error) + Params(context.Context, *QueryParamsRequest) (*QueryParamsResponse, error) } // UnimplementedQueryServer can be embedded to have forward compatible implementations. type UnimplementedQueryServer struct { } +func (*UnimplementedQueryServer) Subaccount(ctx context.Context, req *QuerySubaccountRequest) (*QuerySubaccountResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Subaccount not implemented") +} +func (*UnimplementedQueryServer) Params(ctx context.Context, req *QueryParamsRequest) (*QueryParamsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method Params not implemented") +} + func RegisterQueryServer(s grpc1.Server, srv QueryServer) { s.RegisterService(&_Query_serviceDesc, srv) } +func _Query_Subaccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QuerySubaccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Subaccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Query/Subaccount", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Subaccount(ctx, req.(*QuerySubaccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _Query_Params_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(QueryParamsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(QueryServer).Params(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/sgenetwork.sge.subaccount.Query/Params", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(QueryServer).Params(ctx, req.(*QueryParamsRequest)) + } + return interceptor(ctx, in, info, handler) +} + var _Query_serviceDesc = grpc.ServiceDesc{ ServiceName: "sgenetwork.sge.subaccount.Query", HandlerType: (*QueryServer)(nil), - Methods: []grpc.MethodDesc{}, - Streams: []grpc.StreamDesc{}, - Metadata: "sge/subaccount/query.proto", + Methods: []grpc.MethodDesc{ + { + MethodName: "Subaccount", + Handler: _Query_Subaccount_Handler, + }, + { + MethodName: "Params", + Handler: _Query_Params_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "sge/subaccount/query.proto", +} + +func (m *QueryParamsRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + return len(dAtA) - i, nil +} + +func (m *QueryParamsResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QueryParamsResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QueryParamsResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = 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)) + } + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySubaccountRequest) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *QuerySubaccountRequest) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySubaccountRequest) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.SubaccountOwner) > 0 { + i -= len(m.SubaccountOwner) + copy(dAtA[i:], m.SubaccountOwner) + i = encodeVarintQuery(dAtA, i, uint64(len(m.SubaccountOwner))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func (m *QuerySubaccountResponse) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil } + +func (m *QuerySubaccountResponse) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *QuerySubaccountResponse) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.LockedBalance) > 0 { + for iNdEx := len(m.LockedBalance) - 1; iNdEx >= 0; iNdEx-- { + { + size, err := m.LockedBalance[iNdEx].MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x1a + } + } + { + size, err := m.Balance.MarshalToSizedBuffer(dAtA[:i]) + if err != nil { + return 0, err + } + i -= size + i = encodeVarintQuery(dAtA, i, uint64(size)) + } + i-- + dAtA[i] = 0x12 + if len(m.SubaccountAddress) > 0 { + i -= len(m.SubaccountAddress) + copy(dAtA[i:], m.SubaccountAddress) + i = encodeVarintQuery(dAtA, i, uint64(len(m.SubaccountAddress))) + i-- + dAtA[i] = 0xa + } + return len(dAtA) - i, nil +} + +func encodeVarintQuery(dAtA []byte, offset int, v uint64) int { + offset -= sovQuery(v) + base := offset + for v >= 1<<7 { + dAtA[offset] = uint8(v&0x7f | 0x80) + v >>= 7 + offset++ + } + dAtA[offset] = uint8(v) + return base +} +func (m *QueryParamsRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + return n +} + +func (m *QueryParamsResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.Params != nil { + l = m.Params.Size() + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySubaccountRequest) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SubaccountOwner) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + return n +} + +func (m *QuerySubaccountResponse) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + l = len(m.SubaccountAddress) + if l > 0 { + n += 1 + l + sovQuery(uint64(l)) + } + l = m.Balance.Size() + n += 1 + l + sovQuery(uint64(l)) + if len(m.LockedBalance) > 0 { + for _, e := range m.LockedBalance { + l = e.Size() + n += 1 + l + sovQuery(uint64(l)) + } + } + return n +} + +func sovQuery(x uint64) (n int) { + return (math_bits.Len64(x|1) + 6) / 7 +} +func sozQuery(x uint64) (n int) { + return sovQuery(uint64((x << 1) ^ uint64((int64(x) >> 63)))) +} +func (m *QueryParamsRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QueryParamsResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QueryParamsResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QueryParamsResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Params", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + 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 + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySubaccountRequest) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySubaccountRequest: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySubaccountRequest: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountOwner", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubaccountOwner = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *QuerySubaccountResponse) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: QuerySubaccountResponse: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: QuerySubaccountResponse: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field SubaccountAddress", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.SubaccountAddress = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 2: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Balance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + if err := m.Balance.Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field LockedBalance", wireType) + } + var msglen int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowQuery + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + msglen |= int(b&0x7F) << shift + if b < 0x80 { + break + } + } + if msglen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + msglen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.LockedBalance = append(m.LockedBalance, LockedBalance{}) + if err := m.LockedBalance[len(m.LockedBalance)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { + return err + } + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipQuery(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthQuery + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func skipQuery(dAtA []byte) (n int, err error) { + l := len(dAtA) + iNdEx := 0 + depth := 0 + for iNdEx < l { + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= (uint64(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + wireType := int(wire & 0x7) + switch wireType { + case 0: + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + iNdEx++ + if dAtA[iNdEx-1] < 0x80 { + break + } + } + case 1: + iNdEx += 8 + case 2: + var length int + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return 0, ErrIntOverflowQuery + } + if iNdEx >= l { + return 0, io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + length |= (int(b) & 0x7F) << shift + if b < 0x80 { + break + } + } + if length < 0 { + return 0, ErrInvalidLengthQuery + } + iNdEx += length + case 3: + depth++ + case 4: + if depth == 0 { + return 0, ErrUnexpectedEndOfGroupQuery + } + depth-- + case 5: + iNdEx += 4 + default: + return 0, fmt.Errorf("proto: illegal wireType %d", wireType) + } + if iNdEx < 0 { + return 0, ErrInvalidLengthQuery + } + if depth == 0 { + return iNdEx, nil + } + } + return 0, io.ErrUnexpectedEOF +} + +var ( + ErrInvalidLengthQuery = fmt.Errorf("proto: negative length found during unmarshaling") + ErrIntOverflowQuery = fmt.Errorf("proto: integer overflow") + ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group") +) diff --git a/x/subaccount/types/query.pb.gw.go b/x/subaccount/types/query.pb.gw.go new file mode 100644 index 00000000..bc73c33f --- /dev/null +++ b/x/subaccount/types/query.pb.gw.go @@ -0,0 +1,236 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: sge/subaccount/query.proto + +/* +Package types is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package types + +import ( + "context" + "io" + "net/http" + + "github.com/golang/protobuf/descriptor" + "github.com/golang/protobuf/proto" + "github.com/grpc-ecosystem/grpc-gateway/runtime" + "github.com/grpc-ecosystem/grpc-gateway/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = descriptor.ForMessage +var _ = metadata.Join + +var ( + filter_Query_Subaccount_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_Query_Subaccount_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySubaccountRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Subaccount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.Subaccount(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Subaccount_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QuerySubaccountRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_Query_Subaccount_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.Subaccount(ctx, &protoReq) + return msg, metadata, err + +} + +func request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, client QueryClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := client.Params(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_Query_Params_0(ctx context.Context, marshaler runtime.Marshaler, server QueryServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq QueryParamsRequest + var metadata runtime.ServerMetadata + + msg, err := server.Params(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterQueryHandlerServer registers the http handlers for service Query to "mux". +// UnaryRPC :call QueryServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead. +func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error { + + mux.Handle("GET", pattern_Query_Subaccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Subaccount_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Subaccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_Query_Params_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.Dial(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Infof("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterQueryHandler(ctx, mux, conn) +} + +// RegisterQueryHandler registers the http handlers for service Query to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterQueryHandlerClient(ctx, mux, NewQueryClient(conn)) +} + +// RegisterQueryHandlerClient registers the http handlers for service Query +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "QueryClient" to call the correct interceptors. +func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error { + + mux.Handle("GET", pattern_Query_Subaccount_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Subaccount_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Subaccount_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_Query_Params_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_Query_Params_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_Query_Params_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_Query_Subaccount_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 1}, []string{"sge", "subaccount"}, "", runtime.AssumeColonVerbOpt(false))) + + pattern_Query_Params_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"sge", "subaccount", "params"}, "", runtime.AssumeColonVerbOpt(false))) +) + +var ( + forward_Query_Subaccount_0 = runtime.ForwardResponseMessage + + forward_Query_Params_0 = runtime.ForwardResponseMessage +) diff --git a/x/subaccount/types/subaccount.go b/x/subaccount/types/subaccount.go index f1be3298..8f9a5441 100644 --- a/x/subaccount/types/subaccount.go +++ b/x/subaccount/types/subaccount.go @@ -32,7 +32,7 @@ func (m *Balance) Available() sdk.Int { } func (m *Balance) Spend(amt sdk.Int) error { - if !amt.IsPositive() { + if amt.IsNegative() { return fmt.Errorf("amount is not positive") } if amt.GT(m.Available()) { @@ -43,7 +43,7 @@ func (m *Balance) Spend(amt sdk.Int) error { } func (m *Balance) Unspend(amt sdk.Int) error { - if !amt.IsPositive() { + if amt.IsNegative() { return fmt.Errorf("amount is not positive") } if amt.GT(m.SpentAmount) { @@ -54,7 +54,7 @@ func (m *Balance) Unspend(amt sdk.Int) error { } func (m *Balance) AddLoss(amt sdk.Int) error { - if !amt.IsPositive() { + if amt.IsNegative() { return fmt.Errorf("amount is not positive") } m.LostAmount = m.LostAmount.Add(amt) diff --git a/x/subaccount/types/tx.pb.go b/x/subaccount/types/tx.pb.go index 1036932f..865dc53d 100644 --- a/x/subaccount/types/tx.pb.go +++ b/x/subaccount/types/tx.pb.go @@ -6,6 +6,7 @@ package types import ( context "context" fmt "fmt" + _ "github.com/cosmos/gogoproto/gogoproto" grpc1 "github.com/gogo/protobuf/grpc" proto "github.com/gogo/protobuf/proto" types "github.com/sge-network/sge/x/bet/types" @@ -36,7 +37,7 @@ type MsgCreateSubAccount struct { // sub_account_owner is the owner of the subaccount. SubAccountOwner string `protobuf:"bytes,2,opt,name=sub_account_owner,json=subAccountOwner,proto3" json:"sub_account_owner,omitempty"` // locked_balances is the list of balance locks. - LockedBalances []*LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances,omitempty"` + LockedBalances []LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` } func (m *MsgCreateSubAccount) Reset() { *m = MsgCreateSubAccount{} } @@ -86,7 +87,7 @@ func (m *MsgCreateSubAccount) GetSubAccountOwner() string { return "" } -func (m *MsgCreateSubAccount) GetLockedBalances() []*LockedBalance { +func (m *MsgCreateSubAccount) GetLockedBalances() []LockedBalance { if m != nil { return m.LockedBalances } @@ -137,7 +138,7 @@ type MsgTopUp struct { // sub_account is the subaccount address. SubAccount string `protobuf:"bytes,2,opt,name=sub_account,json=subAccount,proto3" json:"sub_account,omitempty"` // locked_balances is the list of balance locks. - LockedBalances []*LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances,omitempty"` + LockedBalances []LockedBalance `protobuf:"bytes,3,rep,name=locked_balances,json=lockedBalances,proto3" json:"locked_balances"` } func (m *MsgTopUp) Reset() { *m = MsgTopUp{} } @@ -187,7 +188,7 @@ func (m *MsgTopUp) GetSubAccount() string { return "" } -func (m *MsgTopUp) GetLockedBalances() []*LockedBalance { +func (m *MsgTopUp) GetLockedBalances() []LockedBalance { if m != nil { return m.LockedBalances } @@ -602,44 +603,45 @@ func init() { func init() { proto.RegisterFile("sge/subaccount/tx.proto", fileDescriptor_e042e836d366badb) } var fileDescriptor_e042e836d366badb = []byte{ - // 579 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0x41, 0x6e, 0xd3, 0x40, - 0x18, 0x85, 0x63, 0xa2, 0x56, 0xe5, 0x0f, 0x90, 0x30, 0x48, 0x34, 0x18, 0x70, 0x83, 0x0b, 0x52, - 0x68, 0x55, 0x47, 0x4a, 0x04, 0x0b, 0x16, 0x08, 0x4a, 0xab, 0xb2, 0x20, 0x42, 0x84, 0x56, 0x15, - 0x6c, 0x22, 0x3b, 0x19, 0x4d, 0xa2, 0xa6, 0x1e, 0xe3, 0xdf, 0x56, 0x0a, 0xa7, 0x40, 0x2c, 0x38, - 0x05, 0x12, 0xd7, 0x60, 0xd9, 0x25, 0x4b, 0x94, 0x5c, 0x04, 0x79, 0x6c, 0x4f, 0x9c, 0xa4, 0x8e, - 0x53, 0x24, 0x76, 0xe3, 0xd1, 0x7b, 0x6f, 0xbe, 0x67, 0xcd, 0xaf, 0x81, 0x75, 0x64, 0xb4, 0x86, - 0xbe, 0x65, 0x76, 0x3a, 0xdc, 0xb7, 0xbd, 0x9a, 0x77, 0x66, 0x38, 0x2e, 0xf7, 0x38, 0xb9, 0x83, - 0x8c, 0xda, 0xd4, 0x1b, 0x72, 0xf7, 0xc4, 0x40, 0x46, 0x8d, 0x89, 0x46, 0xdd, 0x98, 0xf1, 0x4c, - 0x96, 0xa1, 0x57, 0x2d, 0x05, 0x02, 0x8b, 0x4e, 0xd2, 0x54, 0x12, 0xec, 0xf4, 0xb8, 0x8f, 0x54, - 0xee, 0xe9, 0x3f, 0x14, 0xb8, 0xd5, 0x44, 0xf6, 0xca, 0xa5, 0xa6, 0x47, 0xdf, 0xfb, 0xd6, 0xcb, - 0x30, 0x83, 0xdc, 0x86, 0x55, 0xa4, 0x76, 0x97, 0xba, 0x65, 0xa5, 0xa2, 0x54, 0xaf, 0xb6, 0xa2, - 0x2f, 0xb2, 0x05, 0x37, 0xd1, 0xb7, 0xda, 0xd1, 0x51, 0x6d, 0x3e, 0xb4, 0xa9, 0x5b, 0xbe, 0x22, - 0x24, 0x45, 0x94, 0xf6, 0xb7, 0xc1, 0x36, 0x79, 0x07, 0xc5, 0x01, 0xef, 0x9c, 0xd0, 0x6e, 0xdb, - 0x32, 0x07, 0xa6, 0xdd, 0xa1, 0x58, 0xce, 0x57, 0xf2, 0xd5, 0x42, 0xbd, 0x6a, 0xa4, 0xf6, 0x32, - 0xde, 0x08, 0xc7, 0x6e, 0x68, 0x68, 0xdd, 0x18, 0x24, 0x3f, 0x51, 0xbf, 0x0f, 0x77, 0x2f, 0xa0, - 0x6d, 0x51, 0x74, 0xb8, 0x8d, 0x54, 0xff, 0xae, 0xc0, 0x5a, 0x13, 0xd9, 0x21, 0x77, 0x8e, 0x9c, - 0xd4, 0x0a, 0x1b, 0x50, 0x48, 0x54, 0x88, 0xe0, 0x61, 0x02, 0xff, 0x3f, 0xb8, 0x09, 0x94, 0x62, - 0x2e, 0x09, 0xfb, 0x44, 0x74, 0x39, 0xee, 0x7b, 0xbd, 0xae, 0x6b, 0x0e, 0x8f, 0xec, 0x69, 0x4b, - 0x1a, 0xbe, 0xfe, 0x08, 0x36, 0x17, 0xd8, 0x64, 0xfa, 0x33, 0xf1, 0x27, 0x8e, 0x4d, 0x46, 0x5d, - 0x62, 0x40, 0xfe, 0x14, 0x99, 0xc8, 0x29, 0xd4, 0xef, 0xcd, 0x96, 0xb0, 0xa8, 0x67, 0xc4, 0xd2, - 0x56, 0x20, 0xd4, 0x0f, 0x05, 0x6d, 0xb8, 0x11, 0xe5, 0x91, 0x17, 0xb0, 0xe6, 0x46, 0xeb, 0x28, - 0xe8, 0xe1, 0xc2, 0xa0, 0x48, 0xdb, 0x92, 0x2e, 0x7d, 0x1f, 0x8a, 0x4d, 0x64, 0xaf, 0x83, 0xfb, - 0xb7, 0x47, 0x1d, 0x8e, 0x7d, 0x8f, 0xd4, 0x93, 0x60, 0x95, 0xd9, 0x3c, 0x71, 0x55, 0x83, 0xc4, - 0x48, 0x1e, 0xc2, 0xb5, 0x61, 0x7d, 0x26, 0x46, 0x32, 0xee, 0xcd, 0x31, 0x56, 0x33, 0x33, 0xe7, - 0x39, 0x0f, 0x44, 0x7b, 0x71, 0x40, 0xfc, 0x97, 0x49, 0x23, 0x09, 0xfa, 0x20, 0x35, 0x34, 0xd6, - 0x87, 0xa4, 0x26, 0x94, 0x67, 0x83, 0x24, 0xea, 0xfe, 0x1c, 0xea, 0xe3, 0xec, 0xd4, 0x39, 0xd6, - 0xfa, 0xcf, 0x15, 0xc8, 0x37, 0x91, 0x91, 0x2f, 0x50, 0x9a, 0x1b, 0x61, 0x63, 0xc1, 0x6d, 0xbd, - 0x60, 0x88, 0xd4, 0xa7, 0x97, 0xd3, 0xcb, 0x2a, 0x1f, 0x60, 0x25, 0x1c, 0xb8, 0xcd, 0xc5, 0x01, - 0x42, 0xa4, 0x6e, 0x2f, 0x21, 0x92, 0xd1, 0xdf, 0x14, 0x28, 0xa7, 0x0e, 0x48, 0x06, 0x6f, 0x9a, - 0x4f, 0x7d, 0xfe, 0x6f, 0xbe, 0x64, 0xdf, 0x70, 0xac, 0x32, 0xfa, 0x0a, 0x51, 0x56, 0xdf, 0xe9, - 0x21, 0xb3, 0xe1, 0xda, 0xd4, 0x7c, 0x6c, 0x2d, 0x36, 0x27, 0xb5, 0x6a, 0x7d, 0x79, 0xad, 0x3c, - 0xef, 0x13, 0x5c, 0x9f, 0xbe, 0xe7, 0xdb, 0x4b, 0x84, 0xc4, 0x62, 0xb5, 0x71, 0x09, 0x71, 0x7c, - 0xe4, 0xee, 0xc1, 0xaf, 0x91, 0xa6, 0x9c, 0x8f, 0x34, 0xe5, 0xcf, 0x48, 0x53, 0xbe, 0x8e, 0xb5, - 0xdc, 0xf9, 0x58, 0xcb, 0xfd, 0x1e, 0x6b, 0xb9, 0x8f, 0x3b, 0xac, 0xef, 0xf5, 0x7c, 0xcb, 0xe8, - 0xf0, 0xd3, 0x1a, 0x32, 0xba, 0x13, 0x25, 0x07, 0xeb, 0xda, 0xd9, 0xd4, 0xf3, 0xf8, 0xd9, 0xa1, - 0x68, 0xad, 0x8a, 0x07, 0xac, 0xf1, 0x37, 0x00, 0x00, 0xff, 0xff, 0x1f, 0xf0, 0x28, 0xa5, 0x3d, - 0x07, 0x00, 0x00, + // 597 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x95, 0xcf, 0x6e, 0xd3, 0x4c, + 0x14, 0xc5, 0xe3, 0x2f, 0x5f, 0xab, 0x72, 0x03, 0x24, 0x0c, 0x88, 0x06, 0x03, 0x4e, 0x70, 0x41, + 0x0a, 0xad, 0xea, 0x48, 0x89, 0x60, 0xc1, 0x02, 0x41, 0x68, 0x55, 0x16, 0x44, 0x48, 0xa1, 0x55, + 0x04, 0x9b, 0xc8, 0x4e, 0x46, 0x93, 0xa8, 0xa9, 0xc7, 0xf8, 0xda, 0x4a, 0xe1, 0x29, 0x10, 0x6b, + 0xde, 0x01, 0x89, 0xa7, 0xe8, 0xb2, 0x4b, 0x56, 0x08, 0x25, 0x2f, 0x82, 0x3c, 0xfe, 0x13, 0x27, + 0xa9, 0xe3, 0x14, 0x89, 0xdd, 0xe4, 0xea, 0x9c, 0xdf, 0x9c, 0x13, 0xcd, 0x95, 0x61, 0x13, 0x19, + 0xad, 0xa2, 0x6b, 0xe8, 0xdd, 0x2e, 0x77, 0x4d, 0xa7, 0xea, 0x9c, 0x6a, 0x96, 0xcd, 0x1d, 0x4e, + 0xee, 0x20, 0xa3, 0x26, 0x75, 0x46, 0xdc, 0x3e, 0xd6, 0x90, 0x51, 0x6d, 0xaa, 0x91, 0x4b, 0x73, + 0x9e, 0xe9, 0xd1, 0xf7, 0xca, 0x05, 0x4f, 0x60, 0xd0, 0x29, 0x4d, 0x26, 0xde, 0xa4, 0xcf, 0x5d, + 0xa4, 0xd3, 0xd9, 0x2d, 0xc6, 0x19, 0x17, 0xc7, 0xaa, 0x77, 0xf2, 0xa7, 0xea, 0x0f, 0x09, 0x6e, + 0x36, 0x91, 0xbd, 0xb2, 0xa9, 0xee, 0xd0, 0x77, 0xae, 0xf1, 0xd2, 0x27, 0x93, 0xdb, 0xb0, 0x8e, + 0xd4, 0xec, 0x51, 0xbb, 0x28, 0x95, 0xa5, 0xca, 0x95, 0x56, 0xf0, 0x8b, 0x6c, 0xc3, 0x0d, 0x74, + 0x8d, 0x4e, 0x10, 0xa0, 0xc3, 0x47, 0x26, 0xb5, 0x8b, 0xff, 0x09, 0x49, 0x1e, 0x23, 0xfb, 0x5b, + 0x6f, 0x4c, 0xda, 0x90, 0x1f, 0xf2, 0xee, 0x31, 0xed, 0x75, 0x0c, 0x7d, 0xa8, 0x9b, 0x5d, 0x8a, + 0xc5, 0x6c, 0x39, 0x5b, 0xc9, 0xd5, 0x2a, 0x5a, 0x62, 0x5b, 0xed, 0x8d, 0x70, 0x34, 0x7c, 0x43, + 0xe3, 0xff, 0xb3, 0x5f, 0xa5, 0x4c, 0xeb, 0xfa, 0x30, 0x3e, 0x44, 0xf5, 0x3e, 0xdc, 0xbd, 0x20, + 0x73, 0x8b, 0xa2, 0xc5, 0x4d, 0xa4, 0xea, 0x37, 0x09, 0x36, 0x9a, 0xc8, 0x0e, 0xb9, 0x75, 0x64, + 0x25, 0x16, 0x29, 0x41, 0x2e, 0x56, 0x24, 0xa8, 0x00, 0xd3, 0x0a, 0xff, 0x2e, 0x3d, 0x81, 0x42, + 0x98, 0x2e, 0x8a, 0xfc, 0x44, 0x34, 0x6a, 0x0f, 0x9c, 0x7e, 0xcf, 0xd6, 0x47, 0x47, 0xe6, 0xac, + 0x25, 0xa9, 0x84, 0xfa, 0x08, 0xb6, 0x96, 0xd8, 0x22, 0xfa, 0x33, 0xf1, 0x7f, 0xb4, 0x75, 0x46, + 0x6d, 0xa2, 0x41, 0xf6, 0x04, 0x99, 0xe0, 0xe4, 0x6a, 0xf7, 0xe6, 0xab, 0x18, 0xd4, 0xd1, 0x42, + 0x69, 0xcb, 0x13, 0xaa, 0x87, 0x22, 0xad, 0x3f, 0x08, 0x78, 0xe4, 0x05, 0x6c, 0xd8, 0xc1, 0x39, + 0x00, 0x3d, 0x5c, 0x0a, 0x0a, 0xb4, 0xad, 0xc8, 0xa5, 0xee, 0x43, 0xbe, 0x89, 0xec, 0xb5, 0xf7, + 0x42, 0xf7, 0xa8, 0xc5, 0x71, 0xe0, 0x90, 0x5a, 0x3c, 0x58, 0x79, 0x9e, 0x27, 0x1e, 0xb3, 0x47, + 0x0c, 0xe4, 0x7e, 0xb8, 0x0e, 0x6c, 0xce, 0x61, 0xa2, 0x8c, 0x7b, 0x0b, 0x19, 0x2b, 0xa9, 0xcc, + 0xc5, 0x9c, 0x07, 0xa2, 0xbd, 0xb8, 0x20, 0xfc, 0x97, 0x49, 0x3d, 0x1e, 0xf4, 0x41, 0x22, 0x34, + 0xd4, 0xfb, 0x49, 0x75, 0x28, 0xce, 0x83, 0xa2, 0xa8, 0xfb, 0x0b, 0x51, 0x1f, 0xa7, 0x53, 0x17, + 0xb2, 0xd6, 0xbe, 0xaf, 0x41, 0xb6, 0x89, 0x8c, 0x7c, 0x86, 0xc2, 0xc2, 0x3a, 0x6b, 0x4b, 0xde, + 0xec, 0x05, 0xab, 0x24, 0x3f, 0xbd, 0x9c, 0x3e, 0xaa, 0xf2, 0x1e, 0xd6, 0xfc, 0xb5, 0xdb, 0x5a, + 0x0e, 0x10, 0x22, 0x79, 0x67, 0x05, 0x51, 0x84, 0xfe, 0x2a, 0x41, 0x31, 0x71, 0x41, 0x52, 0xf2, + 0x26, 0xf9, 0xe4, 0xe7, 0x7f, 0xe7, 0x8b, 0xf7, 0xf5, 0xd7, 0x2a, 0xa5, 0xaf, 0x10, 0xa5, 0xf5, + 0x9d, 0x5d, 0x32, 0x13, 0xae, 0xce, 0xec, 0xc7, 0xf6, 0x72, 0x73, 0x5c, 0x2b, 0xd7, 0x56, 0xd7, + 0x46, 0xf7, 0x7d, 0x84, 0x6b, 0xb3, 0xef, 0x7c, 0x67, 0x05, 0x48, 0x28, 0x96, 0xeb, 0x97, 0x10, + 0x87, 0x57, 0x36, 0x0e, 0xce, 0xc6, 0x8a, 0x74, 0x3e, 0x56, 0xa4, 0xdf, 0x63, 0x45, 0xfa, 0x32, + 0x51, 0x32, 0xe7, 0x13, 0x25, 0xf3, 0x73, 0xa2, 0x64, 0x3e, 0xec, 0xb2, 0x81, 0xd3, 0x77, 0x0d, + 0xad, 0xcb, 0x4f, 0xaa, 0xc8, 0xe8, 0x6e, 0x40, 0xf6, 0xce, 0xd5, 0xd3, 0x99, 0x0f, 0xe8, 0x27, + 0x8b, 0xa2, 0xb1, 0x2e, 0x3e, 0x66, 0xf5, 0x3f, 0x01, 0x00, 0x00, 0xff, 0xff, 0x37, 0x0e, 0xaa, + 0x8d, 0x5f, 0x07, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -1628,7 +1630,7 @@ func (m *MsgCreateSubAccount) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.LockedBalances = append(m.LockedBalances, &LockedBalance{}) + m.LockedBalances = append(m.LockedBalances, LockedBalance{}) if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1826,7 +1828,7 @@ func (m *MsgTopUp) Unmarshal(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.LockedBalances = append(m.LockedBalances, &LockedBalance{}) + m.LockedBalances = append(m.LockedBalances, LockedBalance{}) if err := m.LockedBalances[len(m.LockedBalances)-1].Unmarshal(dAtA[iNdEx:postIndex]); err != nil { return err }