Skip to content

Commit

Permalink
Merge pull request #568 from okp4/fix/cli-logic-query
Browse files Browse the repository at this point in the history
  • Loading branch information
amimart authored Feb 23, 2024
2 parents ad04ce4 + 0257729 commit 9fd5264
Show file tree
Hide file tree
Showing 12 changed files with 200 additions and 67 deletions.
4 changes: 2 additions & 2 deletions docs/command/okp4d_query_logic.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ okp4d query logic [flags]
### SEE ALSO

* [okp4d query](okp4d_query.md) - Querying subcommands
* [okp4d query logic ask](okp4d_query_logic_ask.md) - Executes a logic query and returns the solution(s) found.
* [okp4d query logic params](okp4d_query_logic_params.md) - Execute the Params RPC method
* [okp4d query logic ask](okp4d_query_logic_ask.md) - executes a logic query and returns the solutions found.
* [okp4d query logic params](okp4d_query_logic_params.md) - shows the parameters of the module
15 changes: 6 additions & 9 deletions docs/command/okp4d_query_logic_ask.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
## okp4d query logic ask

Executes a logic query and returns the solution(s) found.
executes a logic query and returns the solutions found.

### Synopsis

Executes the [query] and return the solution(s) found.

Optionally, a program can be transmitted, which will be compiled before the query is processed.

Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
is charged for this, but the execution is constrained by the current limits configured in the module (that you can
query).
Optionally, a program can be transmitted, which will be interpreted before the query is processed.
Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
is charged for this, but the execution is constrained by the current limits configured in the module (that you can
query).

```
okp4d query logic ask [query] [flags]
Expand All @@ -29,10 +27,9 @@ $ okp4d query logic ask "chain_id(X)." # returns the chain-id
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for ask
--no-indent Do not indent JSON output
--node string <host>:<port> to CometBFT RPC interface for this chain (default "tcp://localhost:26657")
-o, --output string Output format (text|json) (default "text")
-p, --program string The program to compile before the query.
--program string reads the program from the given string.
```

### SEE ALSO
Expand Down
3 changes: 1 addition & 2 deletions docs/command/okp4d_query_logic_params.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## okp4d query logic params

Execute the Params RPC method
shows the parameters of the module

```
okp4d query logic params [flags]
Expand All @@ -13,7 +13,6 @@ okp4d query logic params [flags]
--grpc-insecure allow gRPC over insecure channels, if not the server must use TLS
--height int Use a specific height to query state at (this can error if the node is pruning state)
-h, --help help for params
--no-indent Do not indent JSON output
--node string <host>:<port> to CometBFT RPC interface for this chain (default "tcp://localhost:26657")
-o, --output string Output format (text|json) (default "text")
```
Expand Down
1 change: 1 addition & 0 deletions docs/command/okp4d_tx.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ okp4d tx [flags]
* [okp4d tx ibc-fee](okp4d_tx_ibc-fee.md) - IBC relayer incentivization transaction subcommands
* [okp4d tx ibc-transfer](okp4d_tx_ibc-transfer.md) - IBC fungible token transfer transaction subcommands
* [okp4d tx interchain-accounts](okp4d_tx_interchain-accounts.md) - IBC interchain accounts transaction subcommands
* [okp4d tx logic](okp4d_tx_logic.md) - Transactions commands for the logic module
* [okp4d tx mint](okp4d_tx_mint.md) - Transactions commands for the mint module
* [okp4d tx multi-sign](okp4d_tx_multi-sign.md) - Generate multisig signatures for transactions generated offline
* [okp4d tx multisign-batch](okp4d_tx_multisign-batch.md) - Assemble multisig transactions in batch from batch signatures
Expand Down
18 changes: 18 additions & 0 deletions docs/command/okp4d_tx_logic.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
## okp4d tx logic

Transactions commands for the logic module

```
okp4d tx logic [flags]
```

### Options

```
-h, --help help for logic
```

### SEE ALSO

* [okp4d tx](okp4d_tx.md) - Transactions subcommands
* [okp4d tx logic update-params](okp4d_tx_logic_update-params.md) - Execute the UpdateParams RPC method
43 changes: 43 additions & 0 deletions docs/command/okp4d_tx_logic_update-params.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## okp4d tx logic update-params

Execute the UpdateParams RPC method

```
okp4d tx logic update-params [flags]
```

### Options

```
-a, --account-number uint The account number of the signing account (offline mode only)
--aux Generate aux signer data instead of sending a tx
-b, --broadcast-mode string Transaction broadcasting mode (sync|async) (default "sync")
--chain-id string The network chain ID
--dry-run ignore the --gas flag and perform a simulation of a transaction, but don't broadcast it (when enabled, the local Keybase is not accessible)
--fee-granter string Fee granter grants fees for the transaction
--fee-payer string Fee payer pays fees for the transaction instead of deducting from the signer
--fees string Fees to pay along with transaction; eg: 10uatom
--from string Name or address of private key with which to sign
--gas string gas limit to set per-transaction; set to "auto" to calculate sufficient gas automatically. Note: "auto" option doesn't always report accurate results. Set a valid coin value to adjust the result. Can be used instead of "fees". (default 200000)
--gas-adjustment float adjustment factor to be multiplied against the estimate returned by the tx simulation; if the gas limit is set manually this flag is ignored (default 1)
--gas-prices string Gas prices in decimal format to determine the transaction fee (e.g. 0.1uatom)
--generate-only Build an unsigned transaction and write it to STDOUT (when enabled, the local Keybase only accessed when providing a key name)
-h, --help help for update-params
--keyring-backend string Select keyring's backend (os|file|kwallet|pass|test|memory) (default "os")
--keyring-dir string The client Keyring directory; if omitted, the default 'home' directory will be used
--ledger Use a connected Ledger device
--node string <host>:<port> to CometBFT rpc interface for this chain (default "tcp://localhost:26657")
--note string Note to add a description to the transaction (previously --memo)
--offline Offline mode (does not allow any online functionality)
-o, --output string Output format (text|json) (default "json")
--params logic.v1beta2.Params (json)
-s, --sequence uint The sequence number of the signing account (offline mode only)
--sign-mode string Choose sign mode (direct|amino-json|direct-aux|textual), this is an advanced feature
--timeout-height uint Set a block timeout height to prevent the tx from being committed past a certain height
--tip string Tip is the amount that is going to be transferred to the fee payer on the target chain. This flag is only valid when used with --aux, and is ignored if the target chain didn't enable the TipDecorator
-y, --yes Skip tx broadcasting prompt confirmation
```

### SEE ALSO

* [okp4d tx logic](okp4d_tx_logic.md) - Transactions commands for the logic module
44 changes: 0 additions & 44 deletions x/logic/autocli.go

This file was deleted.

28 changes: 28 additions & 0 deletions x/logic/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"

"github.com/okp4/okp4d/x/logic/types"
)

// GetQueryCmd returns the cli query commands for this module.
func GetQueryCmd() *cobra.Command {
// Group logic queries under a subcommand
cmd := &cobra.Command{
Use: types.ModuleName,
Short: fmt.Sprintf("Querying commands for the %s module", types.ModuleName),
DisableFlagParsing: true,
SuggestionsMinimumDistance: 2,
RunE: client.ValidateCmd,
}

cmd.AddCommand(CmdQueryParams())
cmd.AddCommand(CmdQueryAsk())

return cmd
}
57 changes: 57 additions & 0 deletions x/logic/client/cli/query_ask.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package cli

import (
"context"
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"

"github.com/okp4/okp4d/x/logic/types"
)

var program string

func CmdQueryAsk() *cobra.Command {
cmd := &cobra.Command{
Use: "ask [query]",
Short: "executes a logic query and returns the solutions found.",
Long: `Executes the [query] and return the solution(s) found.
Optionally, a program can be transmitted, which will be interpreted before the query is processed.
Since the query is without any side-effect, the query is not executed in the context of a transaction and no fee
is charged for this, but the execution is constrained by the current limits configured in the module (that you can
query).`,
Example: fmt.Sprintf(`$ %s query %s ask "chain_id(X)." # returns the chain-id`,
version.AppName,
types.ModuleName),
Args: cobra.MinimumNArgs(1),
RunE: func(cmd *cobra.Command, args []string) (err error) {
clientCtx := client.GetClientContextFromCmd(cmd)
query := args[0]
queryClient := types.NewQueryServiceClient(clientCtx)

res, err := queryClient.Ask(context.Background(), &types.QueryServiceAskRequest{
Program: program,
Query: query,
})
if err != nil {
return
}

return clientCtx.PrintProto(res)
},
}

cmd.Flags().StringVar(
&program,
"program",
"",
`reads the program from the given string.`)

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
36 changes: 36 additions & 0 deletions x/logic/client/cli/query_params.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cli

import (
"context"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"

"github.com/okp4/okp4d/x/logic/types"
)

func CmdQueryParams() *cobra.Command {
cmd := &cobra.Command{
Use: "params",
Short: "shows the parameters of the module",
Args: cobra.NoArgs,
RunE: func(cmd *cobra.Command, _ []string) error {
clientCtx := client.GetClientContextFromCmd(cmd)

queryClient := types.NewQueryServiceClient(clientCtx)

res, err := queryClient.Params(context.Background(), &types.QueryServiceParamsRequest{})
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
8 changes: 8 additions & 0 deletions x/logic/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"

"github.com/grpc-ecosystem/grpc-gateway/runtime"
"github.com/spf13/cobra"

"cosmossdk.io/core/appmodule"

Expand All @@ -15,6 +16,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"

"github.com/okp4/okp4d/x/logic/client/cli"
"github.com/okp4/okp4d/x/logic/exported"
"github.com/okp4/okp4d/x/logic/keeper"
"github.com/okp4/okp4d/x/logic/types"
Expand Down Expand Up @@ -77,6 +79,12 @@ func (AppModuleBasic) RegisterGRPCGatewayRoutes(clientCtx client.Context, mux *r
_ = types.RegisterQueryServiceHandlerClient(context.Background(), mux, types.NewQueryServiceClient(clientCtx))
}

// GetQueryCmd returns the root query command for the module. The subcommands of this root command are used by end-users
// to generate new queries to the subset of the state defined by the module.
func (AppModuleBasic) GetQueryCmd() *cobra.Command {
return cli.GetQueryCmd()
}

// ----------------------------------------------------------------------------
// AppModule
// ----------------------------------------------------------------------------
Expand Down
10 changes: 0 additions & 10 deletions x/logic/types/types.go

This file was deleted.

0 comments on commit 9fd5264

Please sign in to comment.