-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
69 lines (51 loc) · 1.34 KB
/
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"math/rand"
"time"
"github.com/Flur3x/go-chain/api"
"github.com/Flur3x/go-chain/blockchain"
"github.com/Flur3x/go-chain/miner"
"github.com/Flur3x/go-chain/transactions"
"github.com/Flur3x/go-chain/wallet"
logging "github.com/op/go-logging"
)
var log = logging.MustGetLogger("")
var errorReport = make(chan error)
func main() {
go runSimulation()
handleErrors()
}
func runSimulation() {
blockchain.New()
myWallet, err := wallet.New()
if err != nil {
errorReport <- err
}
foreignWallet, err := wallet.New()
if err != nil {
errorReport <- err
}
log.Infof("\nWallets created:\n%+v\n%+v\n", myWallet, foreignWallet)
go api.Start(errorReport)
go miner.Start(errorReport)
log.Info("Simulation started 🌈\n\nFake Transactions are being created and Blocks mined ...\n\n")
for range time.NewTicker(5 * time.Second).C {
randomAmount := uint64(rand.Int63n(10000))
fakeTransaction, err := transactions.New(myWallet.Address, foreignWallet.Address, randomAmount, myWallet)
if err != nil {
errorReport <- err
}
transactions.UpdateOrAdd(fakeTransaction)
}
}
func handleErrors() {
defer func() {
if r := recover(); r != nil {
log.Errorf("%+v\n", r)
log.Infof("More detailed logs in the errors.log file\n")
}
}()
for r := range errorReport {
panic("Client crashed. Error: " + r.Error())
}
}