Skip to content

Commit

Permalink
fix(withdraw): wait for the withdrawal tx receipt (#2902)
Browse files Browse the repository at this point in the history
* wait for the withdrawal tx receipt

* lint

* fix lint[goreleaser]
  • Loading branch information
golangisfun123 authored Jul 24, 2024
1 parent 0458257 commit 81ca8f8
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions services/rfq/relayer/cmd/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@
package cmd

import (
"context"
"fmt"
"math/big"
"time"

"github.com/charmbracelet/huh/spinner"
"github.com/ethereum/go-ethereum/common"
"github.com/synapsecns/sanguine/core"
"github.com/synapsecns/sanguine/core/commandline"
"github.com/synapsecns/sanguine/core/metrics"
"github.com/synapsecns/sanguine/core/retry"
"github.com/synapsecns/sanguine/services/rfq/relayer/relapi"
"github.com/synapsecns/sanguine/services/rfq/relayer/relconfig"
"github.com/synapsecns/sanguine/services/rfq/relayer/service"
Expand Down Expand Up @@ -115,27 +118,41 @@ var withdrawCommand = &cli.Command{
TokenAddress: common.HexToAddress(tokenAddress),
To: common.HexToAddress(to),
}

res, err := client.Withdraw(c.Context, &withdrawRequest)
if err != nil {
return fmt.Errorf("could not start relayer: %w", err)
}

var errClient error
var status *relapi.TxHashByNonceResponse
err = spinner.New().
Title("Waiting for tx...").
Action(func() {

ctx, cancel := context.WithTimeout(c.Context, 30*time.Second)
defer cancel()

action := func() {
err = retry.WithBackoff(ctx, func(_ context.Context) error {
status, err = client.GetTxHashByNonce(
c.Context,
&relapi.GetTxByNonceRequest{
ChainID: uint32(chainID.Uint64()),
Nonce: res.Nonce,
})
if err != nil {
errClient = fmt.Errorf("could not login: %w", err)
errClient = err
return fmt.Errorf("could not get withdrawal tx hash: %w", err)
}
}).Run()
return nil
})

if err != nil {
return
}
}

err = spinner.New().
Title("Getting withdrawal tx hash...").
Action(action).Run()

if err != nil {
return fmt.Errorf("could not get withdrawal tx hash: %w", err)
}
Expand Down

0 comments on commit 81ca8f8

Please sign in to comment.