-
Notifications
You must be signed in to change notification settings - Fork 40
/
health_check.go
45 lines (38 loc) · 985 Bytes
/
health_check.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
package evm
import (
"bytes"
"context"
"math/big"
"github.com/ethereum/go-ethereum/common"
"github.com/palomachain/pigeon/chain"
"github.com/palomachain/pigeon/config"
)
func (p Processor) HealthCheck(ctx context.Context) error {
var zeroAddr common.Address
if len(p.evmClient.addr) == 0 || bytes.Equal(p.evmClient.addr.Bytes(), zeroAddr.Bytes()) {
return chain.ErrMissingAccount.Format(p.chainReferenceID)
}
balance, err := p.evmClient.BalanceAt(ctx, p.evmClient.addr, 0)
if err != nil {
return err
}
cmp := balance.Cmp(p.minOnChainBalance)
if cmp == -1 || balance.Cmp(big.NewInt(0)) == 0 {
return chain.ErrAccountBalanceLow.Format(balance, p.evmClient.addr, p.chainReferenceID, p.minOnChainBalance)
}
return nil
}
func TestAndVerifyConfig(ctx context.Context, cfg config.EVM) error {
cli := &Client{
config: cfg,
}
err := cli.init()
if err != nil {
return err
}
_, err = cli.conn.BlockNumber(ctx)
if err != nil {
return err
}
return nil
}