forked from DEROFDN/Engram
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
202 lines (175 loc) · 6.73 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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
// Copyright 2023-2024 DERO Foundation. All rights reserved.
// Use of this source code in any form is governed by RESEARCH license.
// license can be found in the LICENSE file.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
// THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
// STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
package main
import (
"fmt"
"image/color"
"os"
"runtime"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/driver/mobile"
"github.com/blang/semver"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/walletapi"
)
// Constants
const (
DEFAULT_TESTNET_WALLET_PORT = 40403
DEFAULT_TESTNET_DAEMON_PORT = 40402
DEFAULT_TESTNET_WORK_PORT = 40400
DEFAULT_WALLET_PORT = 10103
DEFAULT_DAEMON_PORT = 10102
DEFAULT_WORK_PORT = 10100
DEFAULT_LOCAL_TESTNET_DAEMON = "127.0.0.1:40402"
DEFAULT_LOCAL_TESTNET_P2P = "127.0.0.1:40401"
DEFAULT_LOCAL_TESTNET_WORK = "0.0.0.0:40400"
DEFAULT_REMOTE_TESTNET_DAEMON = "testnetexplorer.dero.io:40402"
DEFAULT_LOCAL_DAEMON = "127.0.0.1:10102"
DEFAULT_LOCAL_P2P = "127.0.0.1:10101"
DEFAULT_LOCAL_WORK = "0.0.0.0:10100"
DEFAULT_REMOTE_DAEMON = "node.derofoundation.org:11012"
DEFAULT_CONFIRMATION_TIMEOUT = 5
)
// Globals
var version = semver.MustParse("0.5.2")
var a fyne.App
var engram Engram
var session Session
var gnomon Gnomon
var messages Messages
var status Status
var tx Transfers
var res Res
var colors Colors
var cyberdeck Cyberdeck
var themes Theme
var rpc_client Client
var Connected bool
var nav Navigation
var ui UI
func main() {
// Initialize application
a = app.NewWithID("io.dero.engram") // Engram
a.Settings().SetTheme(themes.main)
session.Window = a.NewWindow("Engram")
session.Window.SetMaster()
session.Window.SetCloseIntercept(func() {
if engram.Disk != nil {
closeWallet()
}
session.Window.Close()
os.Exit(0)
})
session.Window.SetPadded(false)
session.Domain = "app.main.loading"
session.Window.CenterOnScreen()
// Load resources
loadResources()
a.SetIcon(resourceIconPng)
session.Window.SetIcon(resourceIconPng)
// Init colors
colors.Network = color.RGBA{R: 67, G: 239, B: 67, A: 255}
colors.Account = color.RGBA{R: 233, G: 228, B: 233, A: 0xff}
colors.DarkMatter = color.RGBA{21, 23, 30, 255}
colors.Red = color.RGBA{R: 214, B: 74, G: 70, A: 255}
colors.DarkGreen = color.RGBA{17, 127, 78, 0xff}
colors.Green = color.RGBA{19, 202, 105, 0xff}
colors.Blue = color.RGBA{R: 27, B: 249, G: 127, A: 255}
colors.Gray = color.RGBA{R: 99, B: 110, G: 99, A: 0xff}
colors.Yellow = color.RGBA{244, 208, 11, 255}
colors.Cold = color.RGBA{60, 73, 92, 255}
colors.Flint = color.RGBA{44, 44, 52, 0xff}
// Init objects
status.Canvas = canvas.NewText("", colors.Network)
status.Network = canvas.NewText("", colors.Network)
session.BalanceText = canvas.NewText("", colors.Account)
status.Connection = canvas.NewCircle(colors.Red)
status.Connection.StrokeColor = colors.Red
status.Connection.StrokeWidth = 0
status.Connection.Refresh()
status.Sync = canvas.NewCircle(colors.Red)
status.Sync.StrokeColor = colors.Red
status.Sync.StrokeWidth = 0
status.Sync.Refresh()
status.Cyberdeck = canvas.NewCircle(colors.Red)
status.Cyberdeck.StrokeColor = colors.Red
status.Cyberdeck.StrokeWidth = 0
status.Cyberdeck.Refresh()
fmt.Printf("Engram v%s (Beta)\n", version)
fmt.Printf("Copyright 2023-2024 DERO Foundation. All rights reserved.\n")
fmt.Printf("OS: %s ARCH: %s GOMAXPROCS: %d\n\n", runtime.GOOS, runtime.GOARCH, runtime.GOMAXPROCS(0))
fmt.Printf("\"Insist on yourself; never imitate. Your own gift you can present every moment with the \ncumulative force of a whole life's cultivation; but of the adopted talent of another, \nyou have only an extemporaneous, half possession.\"\n\n")
// Map arguments for DERO network (TODO: Fully support console arguments)
globals.Arguments = make(map[string]interface{})
globals.Arguments["--debug"] = false
globals.Arguments["--testnet"] = false
globals.Arguments["--daemon-address"] = "127.0.0.1:10102"
globals.Arguments["--p2p-bind"] = "127.0.0.1:10101"
globals.Arguments["--rpc-server"] = true
globals.Arguments["--rpc-bind"] = "127.0.0.1:10103"
globals.Arguments["--allow-rpc-password-change"] = true
globals.Arguments["--rpc-login"] = newRPCUsername() + ":" + newRPCPassword()
globals.Arguments["--offline"] = false
globals.Arguments["--remote"] = false
initSettings()
globals.Initialize()
session.Domain = "app.main"
// Intercept mobile back button event
session.Window.Canvas().SetOnTypedKey(func(ev *fyne.KeyEvent) {
if ev.Name == mobile.KeyBack {
if session.LastDomain != nil {
session.Window.SetContent(layoutTransition())
session.Window.SetContent(session.LastDomain)
} else {
if engram.Disk != nil {
session.LastDomain = layoutDashboard()
session.LastDomain = session.Window.Content()
session.Window.SetContent(layoutTransition())
session.Window.SetContent(layoutDashboard())
} else {
session.LastDomain = layoutMain()
session.LastDomain = session.Window.Content()
session.Window.SetContent(layoutTransition())
session.Window.SetContent(layoutMain())
}
}
}
})
// Check if mobile device
if a.Driver().Device().IsMobile() {
go walletapi.Initialize_LookupTable(1, 1<<21)
ui.MaxWidth = 3600
ui.MaxHeight = 6800
ui.Width = ui.MaxWidth * 0.9
ui.Height = ui.MaxHeight
ui.Padding = ui.MaxWidth * 0.05
resizeWindow(ui.MaxWidth, ui.MaxHeight)
session.Window.SetContent(layoutFrame())
session.Window.SetFixedSize(true)
session.Window.ShowAndRun()
} else {
go walletapi.Initialize_LookupTable(1, 1<<24)
ui.MaxWidth = 360
ui.MaxHeight = 680
ui.Width = ui.MaxWidth * 0.9
ui.Height = ui.MaxHeight
ui.Padding = ui.MaxWidth * 0.05
resizeWindow(ui.MaxWidth, ui.MaxHeight)
session.Window.SetContent(layoutMain())
session.Window.SetFixedSize(true)
session.Window.ShowAndRun()
}
}