Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Subaccount module part 6 #233

Merged
merged 33 commits into from
Aug 9, 2023
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,7 @@ func NewAppKeeper(
appCodec,
appKeepers.keys[subaccounttypes.StoreKey],
appKeepers.GetSubspace(subaccounttypes.ModuleName),
appKeepers.AccountKeeper,
appKeepers.BankKeeper,
appKeepers.OVMKeeper,
appKeepers.BetKeeper,
Expand Down
21 changes: 21 additions & 0 deletions proto/sge/subaccount/genesis.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,32 @@ 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";

// GenesisState defines the subaccount module's genesis state.
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 ];
}
37 changes: 36 additions & 1 deletion proto/sge/subaccount/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
}


5 changes: 3 additions & 2 deletions proto/sge/subaccount/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down Expand Up @@ -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.
Expand All @@ -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.
Expand Down
36 changes: 34 additions & 2 deletions x/subaccount/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Loading