Skip to content

Commit

Permalink
Merge branch 'main' into joel/backup-rpcs
Browse files Browse the repository at this point in the history
  • Loading branch information
joelsmith-2019 committed Jul 8, 2024
2 parents 31ba93e + 6ab7f61 commit bc60dd5
Show file tree
Hide file tree
Showing 25 changed files with 31,357 additions and 10,427 deletions.
9 changes: 9 additions & 0 deletions cmd/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const (
flagInitialBlockHistory = "block-history"
flagFlushInterval = "flush-interval"
flagMemo = "memo"
flagKeyName = "key-name"
flagFilterRule = "filter-rule"
flagFilterChannels = "filter-channels"
flagSrcChainID = "src-chain-id"
Expand Down Expand Up @@ -477,6 +478,14 @@ func memoFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
return cmd
}

func keyNameFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(flagKeyName, "", "a key from the keychain associated with a particular chain")
if err := v.BindPFlag(flagKeyName, cmd.Flags().Lookup(flagKeyName)); err != nil {
panic(err)
}
return cmd
}

func OverwriteConfigFlag(v *viper.Viper, cmd *cobra.Command) *cobra.Command {
cmd.Flags().BoolP(flagOverwriteConfig, "o", false,
"overwrite already configured paths - will clear channel filter(s)")
Expand Down
72 changes: 72 additions & 0 deletions cmd/query.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ func queryCmd(a *appState) *cobra.Command {
queryUnrelayedAcknowledgements(a),
lineBreakCommand(),
queryBalanceCmd(a),
queryBalancesCmd(a),
queryHeaderCmd(a),
queryNodeStateCmd(a),
queryTxs(a),
Expand Down Expand Up @@ -325,6 +326,77 @@ $ %s query balance ibc-0 testkey`,
return cmd
}

func queryBalancesCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "balances [chain-name...]",
Short: "query the relayer's account balances on given networks by chain-ID",
Args: withUsage(cobra.MinimumNArgs(1)),
Example: strings.TrimSpace(fmt.Sprintf(`
$ %s query balances ibc-0 ibc-1
$ %s query balances ibc-0 ibc-1 --key-name=test`,
appName, appName,
)),
RunE: func(cmd *cobra.Command, args []string) error {
keyName, _ := cmd.Flags().GetString(flagKeyName)

data := map[string]string{}
for _, arg := range args {
chain, ok := a.config.Chains[arg]
if !ok {
return errChainNotFound(args[0])
}

chainKey := keyName
if chainKey == "" {
chainKey = chain.ChainProvider.Key()
}

showDenoms, err := cmd.Flags().GetBool(flagIBCDenoms)
if err != nil {
return err
}

if !chain.ChainProvider.KeyExists(chainKey) {
return errKeyDoesntExist(chainKey)
}
addr, err := chain.ChainProvider.ShowAddress(chainKey)
if err != nil {
return err
}

coins, err := relayer.QueryBalance(cmd.Context(), chain, addr, showDenoms)
if err != nil {
return err
}

data[addr] = coins.String()
}
jsonOutput, err := json.Marshal(data)
if err != nil {
return err
}

output, _ := cmd.Flags().GetString(flagOutput)
switch output {
case formatJson:
fmt.Fprint(cmd.OutOrStdout(), string(jsonOutput))
case formatLegacy:
fallthrough
default:
for addr, balance := range data {
fmt.Fprintf(cmd.OutOrStdout(), "address {%s} balance {%s} \n", addr, balance)
}
}
return nil
},
}

cmd = addOutputFlag(a.viper, cmd)
cmd = ibcDenomFlags(a.viper, cmd)
cmd = keyNameFlag(a.viper, cmd)
return cmd
}

func queryHeaderCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "header chain_name [height]",
Expand Down
2 changes: 1 addition & 1 deletion cmd/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -1214,7 +1214,7 @@ func ensureKeysExist(chains map[string]*relayer.Chain) error {
return nil
}

// MsgRegisterCounterpartyPayee registers the counterparty_payee
// registerCounterpartyCmd registers the counterparty_payee
func registerCounterpartyCmd(a *appState) *cobra.Command {
cmd := &cobra.Command{
Use: "register-counterparty chain_name channel_id port_id relay_addr counterparty_payee",
Expand Down
6 changes: 2 additions & 4 deletions relayer/chains/cosmos/account.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,8 @@ func (cc *CosmosProvider) GetAccountWithHeight(_ client.Context, addr sdk.AccAdd

// EnsureExists returns an error if no account exists for the given address else nil.
func (cc *CosmosProvider) EnsureExists(clientCtx client.Context, addr sdk.AccAddress) error {
if _, err := cc.GetAccount(clientCtx, addr); err != nil {
return err
}
return nil
_, err := cc.GetAccount(clientCtx, addr)
return err
}

// GetAccountNumberSequence returns sequence and account number for the given address.
Expand Down
2 changes: 1 addition & 1 deletion relayer/chains/cosmos/fee_market_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
Key: "default",
ChainName: "osmosis",
ChainID: "osmosis-1",
RPCAddr: "https://rpc.osmosis.strange.love:443",
RPCAddr: "https://osmosis-rpc.polkachu.com:443",
AccountPrefix: "osmo",
KeyringBackend: "test",
DynamicGasPrice: true,
Expand Down
5 changes: 1 addition & 4 deletions relayer/chains/cosmos/keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,10 +180,7 @@ func (cc *CosmosProvider) ListAddresses() (map[string]string, error) {

// DeleteKey removes a key from the keystore for the specified name.
func (cc *CosmosProvider) DeleteKey(name string) error {
if err := cc.Keybase.Delete(name); err != nil {
return err
}
return nil
return cc.Keybase.Delete(name)
}

// KeyExists returns true if a key with the specified name exists in the keystore, it returns false otherwise.
Expand Down
Loading

0 comments on commit bc60dd5

Please sign in to comment.