blockchain sandbox: UTXO chain, p2p mining, attacker node
This commit is contained in:
@@ -0,0 +1,24 @@
|
||||
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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user