-
Notifications
You must be signed in to change notification settings - Fork 5
/
feeder.go
60 lines (52 loc) · 1.4 KB
/
feeder.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
59
60
package main
import (
"context"
"fmt"
"log"
"os"
"strconv"
"time"
"github.com/joho/godotenv"
alliance_provider "github.com/terra-money/oracle-feeder-go/internal/provider/alliance"
"github.com/terra-money/oracle-feeder-go/internal/types"
)
func main() {
// Load the environment variables
err := godotenv.Load()
if err != nil {
log.Print("Error loading .env file:", err)
}
retries := 3
if feederRetries := os.Getenv("FEEDER_RETRIES"); feederRetries != "" {
retries, err = strconv.Atoi(feederRetries)
if err != nil {
log.Fatal("Error parsing FEEDER_RETRIES:", err)
}
}
// Read the cli arguments
if len(os.Args) != 2 || os.Args[1] == "" {
log.Fatal(`Specify the first argument as the feeder type.`)
}
feederType, err := types.ParseFeederTypeFromString(os.Args[1])
if err != nil {
log.Fatal(err)
}
ctx := context.Background()
alliancesQuerierProvider := alliance_provider.NewAlliancesQuerierProvider(feederType)
for attempt := 1; attempt <= retries; attempt++ {
txHash, err := alliancesQuerierProvider.SubmitTx(ctx)
if err == nil {
fmt.Printf("Transaction Submitted successfully txHash: %s \n", txHash)
break
} else {
// Code execution failed
fmt.Printf("Attempt %d failed: %v\n", attempt, err)
if attempt == retries {
fmt.Println("All attempts failed. Exiting...")
break
}
fmt.Printf("Retrying in 15 seconds...\n")
time.Sleep(15 * time.Second)
}
}
}