-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add in-route-by-denom and out-route-by-denom queries (#262)
- Loading branch information
1 parent
2d3cb15
commit bc86a7b
Showing
13 changed files
with
1,606 additions
and
132 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
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
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,48 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/elys-network/elys/x/amm/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdInRouteByDenom() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "in-route-by-denom [denom-in] [denom-out]", | ||
Example: "elysd q amm in-route-by-denom uelys uusdc", | ||
Short: "Query in-route-by-denom", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
reqDenomIn := args[0] | ||
reqDenomOut := args[1] | ||
|
||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryInRouteByDenomRequest{ | ||
DenomIn: reqDenomIn, | ||
DenomOut: reqDenomOut, | ||
} | ||
|
||
res, err := queryClient.InRouteByDenom(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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,48 @@ | ||
package cli | ||
|
||
import ( | ||
"strconv" | ||
|
||
"github.com/cosmos/cosmos-sdk/client" | ||
"github.com/cosmos/cosmos-sdk/client/flags" | ||
"github.com/elys-network/elys/x/amm/types" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var _ = strconv.Itoa(0) | ||
|
||
func CmdOutRouteByDenom() *cobra.Command { | ||
cmd := &cobra.Command{ | ||
Use: "out-route-by-denom [denom-out] [denom-in]", | ||
Example: "elysd q amm out-route-by-denom uusdc uelys", | ||
Short: "Query out-route-by-denom", | ||
Args: cobra.ExactArgs(2), | ||
RunE: func(cmd *cobra.Command, args []string) (err error) { | ||
reqDenomOut := args[0] | ||
reqDenomIn := args[1] | ||
|
||
clientCtx, err := client.GetClientQueryContext(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
queryClient := types.NewQueryClient(clientCtx) | ||
|
||
params := &types.QueryOutRouteByDenomRequest{ | ||
DenomOut: reqDenomOut, | ||
DenomIn: reqDenomIn, | ||
} | ||
|
||
res, err := queryClient.OutRouteByDenom(cmd.Context(), params) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return clientCtx.PrintProto(res) | ||
}, | ||
} | ||
|
||
flags.AddQueryFlagsToCmd(cmd) | ||
|
||
return cmd | ||
} |
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,22 @@ | ||
package wasm | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
ammtypes "github.com/elys-network/elys/x/amm/types" | ||
) | ||
|
||
func (oq *Querier) queryInRouteByDenom(ctx sdk.Context, query *ammtypes.QueryInRouteByDenomRequest) ([]byte, error) { | ||
res, err := oq.keeper.InRouteByDenom(sdk.WrapSDKContext(ctx), query) | ||
if err != nil { | ||
return nil, errorsmod.Wrap(err, "failed to get in route by denom") | ||
} | ||
|
||
responseBytes, err := json.Marshal(res) | ||
if err != nil { | ||
return nil, errorsmod.Wrap(err, "failed to serialize in route by denom response") | ||
} | ||
return responseBytes, nil | ||
} |
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,22 @@ | ||
package wasm | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
errorsmod "cosmossdk.io/errors" | ||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
ammtypes "github.com/elys-network/elys/x/amm/types" | ||
) | ||
|
||
func (oq *Querier) queryOutRouteByDenom(ctx sdk.Context, query *ammtypes.QueryOutRouteByDenomRequest) ([]byte, error) { | ||
res, err := oq.keeper.OutRouteByDenom(sdk.WrapSDKContext(ctx), query) | ||
if err != nil { | ||
return nil, errorsmod.Wrap(err, "failed to get out route by denom") | ||
} | ||
|
||
responseBytes, err := json.Marshal(res) | ||
if err != nil { | ||
return nil, errorsmod.Wrap(err, "failed to serialize out route by denom response") | ||
} | ||
return responseBytes, nil | ||
} |
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,23 @@ | ||
package keeper | ||
|
||
import ( | ||
"context" | ||
|
||
sdk "github.com/cosmos/cosmos-sdk/types" | ||
"github.com/elys-network/elys/x/amm/types" | ||
"google.golang.org/grpc/codes" | ||
"google.golang.org/grpc/status" | ||
) | ||
|
||
func (k Keeper) InRouteByDenom(goCtx context.Context, req *types.QueryInRouteByDenomRequest) (*types.QueryInRouteByDenomResponse, error) { | ||
if req == nil { | ||
return nil, status.Error(codes.InvalidArgument, "invalid request") | ||
} | ||
|
||
ctx := sdk.UnwrapSDKContext(goCtx) | ||
|
||
// TODO: Process the query | ||
_ = ctx | ||
|
||
return &types.QueryInRouteByDenomResponse{}, nil | ||
} |
Oops, something went wrong.