@@ -23,6 +23,7 @@ import (
23
23
"net/url"
24
24
"os"
25
25
"path/filepath"
26
+ "reflect"
26
27
"strings"
27
28
"time"
28
29
@@ -73,13 +74,6 @@ var fixedURLWhitelist = []string{
73
74
"https://shiftcrypto.support/" ,
74
75
// Exchange rates.
75
76
"https://www.coingecko.com/" ,
76
- // Block explorers.
77
- "https://blockstream.info/tx/" ,
78
- "https://blockstream.info/testnet/tx/" ,
79
- "https://sochain.com/tx/LTCTEST/" ,
80
- "https://blockchair.com/litecoin/transaction/" ,
81
- "https://etherscan.io/tx/" ,
82
- "https://goerli.etherscan.io/tx/" ,
83
77
// Moonpay onramp
84
78
"https://www.moonpay.com/" ,
85
79
"https://support.moonpay.com/" ,
@@ -486,43 +480,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
486
480
servers := backend .defaultElectrumXServers (code )
487
481
coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
488
482
case code == coinpkg .CodeTBTC :
483
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
489
484
servers := backend .defaultElectrumXServers (code )
490
485
coin = btc .NewCoin (coinpkg .CodeTBTC , "Bitcoin Testnet" , "TBTC" , btcFormatUnit , & chaincfg .TestNet3Params , dbFolder , servers ,
491
- "https://blockstream.info/testnet/tx/" , backend .socksProxy )
486
+ blockExplorerPrefix , backend .socksProxy )
492
487
case code == coinpkg .CodeBTC :
488
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
493
489
servers := backend .defaultElectrumXServers (code )
494
490
coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
495
- "https://blockstream.info/tx/" , backend .socksProxy )
491
+ blockExplorerPrefix , backend .socksProxy )
496
492
case code == coinpkg .CodeTLTC :
493
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
497
494
servers := backend .defaultElectrumXServers (code )
498
495
coin = btc .NewCoin (coinpkg .CodeTLTC , "Litecoin Testnet" , "TLTC" , coinpkg .BtcUnitDefault , & ltc .TestNet4Params , dbFolder , servers ,
499
- "https://sochain.com/tx/LTCTEST/" , backend .socksProxy )
496
+ blockExplorerPrefix , backend .socksProxy )
500
497
case code == coinpkg .CodeLTC :
498
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
501
499
servers := backend .defaultElectrumXServers (code )
502
500
coin = btc .NewCoin (coinpkg .CodeLTC , "Litecoin" , "LTC" , coinpkg .BtcUnitDefault , & ltc .MainNetParams , dbFolder , servers ,
503
- "https://blockchair.com/litecoin/transaction/" , backend .socksProxy )
501
+ blockExplorerPrefix , backend .socksProxy )
504
502
case code == coinpkg .CodeETH :
503
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
505
504
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
506
505
coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
507
- "https://etherscan.io/tx/" ,
506
+ blockExplorerPrefix ,
508
507
etherScan ,
509
508
nil )
510
509
case code == coinpkg .CodeGOETH :
510
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
511
511
etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
512
512
coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
513
- "https://goerli.etherscan.io/tx/" ,
513
+ blockExplorerPrefix ,
514
514
etherScan ,
515
515
nil )
516
516
case code == coinpkg .CodeSEPETH :
517
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
517
518
etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
518
519
coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
519
- "https://sepolia.etherscan.io/tx/" ,
520
+ blockExplorerPrefix ,
520
521
etherScan ,
521
522
nil )
522
523
case erc20Token != nil :
524
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
523
525
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
524
526
coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
525
- "https://etherscan.io/tx/" ,
527
+ blockExplorerPrefix ,
526
528
etherScan ,
527
529
erc20Token .token ,
528
530
)
@@ -906,6 +908,16 @@ func (backend *Backend) SystemOpen(url string) error {
906
908
}
907
909
}
908
910
911
+ // Block explorers are not defined in the fixedURLWhiteList but in AvailableBlockexplorers.
912
+ var allAvailableExplorers = reflect .ValueOf (config .AvailableExplorers )
913
+ for i := 0 ; i < allAvailableExplorers .NumField (); i ++ {
914
+ coinAvailableExplorers := allAvailableExplorers .Field (i ).Interface ().([]config.BlockExplorer )
915
+ for _ , explorer := range coinAvailableExplorers {
916
+ if strings .HasPrefix (url , explorer .Url ) {
917
+ return backend .environment .SystemOpen (url )
918
+ }
919
+ }
920
+ }
909
921
return errp .Newf ("Blocked /open with url: %s" , url )
910
922
}
911
923
@@ -1029,3 +1041,8 @@ func (backend *Backend) SetWatchonly(rootFingerprint []byte, watchonly bool) err
1029
1041
& t ,
1030
1042
)
1031
1043
}
1044
+
1045
+ // AvailableExplorers returns a struct containing all available block explorers for each coin.
1046
+ func (backend * Backend ) AvailableExplorers () config.AvailableBlockExplorers {
1047
+ return config .AvailableExplorers
1048
+ }
0 commit comments