Skip to content

Commit

Permalink
feat: mismatch madness
Browse files Browse the repository at this point in the history
  • Loading branch information
hanjukim committed Mar 8, 2022
1 parent 105d6c6 commit 959dc61
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions faucet.go
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ func checkAndUpdateLimit(db *leveldb.DB, account []byte, denom string) error {
return nil
}

func drip(encodedAddress string, denom string, amount int64) []byte {
func drip(encodedAddress string, denom string, amount int64, isDetectMismatch bool) []byte {
url := fmt.Sprintf("%v/bank/accounts/%v/transfers", lcdURL, encodedAddress)
data := strings.TrimSpace(fmt.Sprintf(`{
"base_req": {
Expand Down Expand Up @@ -328,11 +328,11 @@ func drip(encodedAddress string, denom string, amount int64) []byte {
if response.StatusCode != 200 {
stringBody := string(body)

if strings.Contains(stringBody, "sequence mismatch") {
if isDetectMismatch && strings.Contains(stringBody, "sequence mismatch") {
return make([]byte, 0)
}

err := errors.New(string(body))
err := errors.New(stringBody)
panic(err)
}

Expand Down Expand Up @@ -391,13 +391,19 @@ func createGetCoinsHandler(db *leveldb.DB) http.HandlerFunc {

// send the coins!
if captchaPassed {
body := drip(encodedAddress, claim.Denom, amount)
body := drip(encodedAddress, claim.Denom, amount, true)

// Sequence mismatch if the body length is zero
if len(body) == 0 {
// Reload for self healing and re-drip
loadAccountInfo()
body = drip(encodedAddress, claim.Denom, amount)
body = drip(encodedAddress, claim.Denom, amount, true)

// Another try without loading....
if len(body) == 0 {
sequence = sequence + 1
body = drip(encodedAddress, claim.Denom, amount, false)
}
}

resJSON := signAndBroadcast(body)
Expand Down

0 comments on commit 959dc61

Please sign in to comment.