/
main.go
130 lines (109 loc) · 2.63 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"fmt"
"image"
"net/http"
"os"
"path"
"path/filepath"
"strings"
"gioui.org/font/gofont"
"gioui.org/font/opentype"
"gioui.org/text"
_ "net/http/pprof"
"gioui.org/app"
"github.com/raedahgroup/dcrlibwallet"
"github.com/raedahgroup/godcr/ui"
"github.com/raedahgroup/godcr/wallet"
)
func getAbsoultePath() (string, error) {
ex, err := os.Executable()
if err != nil {
return "", fmt.Errorf("error getting executable path: %s", err.Error())
}
exSym, err := filepath.EvalSymlinks(ex)
if err != nil {
return "", fmt.Errorf("error getting filepath after evaluating sym links")
}
return path.Dir(exSym), nil
}
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 := getAbsoultePath()
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
}
wal.LoadWallets()
shutdown := make(chan int)
go func() {
<-shutdown
wal.Shutdown()
os.Exit(0)
}()
var collection []text.FontFace
source, err := os.Open(filepath.Join(absoluteWdPath, "ui/assets/fonts/source_sans_pro_regular.otf"))
if err != nil {
fmt.Println("Failed to load font")
collection = gofont.Collection()
} else {
stat, err := source.Stat()
if err != nil {
fmt.Println(err)
}
bytes := make([]byte, stat.Size())
source.Read(bytes)
fnt, err := opentype.Parse(bytes)
if err != nil {
fmt.Println(err)
}
collection = append(collection, text.FontFace{Font: text.Font{}, Face: fnt})
}
win, err := ui.CreateWindow(wal, decredIcons, collection)
if err != nil {
fmt.Printf("Could not initialize window: %s\ns", err)
return
}
// Start the ui frontend
go win.Loop(shutdown)
app.Main()
}