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