-
Notifications
You must be signed in to change notification settings - Fork 8
/
functions.go
2483 lines (2084 loc) · 70.2 KB
/
functions.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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 (
"context"
"crypto/rand"
"crypto/sha1"
"encoding/base64"
"encoding/json"
"errors"
"fmt"
"image/color"
"io"
"math/big"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"sort"
"strconv"
"strings"
"time"
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/canvas"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/data/binding"
"fyne.io/fyne/v2/widget"
x "fyne.io/x/fyne/widget"
"github.com/civilware/Gnomon/indexer"
"github.com/civilware/Gnomon/rwc"
"github.com/civilware/Gnomon/structures"
"github.com/creachadair/jrpc2"
"github.com/creachadair/jrpc2/channel"
"github.com/gorilla/websocket"
"mvdan.cc/xurls/v2"
"github.com/civilware/Gnomon/storage"
"github.com/deroproject/derohe/config"
"github.com/deroproject/derohe/cryptography/crypto"
"github.com/deroproject/derohe/dvm"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/proof"
"github.com/deroproject/derohe/rpc"
"github.com/deroproject/derohe/transaction"
"github.com/deroproject/derohe/walletapi"
"github.com/deroproject/derohe/walletapi/mnemonics"
"github.com/deroproject/derohe/walletapi/rpcserver"
)
type App struct {
App fyne.App
Window fyne.Window
Focus bool
}
type UI struct {
Padding float32
MaxWidth float32
Width float32
MaxHeight float32
Height float32
}
type Colors struct {
Network color.Color
Account color.Color
Blue color.Color
Red color.Color
DarkGreen color.Color
Green color.Color
Gray color.Color
Yellow color.Color
DarkMatter color.Color
Cold color.Color
Flint color.Color
}
type Navigation struct {
PosX float32
PosY float32
CurX float32
CurY float32
}
type Session struct {
Window fyne.Window
DesktopMode bool
Domain string
LastDomain fyne.CanvasObject
Testnet bool
Offline bool
Language int
ID string
Link string
Type string
Daemon string
WalletOpen bool
Username string
Datapad string
DatapadChanged bool
LastBalance uint64
Balance uint64
BalanceUSD string
BalanceText *canvas.Text
BalanceUSDText *canvas.Text
ModeText *canvas.Text
IDText *canvas.Text
LinkText *canvas.Text
StatusText *canvas.Text
Path string
Name string
Password string
PasswordConfirm string
DaemonHeight uint64
WalletHeight uint64
RPCServer *rpcserver.RPCServer
Verified bool
Dashboard string
Error string
NewUser string
Gif *x.AnimatedGif
RegHashes int64
LimitMessages bool
TrackRecentBlocks int64
}
type Cyberdeck struct {
user string
pass string
userText *widget.Entry
passText *widget.Entry
toggle *widget.Button
status *canvas.Text
server *rpcserver.RPCServer
}
type Engram struct {
Disk *walletapi.Wallet_Disk
}
type Theme struct {
main eTheme
alt eTheme2
}
type Gnomon struct {
Active int
Index *indexer.Indexer
BBolt *storage.BboltStore
Graviton *storage.GravitonStore
Path string
}
type ProofData struct {
Receivers []string
Amounts []uint64
Payloads []string
}
type Status struct {
Canvas *canvas.Text
Message string
Network *canvas.Text
Connection *canvas.Circle
Sync *canvas.Circle
Cyberdeck *canvas.Circle
}
type Transfers struct {
Address *rpc.Address
PaymentID uint64
Amount uint64
Comment string
GasStorage uint64
Fees uint64
Pending []rpc.Transfer
TX *transaction.Transaction
TXID crypto.Hash
Proof string
Ringsize uint64
SendAll bool
Size float32
Status string
OfflineTX bool
Filename string
}
type Messages struct {
Contact string
Data []string
Box *widget.List
List binding.ExternalStringList
Height uint64
Message string
}
type InstallContract struct {
TXID string
}
type Client struct {
WS *websocket.Conn
RPC *jrpc2.Client
}
// Get the Engram settings from the local Graviton tree
func initSettings() {
getTestnet()
getMode()
getDaemon()
getGnomon()
}
// Go routine to update the latest information from the connected daemon (Online Mode only)
func StartPulse() {
if !walletapi.Connected && engram.Disk != nil {
fmt.Printf("[Network] Attempting network connection to: %s\n", walletapi.Daemon_Endpoint)
err := walletapi.Connect(session.Daemon)
if err != nil {
fmt.Printf("[Network] Failed to connect to: %s\n", walletapi.Daemon_Endpoint)
walletapi.Connected = false
closeWallet()
session.Window.SetContent(layoutAlert(1))
removeOverlays()
return
} else {
walletapi.Connected = true
engram.Disk.SetOnlineMode()
session.BalanceText = canvas.NewText("", colors.Blue)
session.StatusText = canvas.NewText("", colors.Blue)
status.Connection.FillColor = colors.Gray
status.Connection.Refresh()
status.Sync.FillColor = colors.Gray
status.Sync.Refresh()
go func() {
for walletapi.Connected && engram.Disk != nil {
if walletapi.Get_Daemon_Height() < 1 {
fmt.Printf("[Network] Attempting network connection to: %s\n", walletapi.Daemon_Endpoint)
err := walletapi.Connect(session.Daemon)
if err != nil {
fmt.Printf("[Network] Failed to connect to: %s\n", walletapi.Daemon_Endpoint)
walletapi.Connected = false
closeWallet()
session.Window.SetContent(layoutAlert(1))
removeOverlays()
break
}
}
if !engram.Disk.IsRegistered() {
if !walletapi.Connected {
fmt.Printf("[Network] Could not connect to daemon...%d\n", engram.Disk.Get_Daemon_TopoHeight())
status.Connection.FillColor = colors.Red
status.Connection.Refresh()
status.Sync.FillColor = colors.Red
status.Sync.Refresh()
}
time.Sleep(time.Second)
} else {
session.Balance, _ = engram.Disk.Get_Balance()
session.BalanceText.Text = globals.FormatMoney(session.Balance)
session.BalanceText.Refresh()
session.WalletHeight = engram.Disk.Get_Height()
session.DaemonHeight = engram.Disk.Get_Daemon_Height()
session.StatusText.Text = fmt.Sprintf("%d", session.WalletHeight)
session.StatusText.Refresh()
if session.LastBalance != session.Balance && session.Balance != 0 {
go convertBalance()
}
session.LastBalance = session.Balance
if walletapi.IsDaemonOnline() {
status.Connection.FillColor = colors.Green
status.Connection.Refresh()
if session.DaemonHeight > 0 && session.DaemonHeight-session.WalletHeight < 2 {
status.Connection.FillColor = colors.Green
status.Connection.Refresh()
status.Sync.FillColor = colors.Green
status.Sync.Refresh()
} else if session.DaemonHeight == 0 {
status.Sync.FillColor = colors.Red
status.Sync.Refresh()
} else {
status.Sync.FillColor = colors.Yellow
status.Sync.Refresh()
}
} else {
status.Connection.FillColor = colors.Gray
status.Connection.Refresh()
status.Sync.FillColor = colors.Gray
status.Sync.Refresh()
status.Cyberdeck.FillColor = colors.Gray
status.Cyberdeck.Refresh()
fmt.Printf("[Network] Offline › Last Height: " + strconv.FormatUint(session.WalletHeight, 10) + " / " + strconv.FormatUint(session.DaemonHeight, 10) + "\n")
}
time.Sleep(time.Second)
}
}
if walletapi.Connected {
walletapi.Connected = false
}
}()
}
}
}
// Get Network setting from the local Graviton tree (Ex: Mainnet, Testnet, Simulator)
func getTestnet() bool {
result, err := GetValue("settings", []byte("network"))
if err != nil {
session.Testnet = false
globals.Arguments["--testnet"] = false
setTestnet(false)
return false
} else {
if string(result) == "Testnet" {
session.Testnet = true
globals.Arguments["--testnet"] = true
return true
} else {
session.Testnet = false
globals.Arguments["--testnet"] = false
return false
}
}
}
// Set Network setting to the local Graviton tree (Ex: Mainnet, Testnet, Simulator)
func setTestnet(b bool) (err error) {
s := ""
if !b {
s = "Mainnet"
globals.Arguments["--testnet"] = false
} else {
s = "Testnet"
globals.Arguments["--testnet"] = true
}
StoreValue("settings", []byte("network"), []byte(s))
return
}
// Get daemon endpoint setting from the local Graviton tree
func getDaemon() (r string) {
result, err := GetValue("settings", []byte("endpoint"))
if err != nil {
r = DEFAULT_REMOTE_DAEMON
setDaemon(r)
session.Daemon = r
globals.Arguments["--daemon-address"] = r
return
}
r = string(result)
session.Daemon = r
globals.Arguments["--daemon-address"] = r
return
}
// Set the daemon endpoint setting to the local Graviton tree
func setDaemon(s string) (err error) {
StoreValue("settings", []byte("endpoint"), []byte(s))
globals.Arguments["--daemon-address"] = s
session.Daemon = s
return
}
// Get mode (online, offline) setting from local Graviton tree
func getMode() {
/*
if globals.Arguments["--offline"].(bool) == true {
session.Mode = "Offline"
return
}
s := "mode"
t := "settings"
key := []byte(s)
result, err := GetValue(t, key)
if err != nil {
session.Mode = "Online"
err := setMode("Online")
globals.Arguments["--offline"] = false
if err != nil {
fmt.Printf("[Engram] Error: %s\n", err)
return
}
} else {
if result == nil {
session.Mode = "Online"
err := setMode("Online")
globals.Arguments["--offline"] = false
if err != nil {
fmt.Printf("[Engram] Error: %s\n", err)
return
}
} else {
if string(result) == "Offline" {
globals.Arguments["--offline"] = true
session.Mode = "Offline"
} else {
globals.Arguments["--offline"] = false
session.Mode = "Online"
}
}
}
*/
}
// Set the default Offline Mode settings to the local Graviton tree
func setMode(s string) (err error) {
err = StoreValue("settings", []byte("mode"), []byte(s))
if s == "Offline" {
globals.Arguments["--offline"] = true
} else {
globals.Arguments["--offline"] = false
}
return
}
// Get the default Gnomon settings from local Graviton tree
func getGnomon() (r string, err error) {
v, err := GetValue("settings", []byte("gnomon"))
if err != nil {
gnomon.Active = 1
if gnomon.Index != nil {
gnomon.Index.Endpoint = getDaemon()
}
StoreValue("settings", []byte("gnomon"), []byte("1"))
}
if string(v) == "1" {
gnomon.Active = 1
if gnomon.Index != nil {
gnomon.Index.Endpoint = getDaemon()
}
} else {
gnomon.Active = 0
}
r = string(v)
return
}
// Set the default Gnomon settings to the local Graviton tree
func setGnomon(s string) (err error) {
if s == "1" {
err = StoreValue("settings", []byte("gnomon"), []byte("1"))
gnomon.Active = 1
if gnomon.Index != nil {
gnomon.Index.Endpoint = getDaemon()
}
} else {
err = StoreValue("settings", []byte("gnomon"), []byte("0"))
gnomon.Active = 0
}
return
}
/*
func getAuthMode() (result string, err error) {
r, err := GetValue("settings", []byte("auth_mode"))
if err != nil {
StoreValue("settings", []byte("auth_mode"), []byte("true"))
cyberdeck.mode = 1
result = "true"
} else {
result = string(r)
if string(result) == "true" {
cyberdeck.mode = 1
result = "true"
} else {
cyberdeck.mode = 0
result = "false"
}
}
return
}
*/
// Get the auth_mode settings from local Graviton tree
func setAuthMode(s string) {
if s == "true" {
StoreValue("settings", []byte("auth_mode"), []byte("true"))
} else {
StoreValue("settings", []byte("auth_mode"), []byte("false"))
}
}
// Check if a URL exists in the string
func getTextURL(s string) (result []string) {
return xurls.Relaxed().FindAllString(s, -1)
}
// Set the window size from provided height and width
func resizeWindow(width float32, height float32) {
s := fyne.NewSize(width, height)
session.Window.Resize(s)
}
// Close the active wallet
func closeWallet() {
showLoadingOverlay()
if gnomon.Index != nil {
fmt.Printf("[Gnomon] Shutting down indexers...\n")
stopGnomon()
}
if engram.Disk != nil {
fmt.Printf("[Engram] Shutting down wallet services...\n")
engram.Disk.SetOfflineMode()
engram.Disk.Save_Wallet()
globals.Exit_In_Progress = true
engram.Disk.Close_Encrypted_Wallet()
session.WalletOpen = false
session.Domain = "app.main"
session.BalanceUSD = ""
session.LastBalance = 0
engram.Disk = nil
tx = Transfers{}
if cyberdeck.server != nil {
cyberdeck.server.RPCServer_Stop()
cyberdeck.server = nil
fmt.Printf("[Engram] Cyberdeck closed.\n")
}
if rpc_client.WS != nil {
rpc_client.WS.Close()
rpc_client.WS = nil
fmt.Printf("[Engram] Websocket client closed.\n")
}
if rpc_client.RPC != nil {
rpc_client.RPC.Close()
rpc_client.RPC = nil
fmt.Printf("[Engram] RPC client closed.\n")
}
session.Path = ""
session.Name = ""
session.LastDomain = layoutMain()
session.Window.SetContent(layoutTransition())
session.Window.SetContent(layoutMain())
removeOverlays()
//session.Window.CenterOnScreen()
fmt.Printf("[Engram] Wallet saved and closed successfully.\n")
return
}
}
// Create a new account and wallet file
func create() (address string, seed string, err error) {
check := findAccount()
if session.Path == "" {
session.Error = "Please enter an account name."
} else if session.Language == -1 {
session.Error = "Please select a language."
} else if session.Password == "" {
session.Error = "Please enter a password."
} else if session.PasswordConfirm == "" {
session.Error = "Please confirm your password."
} else if session.PasswordConfirm != session.Password {
session.Error = "Passwords do not match."
} else if check {
session.Error = "Account name already exists."
} else {
engram.Disk, err = walletapi.Create_Encrypted_Wallet_Random(session.Path, session.Password)
if err != nil {
session.Language = -1
session.Name = ""
session.Path = ""
session.Password = ""
session.PasswordConfirm = ""
session.Error = "Account could not be created."
} else {
if session.Testnet {
engram.Disk.SetNetwork(false)
globals.Arguments["--testnet"] = true
} else {
engram.Disk.SetNetwork(true)
globals.Arguments["--testnet"] = false
}
languages := mnemonics.Language_List()
if session.Language < 0 || session.Language > len(languages)-1 {
session.Language = 0 // English
}
engram.Disk.SetSeedLanguage(languages[session.Language])
address = engram.Disk.GetAddress().String()
seed = engram.Disk.GetSeed()
engram.Disk.Close_Encrypted_Wallet()
engram.Disk = nil
session.Error = "Account successfully created."
session.Language = -1
session.Name = ""
session.Path = ""
session.Password = ""
session.PasswordConfirm = ""
session.Domain = "app.main"
}
}
return
}
// The main login routine
func login() {
var err error
var temp *walletapi.Wallet_Disk
showLoadingOverlay()
if engram.Disk == nil {
temp, err = walletapi.Open_Encrypted_Wallet(session.Path, session.Password)
if err != nil {
temp = nil
session.Domain = "app.main"
session.Error = err.Error()
if len(session.Error) > 40 {
session.Error = fmt.Sprintf("%s...", session.Error[0:40])
}
session.Window.Canvas().Content().Refresh()
removeOverlays()
return
}
engram.Disk = temp
temp = nil
session.Password = ""
}
if session.Testnet {
engram.Disk.SetNetwork(false)
globals.Arguments["--testnet"] = true
} else {
engram.Disk.SetNetwork(true)
globals.Arguments["--testnet"] = false
}
session.WalletOpen = true
session.BalanceUSD = ""
session.LastBalance = 0
if !session.Offline {
walletapi.SetDaemonAddress(session.Daemon)
engram.Disk.SetDaemonAddress(session.Daemon)
if session.TrackRecentBlocks > 0 {
fmt.Printf("[Engram] Scan tracking enabled, only scanning the last %d blocks...\n", session.TrackRecentBlocks)
engram.Disk.SetTrackRecentBlocks(session.TrackRecentBlocks)
}
StartPulse()
} else {
engram.Disk.SetOfflineMode()
status.Connection.FillColor = colors.Gray
status.Connection.Refresh()
status.Sync.FillColor = colors.Gray
status.Sync.Refresh()
}
setRingSize(engram.Disk, 16)
session.Verified = false
if !session.Offline {
// Online mode
status.Connection.FillColor = colors.Green
status.Connection.Refresh()
session.Balance = 0
if !walletapi.Connected {
closeWallet()
session.Window.SetContent(layoutAlert(1))
removeOverlays()
return
}
if engram.Disk.Get_Height() < session.DaemonHeight {
time.Sleep(time.Second * 1)
}
for i := 0; i < 10; i++ {
reg := engram.Disk.Get_Registration_TopoHeight()
if reg < 1 {
time.Sleep(time.Second * 1)
} else {
break
}
if i == 9 {
registerAccount()
removeOverlays()
session.Verified = true
fmt.Printf("[Registration] Account registration PoW started...\n")
fmt.Printf("[Registration] Registering your account. This can take up to 120 minutes (one time). Please wait...\n")
return
}
}
go startGnomon()
}
if a.Driver().Device().IsMobile() {
session.Domain = "app.wallet"
resizeWindow(ui.MaxWidth, ui.MaxHeight)
}
session.Window.SetContent(layoutDashboard())
removeOverlays()
session.Balance, _ = engram.Disk.Get_Balance()
session.BalanceText.Text = globals.FormatMoney(session.Balance)
session.BalanceText.Refresh()
session.WalletHeight = engram.Disk.Wallet_Memory.Get_Height()
session.DaemonHeight = engram.Disk.Get_Daemon_Height()
session.StatusText.Text = fmt.Sprintf("%d", session.WalletHeight)
session.StatusText.Refresh()
if session.WalletHeight == session.DaemonHeight && !session.Offline {
status.Sync.FillColor = colors.Green
status.Sync.Refresh()
}
address := engram.Disk.GetAddress().String()
shard := fmt.Sprintf("%x", sha1.Sum([]byte(address)))
session.ID = shard
session.LimitMessages = true
}
// Remove all overlays
func removeOverlays() {
overlays := session.Window.Canvas().Overlays()
list := overlays.List()
for o := range list {
overlays.Remove(list[o])
}
if res.loading != nil {
res.loading.Hide()
res.loading.Stop()
res.loading = nil
}
}
// Add an overlay with the loading animation
func showLoadingOverlay() {
frame := &iframe{}
if res.loading == nil {
res.loading, _ = x.NewAnimatedGifFromResource(resourceLoadingGif)
res.loading.SetMinSize(fyne.NewSize(ui.Width*0.45, ui.Width*0.45))
}
rect := canvas.NewRectangle(colors.DarkMatter)
rect.SetMinSize(frame.Size())
background := container.NewStack(
rect,
container.NewCenter(
res.loading,
),
)
res.loading.Start()
layout := container.NewStack(
frame,
background,
)
overlays := session.Window.Canvas().Overlays()
overlays.Add(layout)
}
// Load embedded resources
func loadResources() {
res.bg = canvas.NewImageFromResource(resourceBgPng)
res.bg.FillMode = canvas.ImageFillContain
res.bg2 = canvas.NewImageFromResource(resourceBg2Png)
res.bg2.FillMode = canvas.ImageFillContain
res.icon = canvas.NewImageFromResource(resourceIconPng)
res.icon.FillMode = canvas.ImageFillContain
res.header = canvas.NewImageFromResource(resourceBackground1Png)
res.header.FillMode = canvas.ImageFillContain
res.load = canvas.NewImageFromResource(resourceLoadPng)
res.load.FillMode = canvas.ImageFillStretch
res.dero = canvas.NewImageFromResource(resourceDeroPng)
res.dero.FillMode = canvas.ImageFillContain
res.gram = canvas.NewImageFromResource(resourceGramPng)
res.gram.FillMode = canvas.ImageFillContain
res.block = canvas.NewImageFromResource(resourceBlockGrayPng)
res.block.FillMode = canvas.ImageFillContain
res.red_alert = canvas.NewImageFromResource(resourceRedAlertPng)
res.red_alert.FillMode = canvas.ImageFillContain
res.green_alert = canvas.NewImageFromResource(resourceGreenAlertPng)
res.green_alert.FillMode = canvas.ImageFillContain
}
// Reset UI resources
func resetResources() {
res = Res{}
loadResources()
}
// Get SC balance by SCID
func get_balance_SCID(s string) string {
b := ""
if s == "" {
b = "Balance: " + walletapi.FormatMoney(0)
return b
}
id := crypto.HashHexToHash(s)
balance, _, err := engram.Disk.GetDecryptedBalanceAtTopoHeight(id, -1, engram.Disk.GetAddress().String())
if err != nil {
b = "Balance: " + walletapi.FormatMoney(0)
} else {
b = "Balance: " + walletapi.FormatMoney(balance)
}
return b
}
// Check the transaction ring members to see if the provided address exists
func ring_member_exists(txid string, address string) bool {
if engram.Disk == nil || session.Offline {
return false
}
var err error
var tx_params rpc.GetTransaction_Params
var tx_result rpc.GetTransaction_Result
tx_params.Tx_Hashes = append(tx_params.Tx_Hashes, txid)
rpc_client.WS, _, err = websocket.DefaultDialer.Dial("ws://"+session.Daemon+"/ws", nil)
input_output := rwc.New(rpc_client.WS)
rpc_client.RPC = jrpc2.NewClient(channel.RawJSON(input_output, input_output), nil)
if err = rpc_client.RPC.CallResult(context.Background(), "DERO.GetTransaction", tx_params, &tx_result); err != nil {
fmt.Printf("[Messages] Checking ring members for TXID: %s (Failed: %s)\n", txid, err)
return false
}
rpc_client.WS.Close()
rpc_client.RPC.Close()
if tx_result.Status != "OK" {
fmt.Printf("[Messages] Checking ring members for TXID: %s (Failed: %s)\n", txid, tx_result.Status)
return false
}
if len(tx_result.Txs_as_hex[0]) < 50 {
return false
}
ring := tx_result.Txs[0].Ring
for i := 0; i < len(ring[0]); i++ {
if ring[0][i] == address {
fmt.Printf("[Messages] Checking ring members for TXID: %s (Verified)\n", txid)
return true
}
}
fmt.Printf("[Messages] Checking ring members for TXID: %s (Unverified - Skipping)\n", txid)
return false
}
// Get the recovery words (seed words) for an account
func display_seed() string {
seed := engram.Disk.GetSeed()
return seed
}
// Get the account public/private keys
func display_spend_key() (secret string, public string) {
keys := engram.Disk.Get_Keys()
secret = keys.Secret.Text(16)
public = keys.Public.StringHex()
return secret, public
}
// Detect and open URLs in default system browser
func openURL(url string, a *App) {
var err error
switch runtime.GOOS {
case "linux":
err = exec.Command("xdg-open", url).Start()
case "windows":
err = exec.Command("rundll32", "url.dll,FileProtocolHandler", url).Start()
case "darwin":
err = exec.Command("open", url).Start()
default:
err = exec.Command("open", url).Start()
}
if err != nil {
return
}
}
// Validate if the provided word is a seed word
func checkSeedWord(w string) (check bool) {
split := strings.Split(w, " ")
if len(split) > 1 {
return
}
_, _, _, check = mnemonics.Find_indices([]string{w})
return
}
// Add a DERO transfer to the batch
func addTransfer() error {
var arguments = rpc.Arguments{}
var err error
fmt.Printf("[Send] Starting tx...\n")
if tx.Address.IsIntegratedAddress() {
if tx.Address.Arguments.Validate_Arguments() != nil {
fmt.Printf("[Service] Integrated Address arguments could not be validated")
err = errors.New("Integrated Address arguments could not be validated")
return err
}
fmt.Printf("[Send] Not Integrated..\n")
if !tx.Address.Arguments.Has(rpc.RPC_DESTINATION_PORT, rpc.DataUint64) {
fmt.Printf("[Service] Integrated Address does not contain destination port")
err = errors.New("Integrated Address does not contain destination port")
return err
}
arguments = append(arguments, rpc.Argument{Name: rpc.RPC_DESTINATION_PORT, DataType: rpc.DataUint64, Value: tx.Address.Arguments.Value(rpc.RPC_DESTINATION_PORT, rpc.DataUint64).(uint64)})
fmt.Printf("[Send] Added arguments..\n")
if tx.Address.Arguments.Has(rpc.RPC_EXPIRY, rpc.DataTime) {
if tx.Address.Arguments.Value(rpc.RPC_EXPIRY, rpc.DataTime).(time.Time).Before(time.Now().UTC()) {
fmt.Printf("[Service] This address has expired.", "expiry time", tx.Address.Arguments.Value(rpc.RPC_EXPIRY, rpc.DataTime))
err = errors.New("This address has expired")
return err
} else {
fmt.Printf("[Service] This address will expire ", "expiry time", tx.Address.Arguments.Value(rpc.RPC_EXPIRY, rpc.DataTime))
err = errors.New("This address has expired")
return err
}