Skip to content

Commit d3aaebe

Browse files
committed
nit: etherlink retry error
1 parent 915728c commit d3aaebe

File tree

1 file changed

+13
-5
lines changed
  • models/aggregated_block_feed/redstone_price_feed

1 file changed

+13
-5
lines changed

models/aggregated_block_feed/redstone_price_feed/command.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,16 @@ import (
99
"github.com/Gearbox-protocol/sdk-go/log"
1010
)
1111

12+
// retry 2 times and if error then fatal
1213
func GetRedStoneResult(data []byte, block int64, rpc string) []byte {
14+
bytes, err := getRedStoneResult(data, block, rpc) // try 1
15+
if err != nil {
16+
bytes, err = getRedStoneResult(data, block, rpc) // try 2
17+
log.CheckFatal(err)
18+
}
19+
return bytes
20+
}
21+
func getRedStoneResult(data []byte, block int64, rpc string) ([]byte, error) {
1322
// Define the command and its arguments.
1423
// The first argument to exec.Command is the command itself,
1524
// and subsequent arguments are passed to that command.
@@ -31,14 +40,14 @@ func GetRedStoneResult(data []byte, block int64, rpc string) []byte {
3140
output, err := cmd.Output()
3241
if err != nil {
3342
log.Info(strings.Join(cmdstr, " "))
34-
log.Fatalf("Error executing command: %v", err)
43+
return nil, err
3544
}
3645

3746
// Convert output to string and get the last line
3847
outputStr := string(output)
3948
lines := strings.Split(strings.TrimSpace(outputStr), "\n")
4049
if len(lines) == 0 {
41-
return nil
50+
return nil, fmt.Errorf("no output from command")
4251
}
4352
lastLine := ""
4453
for _, line := range lines {
@@ -52,9 +61,8 @@ func GetRedStoneResult(data []byte, block int64, rpc string) []byte {
5261
// Convert hex string to bytes
5362
bytes, err := hex.DecodeString(spls[1])
5463
if err != nil {
55-
log.Errorf("Error decoding hex string: %v", err)
56-
return nil
64+
return nil, fmt.Errorf("Error decoding hex string: %v", err)
5765
}
5866

59-
return bytes[len(bytes)-5*32:]
67+
return bytes[len(bytes)-5*32:], nil
6068
}

0 commit comments

Comments
 (0)