Run can be called at most once to start a loop to submit and verify claims after an interval. If the loop has not been started, it starts the loop and return true, it return false otherwise.
()
| 210 | // If the loop has not been started, it starts the loop and return true, it |
| 211 | // return false otherwise. |
| 212 | func (sp *SmartPool) Run() bool { |
| 213 | sp.runMu.Lock() |
| 214 | defer sp.runMu.Unlock() |
| 215 | if sp.Register(sp.MinerAddress) { |
| 216 | if sp.loopStarted { |
| 217 | smartpool.Output.Printf("Warning: calling Run() multiple times\n") |
| 218 | return false |
| 219 | } |
| 220 | err := sp.NetworkClient.Configure( |
| 221 | sp.ContractAddress, |
| 222 | sp.ExtraData, |
| 223 | ) |
| 224 | if err != nil { |
| 225 | return false |
| 226 | } |
| 227 | for { |
| 228 | if sp.NetworkClient.ReadyToMine() { |
| 229 | smartpool.Output.Printf("The network is ready for mining.\n") |
| 230 | sp.ticker = time.Tick(sp.SubmitInterval) |
| 231 | go sp.actOnTick() |
| 232 | break |
| 233 | } |
| 234 | smartpool.Output.Printf("The network is not ready for mining yet. Retry in 10s...\n") |
| 235 | time.Sleep(10 * time.Second) |
| 236 | } |
| 237 | sp.loopStarted = true |
| 238 | smartpool.Output.Printf("Share collector is running...") |
| 239 | return true |
| 240 | } else { |
| 241 | return false |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | func NewSmartPool( |
| 246 | pm smartpool.PoolMonitor, sr smartpool.ShareReceiver, |