- // Create a new scanner for parsing incoming bytes into transaction tokens
- scanner := bufio.NewScanner(ui.HLClient.Connection)
- scanner.Split(transactionScanner)
-
- // Scan for new transactions and handle them as they come in.
- for scanner.Scan() {
- // Make a new []byte slice and copy the scanner bytes to it. This is critical to avoid a data race as the
- // scanner re-uses the buffer for subsequent scans.
- buf := make([]byte, len(scanner.Bytes()))
- copy(buf, scanner.Bytes())
-
- var t Transaction
- _, err := t.Write(buf)
- if err != nil {
- break
- }
- if err := ui.HLClient.HandleTransaction(&t); err != nil {
- ui.HLClient.Logger.Errorw("Error handling transaction", "err", err)
- }