-
Notifications
You must be signed in to change notification settings - Fork 271
/
Copy pathutils.go
58 lines (53 loc) · 1.45 KB
/
utils.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package withdraw
import (
"context"
"errors"
"fmt"
"math/big"
"time"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethclient"
"github.com/ethereum/go-ethereum/rpc"
)
type WithdrawHelper interface {
CheckIfProvable() error
GetProvenWithdrawalTime() (uint64, error)
ProveWithdrawal() error
IsProofFinalized() (bool, error)
FinalizeWithdrawal() error
}
func txBlock(ctx context.Context, l2c *rpc.Client, l2TxHash common.Hash) (*big.Int, error) {
l2 := ethclient.NewClient(l2c)
// Figure out when our withdrawal was included
receipt, err := l2.TransactionReceipt(ctx, l2TxHash)
if err != nil {
return nil, err
}
if receipt.Status != types.ReceiptStatusSuccessful {
return nil, errors.New("unsuccessful withdrawal receipt status")
}
return receipt.BlockNumber, nil
}
func waitForConfirmation(ctx context.Context, client *ethclient.Client, tx common.Hash) error {
for {
receipt, err := client.TransactionReceipt(ctx, tx)
if err == ethereum.NotFound {
fmt.Printf("waiting for tx confirmation\n")
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(5 * time.Second):
}
} else if err != nil {
return err
} else if receipt.Status != types.ReceiptStatusSuccessful {
return errors.New("unsuccessful withdrawal receipt status")
} else {
break
}
}
fmt.Printf("%s confirmed\n", tx.String())
return nil
}