-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
37 lines (28 loc) · 838 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package main
import (
"fmt"
"math/rand"
"github.com/echenim/AvalancheConsensusProtocol/pkg/avalanche"
)
func main() {
// Create a new network with 10 nodes
network := avalanche.NewNetwork(10)
// Generate a random transaction
tx := avalanche.RandomTransaction()
// Print the transaction details
fmt.Printf("Transaction: %+v\n", tx)
fmt.Printf("Transaction Hash: %s\n", tx.Hash())
// Run the network in a separate goroutine
go network.Run()
// Simulate sending a transaction to a node
node := network.Nodes[0]
node.HandleMessage(1, avalanche.MessageTransaction{Tx: tx})
// Generate conflicting transaction
conflictingTx := &avalanche.Transaction{
Nonce: tx.Nonce,
Data: int32(rand.Intn(10)),
}
node.HandleMessage(1, avalanche.MessageTransaction{Tx: conflictingTx})
// Keep the program running
select {}
}