Skip to content

Commit

Permalink
feegranter config to unsigned tx
Browse files Browse the repository at this point in the history
  • Loading branch information
dixitaniket committed Sep 15, 2023
1 parent b369602 commit f6c80f7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
23 changes: 10 additions & 13 deletions cw-relayer/relayer/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ type (
KeyringPassphrase string
ChainHeight *ChainHeight
feeGranter sdk.AccAddress
feeGrantEnabled bool
}

passReader struct {
Expand Down Expand Up @@ -109,19 +108,20 @@ func NewRelayerClient(
QueryRpc: queryEndpoint,
}

clientCtx, err := relayerClient.CreateClientContext()
if err != nil {
return RelayerClient{}, err
}

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
} else {
relayerClient.feeGranter = clientCtx.GetFeeGranterAddress()
}

blockHeight, err := rpc.GetChainHeight(clientCtx)
Expand Down Expand Up @@ -202,7 +202,7 @@ func (oc RelayerClient) BroadcastTx(timeoutDuration time.Duration, nextBlockHeig
// set last check height to latest block height
lastCheckHeight = latestBlockHeight

resp, err := BroadcastTx(clientCtx, factory, msgs...)
resp, err := BroadcastTx(oc.feeGranter, clientCtx, factory, msgs...)
if resp != nil && resp.Code != 0 {
telemetry.IncrCounter(1, "failure", "tx", "code")
oc.logger.Error().Msg(resp.String())
Expand Down Expand Up @@ -361,11 +361,8 @@ func (oc RelayerClient) CreateTxFactory() (tx.Factory, error) {
WithGasPrices(oc.GasPrices).
WithKeybase(clientCtx.Keyring).
WithSignMode(signing.SignMode_SIGN_MODE_DIRECT).
WithSimulateAndExecute(true)

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

return txFactory, nil
}
Expand Down
4 changes: 2 additions & 2 deletions cw-relayer/relayer/client/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
// Note, BroadcastTx is copied from the SDK except it removes a few unnecessary
// things like prompting for confirmation and printing the response. Instead,
// we return the TxResponse.
func BroadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
func BroadcastTx(feeGranter sdk.AccAddress, clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sdk.TxResponse, error) {
txf, err := prepareFactory(clientCtx, txf)
if err != nil {
return nil, err
Expand All @@ -31,7 +31,7 @@ func BroadcastTx(clientCtx client.Context, txf tx.Factory, msgs ...sdk.Msg) (*sd
return nil, err
}

unsignedTx.SetFeeGranter(clientCtx.GetFeeGranterAddress())
unsignedTx.SetFeeGranter(feeGranter)

if err = tx.Sign(txf, clientCtx.GetFromName(), unsignedTx, true); err != nil {
return nil, err
Expand Down

0 comments on commit f6c80f7

Please sign in to comment.