forked from planetdecred/godcr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
94 lines (76 loc) · 1.77 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"image"
"net/http"
"os"
"path/filepath"
"strings"
"gioui.org/app"
_ "net/http/pprof"
"github.com/planetdecred/dcrlibwallet"
"github.com/planetdecred/godcr/ui"
"github.com/planetdecred/godcr/wallet"
)
func main() {
cfg, err := loadConfig()
if err != nil {
fmt.Printf("Error: %s\n", err.Error())
return
}
if cfg.Profile > 0 {
go func() {
log.Info(fmt.Sprintf("Starting profiling server on port %d", cfg.Profile))
log.Error(http.ListenAndServe(fmt.Sprintf("127.0.0.1:%d", cfg.Profile), nil))
}()
}
dcrlibwallet.SetLogLevels(cfg.DebugLevel)
absoluteWdPath, err := ui.GetAbsolutePath()
if err != nil {
panic(err)
}
decredIcons := make(map[string]image.Image)
err = filepath.Walk(filepath.Join(absoluteWdPath, "ui/assets/decredicons"), func(path string, info os.FileInfo, err error) error {
if err != nil {
panic(err)
}
if info.IsDir() || !strings.HasSuffix(path, ".png") {
return nil
}
f, _ := os.Open(path)
img, _, err := image.Decode(f)
if err != nil {
return err
}
split := strings.Split(info.Name(), ".")
decredIcons[split[0]] = img
return nil
})
if err != nil {
log.Warn(err)
}
var confirms int32 = dcrlibwallet.DefaultRequiredConfirmations
if cfg.SpendUnconfirmed {
confirms = 0
}
wal, err := wallet.NewWallet(cfg.HomeDir, cfg.Network, make(chan wallet.Response, 3), confirms)
if err != nil {
log.Error(err)
return
}
shutdown := make(chan int)
go func() {
<-shutdown
wal.Shutdown()
os.Exit(0)
}()
collection := fontCollection()
win, appWindow, err := ui.CreateWindow(wal, decredIcons, collection, internalLog)
if err != nil {
fmt.Printf("Could not initialize window: %s\ns", err)
return
}
// Start the ui frontend
go win.Loop(appWindow, shutdown)
app.Main()
}