Skip to content

Commit

Permalink
adding balance command too
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarstonConnell committed Sep 6, 2024
1 parent 6078ce8 commit ffd8db8
Showing 1 changed file with 41 additions and 1 deletion.
42 changes: 41 additions & 1 deletion cmd/wallet/wallet.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wallet

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
Expand All @@ -18,7 +19,7 @@ func WalletCmd() *cobra.Command {
Short: "Wallet subcommands",
}

c.AddCommand(addressCmd(), withdrawCMD())
c.AddCommand(addressCmd(), withdrawCMD(), balanceCMD())

return c
}
Expand Down Expand Up @@ -49,6 +50,45 @@ func addressCmd() *cobra.Command {
}
}

func balanceCMD() *cobra.Command {
return &cobra.Command{
Use: "balance",
Short: "Displays the balance of the provider.",
RunE: func(cmd *cobra.Command, args []string) error {
home, err := cmd.Flags().GetString(types.FlagHome)
if err != nil {
return err
}

_, err = config.Init(home)
if err != nil {
return err
}

wallet, err := config.InitWallet(home)
if err != nil {
return err
}

queryClient := bankTypes.NewQueryClient(wallet.Client.GRPCConn)

params := &bankTypes.QueryBalanceRequest{
Denom: "ujkl",
Address: wallet.AccAddress(),
}

res, err := queryClient.Balance(context.Background(), params)
if err != nil {
fmt.Println(err)
return nil
}

fmt.Printf("Balance: %s\n", res.Balance)
return nil
},
}
}

func withdrawCMD() *cobra.Command {
return &cobra.Command{
Use: "withdraw [to-address] [amount]",
Expand Down

0 comments on commit ffd8db8

Please sign in to comment.