Skip to content

Commit

Permalink
- add taxable query
Browse files Browse the repository at this point in the history
  • Loading branch information
StrathCole committed Nov 30, 2023
1 parent 6564f59 commit 2432c68
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
31 changes: 31 additions & 0 deletions x/taxexemption/client/cli/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,44 @@ func GetQueryCmd() *cobra.Command {
RunE: client.ValidateCmd,
}
taxexemptionQueryCmd.AddCommand(
GetCmdQueryTaxable(),
GetCmdQueryZonelist(),
GetCmdQueryExemptlist(),
)

return taxexemptionQueryCmd
}

func GetCmdQueryTaxable() *cobra.Command {
cmd := &cobra.Command{
Use: "taxable [from-address] [to-address]",
Args: cobra.ExactArgs(2),
Short: "Query tax exemption of an transfer from an address to another",
RunE: func(cmd *cobra.Command, args []string) error {
fromAddress := args[0]
toAddress := args[1]

clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

res, err := queryClient.Taxable(context.Background(), &types.QueryTaxableRequest{
FromAddress: fromAddress,
ToAddress: toAddress,
})
if err != nil {
return err
}
return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)
return cmd
}

func GetCmdQueryZonelist() *cobra.Command {
cmd := &cobra.Command{
Use: "zones",
Expand Down
7 changes: 7 additions & 0 deletions x/taxexemption/keeper/querier.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ func NewQuerier(keeper Keeper) types.QueryServer {

var _ types.QueryServer = querier{}

// Taxable queries if a tx from one address to another is taxable
func (q querier) Taxable(c context.Context, req *types.QueryTaxableRequest) (*types.QueryTaxableResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
taxable := !q.Keeper.IsExemptedFromTax(ctx, req.FromAddress, req.ToAddress)
return &types.QueryTaxableResponse{Taxable: taxable}, nil
}

// TaxExemptionZoneList queries tax exemption zone list of taxexemption module
func (q querier) TaxExemptionZonesList(c context.Context, req *types.QueryTaxExemptionZonesRequest) (*types.QueryTaxExemptionZonesResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
Expand Down

0 comments on commit 2432c68

Please sign in to comment.