Skip to content

Commit

Permalink
Merge branch 'uddugteam:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
andskur authored Feb 28, 2024
2 parents 201d279 + a4e2311 commit 69189bf
Showing 1 changed file with 24 additions and 23 deletions.
47 changes: 24 additions & 23 deletions internal/service/sender.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,35 @@ func (s *coinAveragePriceSender) sendARGPrice(stop chan struct{}) {
logTrace("stop...", "sendARGPrice")
return
default:
logTrace("sending prices...", "sendARGPrice")
epoch, err := s.flare.GetCurrentPriceEpochData()
if err != nil {
logErr(fmt.Sprintln("err get epoch:", err.Error()), "sendARGPrice")
time.Sleep(time.Second * 1)
continue
}

sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60))
random := s.getRandom()
go s.send()
time.Sleep(time.Minute * 3)
}
}
}

s.mu.Lock()
prices := s.currentPrices()
s.mu.Unlock()
func (s *coinAveragePriceSender) send() {
logTrace("sending prices...", "send")
epoch, err := s.flare.GetCurrentPriceEpochData()
if err != nil {
logErr(fmt.Sprintln("err get epoch:", err.Error()), "send")
time.Sleep(time.Second * 1)
return
}

logTrace(fmt.Sprintf("commiting prices"), "sendARGPrice")
if err := s.flare.CommitPrices(epoch.EpochID, s.tokens, prices, random); err != nil {
time.Sleep(time.Second * 1)
continue
}
sleep, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.RevealEndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()-60))
random := s.getRandom()

go s.reveal(sleep, epoch.EpochID, s.tokens, prices, random)
s.mu.Lock()
prices := s.currentPrices()
s.mu.Unlock()

wait, _ := time.ParseDuration(fmt.Sprintf("%vs", epoch.EndTimestamp.Uint64()-epoch.CurrentTimestamp.Uint64()+60))
logTrace(fmt.Sprintf("sleep send prices for %v", wait), "sendARGPrice")
time.Sleep(wait)
}
logTrace(fmt.Sprintf("commiting prices"), "send")
if err := s.flare.CommitPrices(epoch.EpochID, s.tokens, prices, random); err != nil {
time.Sleep(time.Second * 1)
return
}

go s.reveal(sleep, epoch.EpochID, s.tokens, prices, random)
}

// reveal will wait the sleep time and then call the reveal smart-contract method
Expand Down

0 comments on commit 69189bf

Please sign in to comment.