-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathexplorer_service.go
More file actions
1308 lines (1103 loc) · 34.8 KB
/
Copy pathexplorer_service.go
File metadata and controls
1308 lines (1103 loc) · 34.8 KB
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
package main
import (
"encoding/hex"
"fmt"
"strings"
"time"
"github.com/deroproject/derohe/cryptography/crypto"
"github.com/deroproject/derohe/globals"
"github.com/deroproject/derohe/proof"
"github.com/deroproject/derohe/rpc"
"github.com/deroproject/derohe/transaction"
)
// ExplorerService provides block explorer functionality with DeroProof validation
// GetBlock retrieves detailed block information
func (a *App) GetBlock(height int64) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Getting block at height: %d", height))
params := map[string]interface{}{
"height": height,
}
result, err := a.daemonClient.Call("DERO.GetBlock", params)
if err != nil {
return ErrorResponse(err)
}
// Parse block data
blockData := map[string]interface{}{}
if resultMap, ok := result.(map[string]interface{}); ok {
if block, ok := resultMap["block"].(map[string]interface{}); ok {
blockData = block
} else {
blockData = resultMap
}
}
return map[string]interface{}{
"success": true,
"height": height,
"block": blockData,
}
}
// GetBlockExtended retrieves comprehensive block information including all metadata
// This matches the official DERO explorer functionality
func (a *App) GetBlockExtended(heightOrHash string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Getting extended block: %s", heightOrHash))
// Build params based on input type
var params map[string]interface{}
if len(heightOrHash) == 64 {
params = map[string]interface{}{"hash": heightOrHash}
} else {
var height int64
fmt.Sscanf(heightOrHash, "%d", &height)
params = map[string]interface{}{"height": height}
}
result, err := a.daemonClient.Call("DERO.GetBlock", params)
if err != nil {
return ErrorResponse(err)
}
resultMap, ok := result.(map[string]interface{})
if !ok {
return map[string]interface{}{"success": false, "error": "Invalid block data format"}
}
// Extract block_header and blob
blockHeader := map[string]interface{}{}
if bh, ok := resultMap["block_header"].(map[string]interface{}); ok {
blockHeader = bh
}
blob := ""
if b, ok := resultMap["blob"].(string); ok {
blob = b
}
// Use helpers for extraction
age, blockTime := "", ""
if timestamp, ok := blockHeader["timestamp"].(float64); ok {
age, blockTime = calculateBlockAge(timestamp)
}
tips := extractStringArray(blockHeader["tips"])
miners := extractStringArray(blockHeader["miners"])
// Determine network and parse block
isMainnet := true
if network, ok := a.settings["network"].(string); ok && network == "simulator" {
isMainnet = false
}
parsed := parseBlockBlob(blob, isMainnet)
// Calculate fees from transactions
totalFees, txDetails := a.extractBlockTxDetails(parsed.TxHashes)
// Build comprehensive response
response := map[string]interface{}{
"success": true,
// Core identifiers
"height": blockHeader["height"],
"topoheight": blockHeader["topoheight"],
"hash": blockHeader["hash"],
// Block metadata
"depth": blockHeader["depth"],
"difficulty": blockHeader["difficulty"],
"major_version": blockHeader["major_version"],
"minor_version": blockHeader["minor_version"],
"nonce": blockHeader["nonce"],
// Status flags
"orphan_status": blockHeader["orphan_status"],
"sync_block": blockHeader["syncblock"],
"side_block": blockHeader["sideblock"],
// DAG structure
"tips": tips,
// Mining info
"miners": miners,
"miner_address": parsed.MinerAddress,
"reward": blockHeader["reward"],
// Timing
"timestamp": blockHeader["timestamp"],
"age": age,
"block_time": blockTime,
// Transactions
"tx_count": blockHeader["txcount"],
"tx_hashes": parsed.TxHashes,
"txs": txDetails,
"total_fees": totalFees,
// Size
"size_bytes": parsed.BlockSize,
"size_kb": fmt.Sprintf("%.03f", float64(parsed.BlockSize)/1024),
// Raw data
"blob": blob,
}
a.logToConsole(fmt.Sprintf("[OK] Block %v: %d TXs, %d tips, miner=%s",
blockHeader["height"], len(parsed.TxHashes), len(tips),
truncateAddrForLog(parsed.MinerAddress)))
return response
}
// extractBlockTxDetails fetches transaction details for a block
func (a *App) extractBlockTxDetails(txHashes []string) (uint64, []map[string]interface{}) {
var totalFees uint64 = 0
txDetails := []map[string]interface{}{}
for _, txHash := range txHashes {
txInfo := a.GetTransactionBasic(txHash)
if txInfo["success"].(bool) {
if tx, ok := txInfo["tx"].(map[string]interface{}); ok {
txDetails = append(txDetails, map[string]interface{}{
"hash": txHash,
"fee": tx["fee"],
"type": tx["tx_type"],
"scid": tx["scid"],
"signer": tx["signer"],
})
if fee, ok := tx["fee"].(float64); ok {
totalFees += uint64(fee)
}
}
}
}
return totalFees, txDetails
}
// GetTransactionBasic returns basic transaction info (used internally)
func (a *App) GetTransactionBasic(txid string) map[string]interface{} {
params := map[string]interface{}{
"txs_hashes": []string{txid},
"decode_as_json": 1,
}
result, err := a.daemonClient.Call("DERO.GetTransaction", params)
if err != nil {
return map[string]interface{}{
"success": false,
"error": err.Error(),
}
}
resultMap, ok := result.(map[string]interface{})
if !ok {
return map[string]interface{}{
"success": false,
"error": "Invalid response format",
}
}
txs, ok := resultMap["txs"].([]interface{})
if !ok || len(txs) == 0 {
return map[string]interface{}{
"success": false,
"error": "Transaction not found",
}
}
txData, ok := txs[0].(map[string]interface{})
if !ok {
return map[string]interface{}{
"success": false,
"error": "Invalid transaction data",
}
}
return map[string]interface{}{
"success": true,
"tx": txData,
}
}
// truncateAddrForLog truncates an address for logging
func truncateAddrForLog(addr string) string {
if len(addr) > 16 {
return addr[:8] + "..." + addr[len(addr)-8:]
}
return addr
}
// GetBlockByHash retrieves block information by hash
func (a *App) GetBlockByHash(hash string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Getting block by hash: %s", hash[:16]+"..."))
params := map[string]interface{}{
"hash": hash,
}
result, err := a.daemonClient.Call("DERO.GetBlock", params)
if err != nil {
return ErrorResponse(err)
}
return map[string]interface{}{
"success": true,
"hash": hash,
"block": result,
}
}
// GetTransaction retrieves transaction details
func (a *App) GetTransaction(txid string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Getting transaction: %s", txid[:16]+"..."))
params := map[string]interface{}{
"txs_hashes": []string{txid},
"decode_as_json": 1,
}
result, err := a.daemonClient.Call("DERO.GetTransaction", params)
if err != nil {
return ErrorResponse(err)
}
// Extract transaction from result
txData := map[string]interface{}{}
if resultMap, ok := result.(map[string]interface{}); ok {
if txs, ok := resultMap["txs"].([]interface{}); ok && len(txs) > 0 {
if tx, ok := txs[0].(map[string]interface{}); ok {
txData = tx
}
}
}
return map[string]interface{}{
"success": true,
"txid": txid,
"tx": txData,
}
}
// GetCoinbaseMiner extracts the miner address from a coinbase transaction
// by parsing the raw transaction binary
func (a *App) GetCoinbaseMiner(txid string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[MINE] Getting miner address for TX: %s", txid[:16]+"..."))
// Fetch raw transaction hex
params := map[string]interface{}{
"txs_hashes": []string{txid},
"decode_as_json": 1,
}
result, err := a.daemonClient.Call("DERO.GetTransaction", params)
if err != nil {
return ErrorResponse(err)
}
var txHex string
if resultMap, ok := result.(map[string]interface{}); ok {
if txsHex, ok := resultMap["txs_as_hex"].([]interface{}); ok && len(txsHex) > 0 {
if hexStr, ok := txsHex[0].(string); ok {
txHex = hexStr
}
}
}
if txHex == "" {
return map[string]interface{}{
"success": true,
"isCoinbase": false,
"message": "No raw transaction hex available",
}
}
// Decode hex to bytes
txBytes, err := hex.DecodeString(txHex)
if err != nil {
return map[string]interface{}{
"success": false,
"error": "Failed to decode transaction data",
"technicalError": err.Error(),
}
}
// Parse the transaction
var tx transaction.Transaction
if err := tx.Deserialize(txBytes); err != nil {
return map[string]interface{}{
"success": false,
"error": "Failed to parse transaction",
"technicalError": err.Error(),
}
}
// Check if this is a coinbase transaction
if tx.TransactionType != transaction.COINBASE {
return map[string]interface{}{
"success": true,
"isCoinbase": false,
"txType": getTxTypeName(tx.TransactionType),
}
}
// Extract miner address from coinbase TX
var acckey crypto.Point
if err := acckey.DecodeCompressed(tx.MinerAddress[:]); err != nil {
return map[string]interface{}{
"success": true,
"isCoinbase": true,
"error": "Failed to decode miner address",
"technicalError": err.Error(),
}
}
// Determine network (mainnet vs simulator)
mainnet := true
if network, ok := a.settings["network"].(string); ok && network == "simulator" {
mainnet = false
}
// Convert to address string
astring := rpc.NewAddressFromKeys(&acckey)
astring.Mainnet = mainnet
minerAddress := astring.String()
a.logToConsole(fmt.Sprintf("[OK] Coinbase TX miner: %s", minerAddress[:20]+"..."))
return map[string]interface{}{
"success": true,
"isCoinbase": true,
"minerAddress": minerAddress,
"txType": "COINBASE",
}
}
// getTxTypeName returns a human-readable name for the transaction type
func getTxTypeName(txType transaction.TransactionType) string {
switch txType {
case transaction.PREMINE:
return "PREMINE"
case transaction.REGISTRATION:
return "REGISTRATION"
case transaction.COINBASE:
return "COINBASE"
case transaction.NORMAL:
return "NORMAL"
case transaction.BURN_TX:
return "BURN"
case transaction.SC_TX:
return "SC"
default:
return "UNKNOWN"
}
}
// GetTransactionExtended returns comprehensive transaction info matching official DERO explorer
// Includes: ring members per payload, assets breakdown, valid/invalid blocks, size, raw hex
func (a *App) GetTransactionExtended(txid string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Getting extended transaction: %s", txid[:16]+"..."))
// Fetch full transaction data from daemon
params := map[string]interface{}{
"txs_hashes": []string{txid},
"decode_as_json": 1,
}
result, err := a.daemonClient.Call("DERO.GetTransaction", params)
if err != nil {
return ErrorResponse(err)
}
resultMap, ok := result.(map[string]interface{})
if !ok {
return map[string]interface{}{"success": false, "error": "Invalid response format"}
}
// Extract raw hex
var txHex string
if txsHex, ok := resultMap["txs_as_hex"].([]interface{}); ok && len(txsHex) > 0 {
if hexStr, ok := txsHex[0].(string); ok {
txHex = hexStr
}
}
// Extract transaction info
txs, ok := resultMap["txs"].([]interface{})
if !ok || len(txs) == 0 {
return map[string]interface{}{"success": false, "error": "Transaction not found"}
}
txData, ok := txs[0].(map[string]interface{})
if !ok {
return map[string]interface{}{"success": false, "error": "Invalid transaction data"}
}
// Use helper functions for extraction
sizeBytes := calculateTxSize(txHex)
rings := extractRingMembers(txData)
validBlock, invalidBlocks := extractValidInvalidBlocks(txData)
// Determine network mode
isMainnet := true
if network, ok := a.settings["network"].(string); ok && network == "simulator" {
isMainnet = false
}
// Parse transaction bytes
parsed := parseTxBytes(txHex, rings, isMainnet)
// Calculate age
age, blockTime := "", ""
if blockHeight, ok := txData["block_height"].(float64); ok {
age, blockTime = a.calculateTxAge(blockHeight)
}
maxRingSize := getMaxRingSize(rings)
// Build comprehensive response
response := map[string]interface{}{
"success": true,
"txid": txid,
// Transaction type & status
"tx_type": parsed.TxType,
"in_pool": txData["in_pool"],
"ignored": txData["ignored"],
"is_coinbase": parsed.IsCoinbase,
// Block info
"block_height": txData["block_height"],
"valid_block": validBlock,
"invalid_blocks": invalidBlocks,
// Timing
"age": age,
"block_time": blockTime,
// Build info
"height_built": parsed.HeightBuilt,
"blid": parsed.BLID,
"root_hash": parsed.RootHash,
// Addresses
"miner_address": parsed.MinerAddress,
"signer": txData["signer"],
// Economics
"fee": txData["fee"],
"reward": txData["reward"],
"burn_value": parsed.BurnValue,
"balance": txData["balance"],
// Ring members
"rings": rings,
"ring_count": len(rings),
"max_ring_size": maxRingSize,
// Assets breakdown
"assets": parsed.Assets,
// Smart Contract data
"sc_args": parsed.SCArgs,
"sc_code": txData["code"],
"sc_balance": txData["balance"],
"sc_balance_now": txData["balancenow"],
"sc_code_now": txData["codenow"],
// Size
"size_bytes": sizeBytes,
"size_kb": fmt.Sprintf("%.03f", float64(sizeBytes)/1024),
// Raw data
"hex": txHex,
"output_indices": txData["output_indices"],
// Original tx object for backward compatibility
"tx": txData,
}
a.logToConsole(fmt.Sprintf("[OK] TX %s: type=%s, %d assets, ring=%d",
txid[:16]+"...", parsed.TxType, len(parsed.Assets), maxRingSize))
return response
}
// SearchAddress searches for transactions related to an address
func (a *App) SearchAddress(address string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Searching address: %s", address[:16]+"..."))
// Validate address format
if !strings.HasPrefix(address, "dero1") {
return map[string]interface{}{
"success": false,
"error": "Invalid DERO address format",
}
}
// Note: DERO doesn't have a direct "search by address" API due to privacy
// This would need to use Gnomon indexing or local wallet history
if a.gnomonClient.IsRunning() {
// Search through Gnomon for SCIDs owned by this address
ownedSCIDs := a.getOwnedSCIDs(address)
return map[string]interface{}{
"success": true,
"address": address,
"ownedSCIDs": ownedSCIDs,
"ownedCount": len(ownedSCIDs),
"note": "Due to DERO's privacy features, full transaction history is only available for owned wallets",
}
}
return map[string]interface{}{
"success": false,
"error": "Gnomon indexer required for address search",
}
}
// getOwnedSCIDs returns all SCIDs where the given address is the owner
func (a *App) getOwnedSCIDs(address string) []map[string]interface{} {
ownedSCIDs := []map[string]interface{}{}
if !a.gnomonClient.IsRunning() {
return ownedSCIDs
}
// Get all indexed SCIDs and their owners
allSCIDs := a.gnomonClient.GetAllOwnersAndSCIDs()
for scid, owner := range allSCIDs {
// Check if this address owns the SCID
if strings.EqualFold(owner, address) {
// Get more details about this SCID
scidInfo := map[string]interface{}{
"scid": scid,
"owner": owner,
}
// Try to get name/description from variables
vars := a.gnomonClient.GetAllSCIDVariableDetails(scid)
for _, v := range vars {
key := fmt.Sprintf("%v", v.Key)
switch key {
// V2 headers (TELA standard) - check first
case "var_header_name":
if v.Value != nil {
scidInfo["name"] = decodeHexString(fmt.Sprintf("%v", v.Value))
}
case "var_header_description":
if v.Value != nil {
scidInfo["description"] = decodeHexString(fmt.Sprintf("%v", v.Value))
}
// V1 headers (ART-NFA standard) - fallback if V2 not set
case "nameHdr":
if v.Value != nil && scidInfo["name"] == nil {
scidInfo["name"] = decodeHexString(fmt.Sprintf("%v", v.Value))
}
case "descrHdr":
if v.Value != nil && scidInfo["description"] == nil {
scidInfo["description"] = decodeHexString(fmt.Sprintf("%v", v.Value))
}
case "dURL":
if v.Value != nil {
scidInfo["durl"] = decodeHexString(fmt.Sprintf("%v", v.Value))
}
}
}
ownedSCIDs = append(ownedSCIDs, scidInfo)
}
}
a.logToConsole(fmt.Sprintf("[OK] Found %d SCIDs owned by address", len(ownedSCIDs)))
return ownedSCIDs
}
// GetAddressSCIDReferences finds SCIDs where an address appears in stored variables
func (a *App) GetAddressSCIDReferences(address string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[...] Finding SCID references for: %s", address[:16]+"..."))
if !a.gnomonClient.IsRunning() {
return map[string]interface{}{
"success": false,
"error": "Gnomon indexer required",
}
}
references := []map[string]interface{}{}
// Get all indexed SCIDs
allSCIDs := a.gnomonClient.GetAllOwnersAndSCIDs()
for scid := range allSCIDs {
// Check if this address appears in any variables
vars := a.gnomonClient.GetAllSCIDVariableDetails(scid)
for _, v := range vars {
valueStr := fmt.Sprintf("%v", v.Value)
// Check if the address appears in this value (decoded)
decodedValue := decodeHexString(valueStr)
if strings.Contains(strings.ToLower(decodedValue), strings.ToLower(address)) ||
strings.Contains(strings.ToLower(valueStr), strings.ToLower(address)) {
references = append(references, map[string]interface{}{
"scid": scid,
"variable": fmt.Sprintf("%v", v.Key),
})
break // Only add each SCID once
}
}
}
return map[string]interface{}{
"success": true,
"address": address,
"references": references,
"count": len(references),
}
}
// formatAge formats a duration into a human-readable "time ago" format
// Ported from explorerlib.go
func formatAge(d time.Duration) string {
totalSeconds := int64(d.Seconds())
if totalSeconds < 60 {
return fmt.Sprintf("%ds ago", totalSeconds)
} else if totalSeconds < 3600 {
minutes := totalSeconds / 60
seconds := totalSeconds % 60
return fmt.Sprintf("%dm %ds ago", minutes, seconds)
} else if totalSeconds < 86400 {
hours := totalSeconds / 3600
minutes := (totalSeconds % 3600) / 60
return fmt.Sprintf("%dh %dm ago", hours, minutes)
} else {
days := totalSeconds / 86400
hours := (totalSeconds % 86400) / 3600
return fmt.Sprintf("%dd %dh ago", days, hours)
}
}
// FormatBlockAge formats a block timestamp into "time ago" format
func (a *App) FormatBlockAge(timestampMs int64) string {
blockTime := time.UnixMilli(timestampMs)
duration := time.Since(blockTime)
return formatAge(duration)
}
// ValidateProofFull validates a DeroProof using the proof.Prove() function
// This requires fetching the transaction data to get the raw hex and ring members
func (a *App) ValidateProofFull(proofString string, txid string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[WALLET] Validating DeroProof: %s...", proofString[:20]))
if proofString == "" {
return map[string]interface{}{
"success": false,
"error": "No proof string provided",
}
}
// We need the transaction data to validate the proof
// The proof.Prove() function requires:
// 1. The proof string (deroproof1q... format)
// 2. The raw transaction hex
// 3. The ring members for each payload
var txHex string
var ringData [][]string
if txid != "" {
// Fetch transaction data from daemon
params := map[string]interface{}{
"txs_hashes": []string{txid},
"decode_as_json": 1,
}
result, err := a.daemonClient.Call("DERO.GetTransaction", params)
if err != nil {
return ErrorResponse(err)
}
// Extract tx hex and ring data from result
if resultMap, ok := result.(map[string]interface{}); ok {
// Get raw hex
if txsHex, ok := resultMap["txs_as_hex"].([]interface{}); ok && len(txsHex) > 0 {
if hexStr, ok := txsHex[0].(string); ok {
txHex = hexStr
}
}
// Get ring data from txs array
if txs, ok := resultMap["txs"].([]interface{}); ok && len(txs) > 0 {
if tx, ok := txs[0].(map[string]interface{}); ok {
if ring, ok := tx["ring"].([]interface{}); ok {
for _, payload := range ring {
var payloadRing []string
if addresses, ok := payload.([]interface{}); ok {
for _, addr := range addresses {
if addrStr, ok := addr.(string); ok {
payloadRing = append(payloadRing, addrStr)
}
}
}
ringData = append(ringData, payloadRing)
}
}
}
}
}
if txHex == "" {
return map[string]interface{}{
"success": false,
"error": "Could not extract transaction hex from daemon response",
}
}
} else {
// No txid provided - the proof might be self-contained or we need user to provide tx data
return map[string]interface{}{
"success": false,
"error": "Transaction ID required for proof validation. The proof must be validated against a specific transaction.",
}
}
// Determine network (mainnet vs simulator)
mainnet := true
if network, ok := a.settings["network"].(string); ok && network == "simulator" {
mainnet = false
}
// Call proof.Prove() to validate
a.logToConsole(fmt.Sprintf("[...] Validating proof against TX with %d ring groups", len(ringData)))
addresses, amounts, payloadRaw, payloadDecoded, err := proof.Prove(proofString, txHex, ringData, mainnet)
if err != nil {
a.logToConsole(fmt.Sprintf("[ERR] Proof validation failed: %v", err))
return map[string]interface{}{
"success": true,
"valid": false,
"error": err.Error(),
}
}
// Security validation: Check proof amounts before display
// Blocks fake proofs with impossible amounts (> DERO hard cap or wraparound attacks)
var allWarnings []string
var supplyContexts []string
var percentages []float64
for i, amt := range amounts {
// Validate each amount
validationResult := ValidatePayloadProofAmountWithContext(amt)
if !validationResult.Valid {
a.logToConsole(fmt.Sprintf("[SECURITY] Fake proof rejected for receiver %d: %s", i+1, validationResult.Error))
return map[string]interface{}{
"success": true,
"valid": false,
"error": fmt.Sprintf("Proof rejected: %s", validationResult.Error),
"securityNote": "This proof claims an amount that exceeds the DERO hard cap (21M) and is therefore fabricated.",
}
}
// Collect warnings and context
allWarnings = append(allWarnings, validationResult.Warnings...)
supplyContexts = append(supplyContexts, validationResult.SupplyContext)
percentages = append(percentages, validationResult.PercentOfSupply)
}
// Format the amounts using globals.FormatMoney
formattedAmounts := make([]string, len(amounts))
for i, amt := range amounts {
formattedAmounts[i] = globals.FormatMoney(amt)
}
// Convert raw payloads to hex for display
payloadHex := make([]string, len(payloadRaw))
for i, raw := range payloadRaw {
payloadHex[i] = hex.EncodeToString(raw)
}
a.logToConsole(fmt.Sprintf("[OK] Proof validated! Found %d receiver(s)", len(addresses)))
return map[string]interface{}{
"success": true,
"valid": true,
"addresses": addresses,
"amounts": amounts,
"amountsFormatted": formattedAmounts,
"payloadRaw": payloadHex,
"payloadDecoded": payloadDecoded,
"txid": txid,
"warnings": allWarnings,
"supplyContexts": supplyContexts,
"percentOfSupply": percentages,
}
}
// ValidateProof validates a DeroProof (legacy method - calls ValidateProofFull)
func (a *App) ValidateProof(proofData string) map[string]interface{} {
a.logToConsole("[WALLET] Validating DeroProof...")
if proofData == "" {
return map[string]interface{}{
"success": false,
"error": "No proof data provided",
}
}
// For standalone proof validation without a specific txid,
// we return an error indicating the txid is needed
return map[string]interface{}{
"success": false,
"error": "Please provide a transaction ID along with the proof. Use ValidateProofFull(proof, txid) instead.",
}
}
// ValidateSenderProof validates a sender proof for a transaction
func (a *App) ValidateSenderProof(txid, senderAddress, receiverAddress string, amount uint64, proofSignature string) map[string]interface{} {
a.logToConsole(fmt.Sprintf("[WALLET] Validating sender proof for TX: %s", txid[:16]+"..."))
// Build proof validation request
params := map[string]interface{}{
"txid": txid,
"sender_address": senderAddress,
"receiver_address": receiverAddress,
"amount": amount,
"proof_signature": proofSignature,
}
result, err := a.daemonClient.Call("DERO.ValidateSenderProof", params)
if err != nil {
return map[string]interface{}{
"success": false,
"error": "Proof validation failed. Please check the proof format.",
"technicalError": err.Error(),
}
}
isValid := false
if resultMap, ok := result.(map[string]interface{}); ok {
if valid, ok := resultMap["valid"].(bool); ok {
isValid = valid
}
}
return map[string]interface{}{
"success": true,
"valid": isValid,
"txid": txid,
"amount": amount,
}
}
// GetBlockchainStats returns overall blockchain statistics
func (a *App) GetBlockchainStats() map[string]interface{} {
a.logToConsole("[STATS] Getting blockchain statistics...")
info, err := a.daemonClient.GetInfo()
if err != nil {
return ErrorResponse(err)
}
// Extract relevant stats - info is already map[string]interface{}
stats := map[string]interface{}{}
stats["height"] = info["height"]
stats["topoheight"] = info["topoheight"]
stats["difficulty"] = info["difficulty"]
stats["hashrate"] = info["hashrate"]
stats["total_supply"] = info["total_supply"]
stats["tx_pool_size"] = info["tx_pool_size"]
stats["peers"] = info["peers"]
stats["network"] = info["network"]
stats["version"] = info["version"]
stats["uptime"] = info["uptime"]
return map[string]interface{}{
"success": true,
"stats": stats,
}
}
// GetRecentBlocks returns the most recent blocks
func (a *App) GetRecentBlocks(count int) map[string]interface{} {
if count <= 0 {
count = 10
}
if count > 100 {
count = 100
}
a.logToConsole(fmt.Sprintf("[STATS] Getting %d recent blocks...", count))
// Get current height
info, err := a.daemonClient.GetInfo()
if err != nil {
return ErrorResponse(err)
}
height := int64(0)
if h, ok := info["height"].(float64); ok {
height = int64(h)
}
if height == 0 {
return map[string]interface{}{
"success": false,
"error": "Could not determine chain height",
}
}
// Fetch recent blocks
blocks := []map[string]interface{}{}
for i := 0; i < count && height-int64(i) > 0; i++ {
h := height - int64(i)
result, err := a.daemonClient.Call("DERO.GetBlock", map[string]interface{}{"height": h})
if err != nil {
continue
}
blockData := map[string]interface{}{
"height": h,
}
if resultMap, ok := result.(map[string]interface{}); ok {
if block, ok := resultMap["block"].(map[string]interface{}); ok {
if header, ok := block["block_header"].(map[string]interface{}); ok {
blockData["hash"] = header["hash"]
blockData["timestamp"] = header["timestamp"]
blockData["tx_count"] = header["tx_count"]
blockData["reward"] = header["reward"]
}
}
}
blocks = append(blocks, blockData)
}
return map[string]interface{}{
"success": true,
"blocks": blocks,
"count": len(blocks),
}
}
// GetMempoolTransactions returns current mempool transactions
func (a *App) GetMempoolTransactions() map[string]interface{} {
a.logToConsole("[STATS] Getting mempool transactions...")
result, err := a.daemonClient.Call("DERO.GetTxPool", nil)
if err != nil {
return ErrorResponse(err)