fix: same address in cron
This commit is contained in:
parent
da6ba29817
commit
05de71a2d6
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
.env
|
||||||
35
main.go
35
main.go
@ -16,20 +16,28 @@ import (
|
|||||||
func main() {
|
func main() {
|
||||||
godotenv.Load() //nolint:errcheck
|
godotenv.Load() //nolint:errcheck
|
||||||
|
|
||||||
address := strings.Split(os.Getenv("ADDRESS"), ",")
|
wallets := strings.Split(os.Getenv("ADDRESS"), ",")
|
||||||
|
|
||||||
s := gocron.NewScheduler(time.UTC)
|
s := gocron.NewScheduler(time.UTC)
|
||||||
|
|
||||||
for _, a := range address {
|
for _, w := range wallets {
|
||||||
|
run(s, w)
|
||||||
|
}
|
||||||
|
|
||||||
|
s.StartBlocking()
|
||||||
|
}
|
||||||
|
|
||||||
|
func run(s *gocron.Scheduler, w string) {
|
||||||
s.Every(6).Hours().Do(func() { //nolint:errcheck
|
s.Every(6).Hours().Do(func() { //nolint:errcheck
|
||||||
url := "https://faucet.devnet.sui.io/gas"
|
url := "https://faucet.devnet.sui.io/gas"
|
||||||
|
|
||||||
request := `{"FixedAmountRequest":{"recipient":"` + a + `"}}`
|
request := `
|
||||||
|
{"FixedAmountRequest":{"recipient":"` + w + `"}}
|
||||||
|
`
|
||||||
|
|
||||||
resp, err := http.Post(url, "application/json", strings.NewReader(request))
|
resp, err := http.Post(url, "application/json", strings.NewReader(request))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("error sending request")
|
log.Err(err).Str("wallet", w).Msg("error sending request")
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
@ -38,8 +46,7 @@ func main() {
|
|||||||
|
|
||||||
body, err := io.ReadAll(resp.Body)
|
body, err := io.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("error reading response body")
|
log.Err(err).Str("wallet", w).Msg("error reading response body")
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if resp.StatusCode == http.StatusCreated {
|
if resp.StatusCode == http.StatusCreated {
|
||||||
@ -54,15 +61,15 @@ func main() {
|
|||||||
var d Data
|
var d Data
|
||||||
err = json.Unmarshal(body, &d)
|
err = json.Unmarshal(body, &d)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Err(err).Msg("error unmarshalling data")
|
log.Err(err).Str("wallet", w).Msg("error unmarshalling data")
|
||||||
panic(err)
|
|
||||||
}
|
}
|
||||||
log.Info().Msg("Claim successful!")
|
log.Info().Str("wallet", w).Msg("Claim successful!")
|
||||||
} else {
|
} else {
|
||||||
log.Error().Msg(string(body))
|
if string(body) == "error code: 1015" {
|
||||||
|
log.Info().Str("wallet", w).Msg("Claim already made!")
|
||||||
|
} else {
|
||||||
|
log.Error().Str("wallet", w).Msg(string(body))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
|
||||||
|
|
||||||
s.StartBlocking()
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user