-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"github.com/KYVENetwork/chain/x/query/types" | ||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/cosmos/cosmos-sdk/types/query" | ||
"github.com/spf13/cobra" | ||
"strconv" | ||
) | ||
|
||
func byFunder( | ||
clientCtx client.Context, | ||
queryClient types.QueryFundersClient, | ||
pageReq *query.PageRequest, | ||
address string, | ||
) error { | ||
params := &types.QueryFundingsByFunderRequest{ | ||
Pagination: pageReq, | ||
Address: address, | ||
WithInactiveFundings: true, | ||
} | ||
|
||
res, err := queryClient.FundingsByFunder(context.Background(), params) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
} | ||
|
||
func byPool( | ||
clientCtx client.Context, | ||
queryClient types.QueryFundersClient, | ||
pageReq *query.PageRequest, | ||
poolId uint64, | ||
) error { | ||
params := &types.QueryFundingsByPoolRequest{ | ||
Pagination: pageReq, | ||
PoolId: poolId, | ||
WithInactiveFundings: true, | ||
} | ||
|
||
res, err := queryClient.FundingsByPool(context.Background(), params) | ||
if err != nil { | ||
return err | ||
} | ||
return clientCtx.PrintProto(res) | ||
} | ||
|
||
func CmdListFundings() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "fundings [address | pool-id]", | ||
Short: "list all fundings of a user or a pool", | ||
Args: cobra.ExactArgs(1), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
reqAddressOrPool := args[0] | ||
|
||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
pageReq, err := client.ReadPageRequest(cmd.Flags()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryFundersClient(clientCtx) | ||
|
||
poolId, err := strconv.ParseUint(reqAddressOrPool, 10, 64) | ||
if err != nil { | ||
return byFunder(clientCtx, queryClient, pageReq, reqAddressOrPool) | ||
} | ||
return byPool(clientCtx, queryClient, pageReq, poolId) | ||
}, | ||
} | ||
|
||
flags.AddPaginationFlagsToCmd(cmd, cmd.Use) | ||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |