Skip to content

Commit

Permalink
fee grant support
Browse files Browse the repository at this point in the history
  • Loading branch information
dixitaniket committed Sep 15, 2023
1 parent 71fa322 commit b369602
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
1 change: 1 addition & 0 deletions cw-relayer/cmd/cw-relayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ func cwRelayerCmdHandler(cmd *cobra.Command, args []string) error {
cfg.Account.AccPrefix,
cfg.GasAdjustment,
cfg.GasPrices,
cfg.FeeGrant.Granter,
)
if err != nil {
return err
Expand Down
15 changes: 11 additions & 4 deletions cw-relayer/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ var (
type (
// Config defines all necessary cw-relayer configuration parameters.
Config struct {
Account Account `mapstructure:"account" validate:"required,gt=0,dive,required"`
Keyring Keyring `mapstructure:"keyring" validate:"required,gt=0,dive,required"`
RPC RPC `mapstructure:"rpc" validate:"required,gt=0,dive,required"`
Restart RestartConfig `mapstructure:"restart" validate:"required"`
Account Account `mapstructure:"account" validate:"required,gt=0,dive,required"`
Keyring Keyring `mapstructure:"keyring" validate:"required,gt=0,dive,required"`
RPC RPC `mapstructure:"rpc" validate:"required,gt=0,dive,required"`
Restart RestartConfig `mapstructure:"restart" validate:"required"`
FeeGrant FeeGrantConfig `mapstructure:"fee_grant" validate:"dive"`

ProviderTimeout string `mapstructure:"provider_timeout"`
ContractAddress string `mapstructure:"contract_address"`
Expand Down Expand Up @@ -87,6 +88,10 @@ type (
SkipError bool `mapstructure:"skip_error"`
}

FeeGrantConfig struct {
Granter string `mapstructure:"granter" validate:"omitempty,required"`
}

// RPC defines RPC configuration of both the wasmd chain and Tendermint nodes.
RPC struct {
TMRPCEndpoint string `mapstructure:"tmrpc_endpoint" validate:"required"`
Expand Down Expand Up @@ -160,5 +165,7 @@ func ParseConfig(configPath string) (Config, error) {
cfg.MaxRetries = defaultRetries
}

fmt.Println()

return cfg, cfg.Validate()
}
17 changes: 17 additions & 0 deletions cw-relayer/relayer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ type (
GasAdjustment float64
KeyringPassphrase string
ChainHeight *ChainHeight
feeGranter sdk.AccAddress
feeGrantEnabled bool
}

passReader struct {
Expand Down Expand Up @@ -80,6 +82,7 @@ func NewRelayerClient(
accPrefix string,
gasAdjustment float64,
GasPrices string,
granter string,
) (RelayerClient, error) {
config := sdk.GetConfig()
config.SetBech32PrefixForAccount(accPrefix, accPrefix+sdk.PrefixPublic)
Expand All @@ -106,6 +109,16 @@ func NewRelayerClient(
QueryRpc: queryEndpoint,
}

if len(granter) > 0 {
feeGranterAddr, err := sdk.AccAddressFromBech32(granter)
if err != nil {
return RelayerClient{}, err
}

relayerClient.feeGranter = feeGranterAddr
relayerClient.feeGrantEnabled = true
}

clientCtx, err := relayerClient.CreateClientContext()
if err != nil {
return RelayerClient{}, err
Expand Down Expand Up @@ -350,6 +363,10 @@ func (oc RelayerClient) CreateTxFactory() (tx.Factory, error) {
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
WithSimulateAndExecute(true)

if oc.feeGrantEnabled {
txFactory = txFactory.WithFeeGranter(oc.feeGranter)
}

return txFactory, nil
}

Expand Down

0 comments on commit b369602

Please sign in to comment.