Example #1
0
func (m *Miner) Start() {
	for {
		bytes, err := m.client.Read()
		if err != nil {
			log.Printf("quit miner due to :%v", err)
			break
		}

		msg, err := bitcoin.FromBytes(bytes)
		if err != nil {
			continue // ignore invalid request
		}

		m.handleMessage(msg)
	}

	log.Printf("quit miner")
}
Example #2
0
func NewEventParser() impl.EventParser {
	return func(id int, payload []byte, err error) *impl.Event {
		if err != nil {
			return impl.NewConnLostEvent(id, err)
		}

		msg, _ := bitcoin.FromBytes(payload)
		switch msg.Type {
		case bitcoin.Request:
			return impl.NewClientRequestEvent(id, msg)
		case bitcoin.Join:
			return impl.NewWorkerJoinEvent(id)
		case bitcoin.Result:
			return impl.NewWorkerDoneEvent(id, msg)
		default:
			return impl.NewNilEvent()
		}
	}
}
Example #3
0
func (c *Client) Start() {
	go func() {
		for {
			data, err := c.client.Read()
			if err != nil {
				log.Printf("quit client due to %v", err)
				printDisconnected()
				break
			}

			msg, err := bitcoin.FromBytes(data)
			if err != nil {
				log.Printf("invalid message from server %v", err)
				continue
			}

			c.handleMessage(msg)
			break
		}

		c.done <- true
	}()
}