MCPcopy Create free account
hub / github.com/DEROFDN/Engram / StartPulse

Function StartPulse

functions.go:285–451  ·  view source on GitHub ↗

Go routine to update the latest information from the connected daemon (Online Mode only)

()

Source from the content-addressed store, hash-verified

283
284// Go routine to update the latest information from the connected daemon (Online Mode only)
285func StartPulse() {
286 if !walletapi.Connected && engram.Disk != nil {
287 logger.Printf("[Network] Attempting network connection to: %s\n", walletapi.Daemon_Endpoint)
288 err := walletapi.Connect(session.Daemon)
289 if err != nil {
290 logger.Errorf("[Network] Failed to connect to: %s\n", walletapi.Daemon_Endpoint)
291 walletapi.Connected = false
292 closeWallet()
293 session.Window.SetContent(layoutAlert(1))
294 removeOverlays()
295 return
296 } else {
297 sentNotifications := false
298 walletapi.Connected = true
299 engram.Disk.SetOnlineMode()
300 session.BalanceText = canvas.NewText("", colors.Blue)
301 session.StatusText = canvas.NewText("", colors.Blue)
302 status.Connection.FillColor = colors.Gray
303 status.Sync.FillColor = colors.Gray
304
305 go func() {
306 count := 0
307 for engram.Disk != nil {
308 if walletapi.Get_Daemon_Height() < 1 || !walletapi.Connected {
309 logger.Printf("[Network] Attempting network connection to: %s\n", walletapi.Daemon_Endpoint)
310 err := walletapi.Connect(session.Daemon)
311 if err != nil {
312 // If we fail DEFAULT_DAEMON_RECONNECT_TIMEOUT+ times, display node communication layout err
313 if count >= DEFAULT_DAEMON_RECONNECT_TIMEOUT {
314 walletapi.Connected = false
315 closeWallet()
316 session.Window.SetContent(layoutAlert(1))
317 removeOverlays()
318 break
319 }
320 count++
321 logger.Errorf("[Network] Failed to connect to: %s (%d / %d)\n", walletapi.Daemon_Endpoint, count, DEFAULT_DAEMON_RECONNECT_TIMEOUT)
322 walletapi.Connected = false
323 status.Connection.FillColor = colors.Red
324 status.Sync.FillColor = colors.Red
325 status.Gnomon.FillColor = colors.Red
326 status.EPOCH.FillColor = colors.Red
327 session.Offline = true
328
329 time.Sleep(time.Second)
330 continue
331 } else {
332 count = 0
333 time.Sleep(time.Second)
334 session.Offline = false
335 }
336 }
337
338 if !engram.Disk.IsRegistered() {
339 if !walletapi.Connected {
340 logger.Errorf("[Network] Could not connect to daemon...%d\n", engram.Disk.Get_Daemon_TopoHeight())
341 status.Connection.FillColor = colors.Red
342 status.Connection.Refresh()

Callers 1

loginFunction · 0.85

Calls 6

closeWalletFunction · 0.85
layoutAlertFunction · 0.85
removeOverlaysFunction · 0.85
getGnomonFunction · 0.85
startGnomonFunction · 0.85
RefreshMethod · 0.80

Tested by

no test coverage detected