-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into fix/account-errors
- Loading branch information
Showing
66 changed files
with
2,223 additions
and
781 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
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
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
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,67 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"github.com/ignite/cli/ignite/pkg/cosmosclient" | ||
"github.com/ignite/cli/ignite/pkg/xurl" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
const ( | ||
flagNode = "node" | ||
cosmosRPCAddress = "https://rpc.cosmos.network:443" | ||
) | ||
|
||
func NewNode() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "node [command]", | ||
Short: "Make calls to a live blockchain node", | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
c.PersistentFlags().String(flagNode, cosmosRPCAddress, "<host>:<port> to tendermint rpc interface for this chain") | ||
|
||
c.AddCommand(NewNodeQuery()) | ||
c.AddCommand(NewNodeTx()) | ||
|
||
return c | ||
} | ||
|
||
func newNodeCosmosClient(cmd *cobra.Command) (cosmosclient.Client, error) { | ||
var ( | ||
home = getHome(cmd) | ||
prefix = getAddressPrefix(cmd) | ||
node = getRPC(cmd) | ||
keyringBackend = getKeyringBackend(cmd) | ||
keyringDir = getKeyringDir(cmd) | ||
gas = getGas(cmd) | ||
gasPrices = getGasPrices(cmd) | ||
fees = getFees(cmd) | ||
broadcastMode = getBroadcastMode(cmd) | ||
) | ||
|
||
options := []cosmosclient.Option{ | ||
cosmosclient.WithAddressPrefix(prefix), | ||
cosmosclient.WithHome(home), | ||
cosmosclient.WithKeyringBackend(keyringBackend), | ||
cosmosclient.WithKeyringDir(keyringDir), | ||
cosmosclient.WithNodeAddress(xurl.HTTPEnsurePort(node)), | ||
cosmosclient.WithBroadcastMode(broadcastMode), | ||
} | ||
|
||
if gas != "" { | ||
options = append(options, cosmosclient.WithGas(gas)) | ||
} | ||
if gasPrices != "" { | ||
options = append(options, cosmosclient.WithGasPrices(gasPrices)) | ||
} | ||
if fees != "" { | ||
options = append(options, cosmosclient.WithFees(fees)) | ||
} | ||
|
||
return cosmosclient.New(cmd.Context(), options...) | ||
} | ||
|
||
func getRPC(cmd *cobra.Command) (rpc string) { | ||
rpc, _ = cmd.Flags().GetString(flagNode) | ||
return | ||
} |
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,72 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/types/query" | ||
"github.com/spf13/cobra" | ||
flag "github.com/spf13/pflag" | ||
) | ||
|
||
const ( | ||
flagPage = "page" | ||
flagLimit = "limit" | ||
flagPageKey = "page-key" | ||
flagOffset = "offset" | ||
flagCountTotal = "count-total" | ||
flagReverse = "reverse" | ||
) | ||
|
||
func NewNodeQuery() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "query", | ||
Short: "Querying subcommands", | ||
Aliases: []string{"q"}, | ||
} | ||
|
||
c.AddCommand(NewNodeQueryBank()) | ||
c.AddCommand(NewNodeQueryTx()) | ||
|
||
return c | ||
} | ||
|
||
func flagSetPagination(query string) *flag.FlagSet { | ||
fs := flag.NewFlagSet("", flag.ContinueOnError) | ||
|
||
fs.Uint64(flagPage, 1, fmt.Sprintf("pagination page of %s to query for. This sets offset to a multiple of limit", query)) | ||
fs.String(flagPageKey, "", fmt.Sprintf("pagination page-key of %s to query for", query)) | ||
fs.Uint64(flagOffset, 0, fmt.Sprintf("pagination offset of %s to query for", query)) | ||
fs.Uint64(flagLimit, 100, fmt.Sprintf("pagination limit of %s to query for", query)) | ||
fs.Bool(flagCountTotal, false, fmt.Sprintf("count total number of records in %s to query for", query)) | ||
fs.Bool(flagReverse, false, "results are sorted in descending order") | ||
|
||
return fs | ||
} | ||
|
||
func getPagination(cmd *cobra.Command) (*query.PageRequest, error) { | ||
var ( | ||
pageKey, _ = cmd.Flags().GetString(flagPageKey) | ||
offset, _ = cmd.Flags().GetUint64(flagOffset) | ||
limit, _ = cmd.Flags().GetUint64(flagLimit) | ||
countTotal, _ = cmd.Flags().GetBool(flagCountTotal) | ||
page, _ = cmd.Flags().GetUint64(flagPage) | ||
reverse, _ = cmd.Flags().GetBool(flagReverse) | ||
) | ||
|
||
if page > 1 && offset > 0 { | ||
return nil, errors.New("page and offset cannot be used together") | ||
} | ||
|
||
if page > 1 { | ||
offset = (page - 1) * limit | ||
} | ||
|
||
return &query.PageRequest{ | ||
Key: []byte(pageKey), | ||
Offset: offset, | ||
Limit: limit, | ||
CountTotal: countTotal, | ||
Reverse: reverse, | ||
}, 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,14 @@ | ||
package ignitecmd | ||
|
||
import "github.com/spf13/cobra" | ||
|
||
func NewNodeQueryBank() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "bank", | ||
Short: "Querying commands for the bank module", | ||
} | ||
|
||
c.AddCommand(NewNodeQueryBankBalances()) | ||
|
||
return c | ||
} |
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,61 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ignite/cli/ignite/pkg/cliui" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewNodeQueryBankBalances() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "balances [from_account_or_address]", | ||
Short: "Query for account balances by account name or address", | ||
RunE: nodeQueryBankBalancesHandler, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
|
||
c.Flags().AddFlagSet(flagSetHome()) | ||
c.Flags().AddFlagSet(flagSetAccountPrefixes()) | ||
c.Flags().AddFlagSet(flagSetKeyringBackend()) | ||
c.Flags().AddFlagSet(flagSetKeyringDir()) | ||
c.Flags().AddFlagSet(flagSetPagination("all balances")) | ||
|
||
return c | ||
} | ||
|
||
func nodeQueryBankBalancesHandler(cmd *cobra.Command, args []string) error { | ||
inputAccount := args[0] | ||
|
||
client, err := newNodeCosmosClient(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// inputAccount can be an account of the keyring or a raw address | ||
address, err := client.Address(inputAccount) | ||
if err != nil { | ||
address = inputAccount | ||
} | ||
|
||
pagination, err := getPagination(cmd) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
session := cliui.New() | ||
defer session.Cleanup() | ||
session.StartSpinner("Querying...") | ||
balances, err := client.BankBalances(cmd.Context(), address, pagination) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
var rows [][]string | ||
for _, b := range balances { | ||
rows = append(rows, []string{fmt.Sprintf("%s", b.Amount), b.Denom}) | ||
} | ||
|
||
session.StopSpinner() | ||
return session.PrintTable([]string{"Amount", "Denom"}, rows...) | ||
} |
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,41 @@ | ||
package ignitecmd | ||
|
||
import ( | ||
"encoding/hex" | ||
"encoding/json" | ||
"fmt" | ||
|
||
sdkclient "github.com/cosmos/cosmos-sdk/client" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
func NewNodeQueryTx() *cobra.Command { | ||
c := &cobra.Command{ | ||
Use: "tx [hash]", | ||
Short: "Query for transaction by hash", | ||
RunE: nodeQueryTxHandler, | ||
Args: cobra.ExactArgs(1), | ||
} | ||
return c | ||
} | ||
|
||
func nodeQueryTxHandler(cmd *cobra.Command, args []string) error { | ||
bz, err := hex.DecodeString(args[0]) | ||
if err != nil { | ||
return err | ||
} | ||
rpc, err := sdkclient.NewClientFromNode(getRPC(cmd)) | ||
if err != nil { | ||
return err | ||
} | ||
resp, err := rpc.Tx(cmd.Context(), bz, false) | ||
if err != nil { | ||
return err | ||
} | ||
bz, err = json.MarshalIndent(resp, "", " ") | ||
if err != nil { | ||
return err | ||
} | ||
fmt.Println(string(bz)) | ||
return nil | ||
} |
Oops, something went wrong.