Skip to content

Commit

Permalink
Merge pull request #77 from terra-money/fix/regex-patterns
Browse files Browse the repository at this point in the history
fix: updated response patterns
  • Loading branch information
tuky191 authored Oct 11, 2023
2 parents 0a3e09e + 10bec86 commit d2c2f14
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,15 @@ func loadAccountInfo() {
var seq uint64

if strings.Contains(bodyStr, `"sequence"`) {
seq, _ = strconv.ParseUint(parseRegexp(`"sequence": "?(\d+)"?`, bodyStr), 10, 64)
seq, _ = strconv.ParseUint(parseRegexp(`"sequence": ?"?(\d+)"?`, bodyStr), 10, 64)
} else {
seq = 0
}

sequence = atomic.LoadUint64(&seq)

if strings.Contains(bodyStr, `"account_number"`) {
accountNumber, _ = strconv.ParseUint(parseRegexp(`"account_number": "?(\d+)"?`, bodyStr), 10, 64)
accountNumber, _ = strconv.ParseUint(parseRegexp(`"account_number": ?"?(\d+)"?`, bodyStr), 10, 64)
} else {
accountNumber = 0
}
Expand Down Expand Up @@ -195,7 +195,7 @@ func parseRegexp(regexpStr string, target string) (data string) {
groups := r.FindStringSubmatch(string(target))

if len(groups) != 2 {
os.Exit(1)
panic(fmt.Errorf("regex did not match %s, %s", regexpStr, target))
}

// Convert sequence string to int64
Expand Down Expand Up @@ -477,12 +477,12 @@ func signAndBroadcast(txBuilder client.TxBuilder, isDetectMismatch bool) string
panic(err)
}

code, err := strconv.ParseUint(parseRegexp(`"code": ?(\d+)?`, stringBody), 10, 64)
code, err := strconv.ParseUint(parseRegexp(`"code": ?"?(\d+)"?`, stringBody), 10, 64)
if err != nil {
panic("failed to parse code from tx response")
}
if code != 0 {
panic(parseRegexp(`"raw_log": "?(\d+)"?`, stringBody))
panic(parseRegexp(`"raw_log": ?"?(\d+)"?`, stringBody))
}

if isDetectMismatch && strings.Contains(stringBody, "sequence mismatch") {
Expand Down

0 comments on commit d2c2f14

Please sign in to comment.