25 lines
643 B
Go
25 lines
643 B
Go
package p2p
|
|
|
|
import "time"
|
|
|
|
type Event struct {
|
|
Type string `json:"type"` // "block_accept", "block_reject", "block_mine"
|
|
Node string `json:"node"` // short ID
|
|
BlockHash string `json:"block_hash"` // first 8 chars
|
|
Height int `json:"height"`
|
|
From string `json:"from"` // who sent it (short ID), empty if mined
|
|
Ts int64 `json:"ts"` // unix ms
|
|
TxCount int `json:"tx_count"`
|
|
}
|
|
|
|
// Global event stream. Buffered so nodes never block.
|
|
var Events = make(chan Event, 1000)
|
|
|
|
func emit(e Event) {
|
|
e.Ts = time.Now().UnixMilli()
|
|
select {
|
|
case Events <- e:
|
|
default: // drop if nobody listens
|
|
}
|
|
}
|