@@ -13,17 +13,17 @@ import (
1313 sdkkeyring "github.com/cosmos/cosmos-sdk/crypto/keyring"
1414 cryptotypes "github.com/cosmos/cosmos-sdk/crypto/types"
1515 sdk "github.com/cosmos/cosmos-sdk/types"
16+ banktypes "github.com/cosmos/cosmos-sdk/x/bank/types"
1617 "github.com/cosmos/cosmos-sdk/x/feegrant"
1718 "github.com/gitopia/git-remote-gitopia/config"
1819 glib "github.com/gitopia/gitopia-go"
1920 "github.com/gitopia/gitopia-go/logger"
2021 gitopia "github.com/gitopia/gitopia/v2/app"
2122 offchaintypes "github.com/gitopia/gitopia/v2/x/offchain/types"
2223 goGitConfig "github.com/go-git/go-git/v5/config"
24+ "github.com/pkg/errors"
2325 "github.com/sirupsen/logrus"
2426 "github.com/spf13/pflag"
25-
26- "github.com/pkg/errors"
2727 "google.golang.org/grpc"
2828)
2929
@@ -60,7 +60,7 @@ type OSKeyring struct {
6060 secType secretType
6161}
6262
63- func InitOSKeyringWallet (feegrantClient feegrant.QueryClient ) (Wallet , error ) {
63+ func InitOSKeyringWallet (bankClient banktypes. QueryClient , feegrantClient feegrant.QueryClient ) (Wallet , error ) {
6464 var key string
6565 var backend string
6666
@@ -96,13 +96,23 @@ func InitOSKeyringWallet(feegrantClient feegrant.QueryClient) (Wallet, error) {
9696 return nil , errors .Wrap (err , "error creating cosmos client context" )
9797 }
9898
99- fr , _ := feegrantClient .Allowance (context .Background (), & feegrant.QueryAllowanceRequest {
100- Granter : config .FeeGranterAddr ,
101- Grantee : cc .FromAddress .String (),
102- })
103-
104- if fr != nil {
105- cc .WithFeeGranterAddress (sdk .MustAccAddressFromBech32 (fr .Allowance .Granter ))
99+ if bankClient != nil && feegrantClient != nil {
100+ b , _ := bankClient .Balance (context .Background (), & banktypes.QueryBalanceRequest {
101+ Address : cc .FromAddress .String (),
102+ Denom : config .Denom ,
103+ })
104+
105+ // Use fee grant only when balance is zero
106+ if b .Balance .Amount .IsZero () {
107+ fr , _ := feegrantClient .Allowance (context .Background (), & feegrant.QueryAllowanceRequest {
108+ Granter : config .FeeGranterAddr ,
109+ Grantee : cc .FromAddress .String (),
110+ })
111+
112+ if fr != nil {
113+ cc .WithFeeGranterAddress (sdk .MustAccAddressFromBech32 (fr .Allowance .Granter ))
114+ }
115+ }
106116 }
107117
108118 txf := tx .NewFactoryCLI (cc , & pflag.FlagSet {}).WithGasAdjustment (GAS_ADJUSTMENT )
0 commit comments