blockchain sandbox: UTXO chain, p2p mining, attacker node

This commit is contained in:
2026-07-26 20:37:26 +03:00
commit 7ce39c8964
18 changed files with 2536 additions and 0 deletions
+24
View File
@@ -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
}
}