@@ -21,6 +21,7 @@ import (
21
21
"net/url"
22
22
"os"
23
23
"path/filepath"
24
+ "reflect"
24
25
"strings"
25
26
"time"
26
27
@@ -69,13 +70,6 @@ var fixedURLWhitelist = []string{
69
70
"https://shiftcrypto.support/" ,
70
71
// Exchange rates.
71
72
"https://www.coingecko.com/" ,
72
- // Block explorers.
73
- "https://blockstream.info/tx/" ,
74
- "https://blockstream.info/testnet/tx/" ,
75
- "https://sochain.com/tx/LTCTEST/" ,
76
- "https://blockchair.com/litecoin/transaction/" ,
77
- "https://etherscan.io/tx/" ,
78
- "https://goerli.etherscan.io/tx/" ,
79
73
// Moonpay onramp
80
74
"https://www.moonpay.com/" ,
81
75
"https://support.moonpay.com/" ,
@@ -482,43 +476,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
482
476
servers := backend .defaultElectrumXServers (code )
483
477
coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
484
478
case code == coinpkg .CodeTBTC :
479
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
485
480
servers := backend .defaultElectrumXServers (code )
486
481
coin = btc .NewCoin (coinpkg .CodeTBTC , "Bitcoin Testnet" , "TBTC" , btcFormatUnit , & chaincfg .TestNet3Params , dbFolder , servers ,
487
- "https://blockstream.info/testnet/tx/" , backend .socksProxy )
482
+ blockExplorerPrefix , backend .socksProxy )
488
483
case code == coinpkg .CodeBTC :
484
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
489
485
servers := backend .defaultElectrumXServers (code )
490
486
coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
491
- "https://blockstream.info/tx/" , backend .socksProxy )
487
+ blockExplorerPrefix , backend .socksProxy )
492
488
case code == coinpkg .CodeTLTC :
489
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
493
490
servers := backend .defaultElectrumXServers (code )
494
491
coin = btc .NewCoin (coinpkg .CodeTLTC , "Litecoin Testnet" , "TLTC" , coinpkg .BtcUnitDefault , & ltc .TestNet4Params , dbFolder , servers ,
495
- "https://sochain.com/tx/LTCTEST/" , backend .socksProxy )
492
+ blockExplorerPrefix , backend .socksProxy )
496
493
case code == coinpkg .CodeLTC :
494
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
497
495
servers := backend .defaultElectrumXServers (code )
498
496
coin = btc .NewCoin (coinpkg .CodeLTC , "Litecoin" , "LTC" , coinpkg .BtcUnitDefault , & ltc .MainNetParams , dbFolder , servers ,
499
- "https://blockchair.com/litecoin/transaction/" , backend .socksProxy )
497
+ blockExplorerPrefix , backend .socksProxy )
500
498
case code == coinpkg .CodeETH :
499
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
501
500
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
502
501
coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
503
- "https://etherscan.io/tx/" ,
502
+ blockExplorerPrefix ,
504
503
etherScan ,
505
504
nil )
506
505
case code == coinpkg .CodeGOETH :
506
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
507
507
etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
508
508
coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
509
- "https://goerli.etherscan.io/tx/" ,
509
+ blockExplorerPrefix ,
510
510
etherScan ,
511
511
nil )
512
512
case code == coinpkg .CodeSEPETH :
513
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
513
514
etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
514
515
coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
515
- "https://sepolia.etherscan.io/tx/" ,
516
+ blockExplorerPrefix ,
516
517
etherScan ,
517
518
nil )
518
519
case erc20Token != nil :
520
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
519
521
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
520
522
coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
521
- "https://etherscan.io/tx/" ,
523
+ blockExplorerPrefix ,
522
524
etherScan ,
523
525
erc20Token .token ,
524
526
)
@@ -819,6 +821,16 @@ func (backend *Backend) SystemOpen(url string) error {
819
821
}
820
822
}
821
823
824
+ // Block explorers are not defined in the fixedURLWhiteList but in AvailableBlockexplorers.
825
+ var allAvailableExplorers = reflect .ValueOf (config .AvailableExplorers )
826
+ for i := 0 ; i < allAvailableExplorers .NumField (); i ++ {
827
+ coinAvailableExplorers := allAvailableExplorers .Field (i ).Interface ().([]config.BlockExplorer )
828
+ for _ , explorer := range coinAvailableExplorers {
829
+ if strings .HasPrefix (url , explorer .Url ) {
830
+ return backend .environment .SystemOpen (url )
831
+ }
832
+ }
833
+ }
822
834
return errp .Newf ("Blocked /open with url: %s" , url )
823
835
}
824
836
@@ -942,3 +954,8 @@ func (backend *Backend) SetWatchonly(rootFingerprint []byte, watchonly bool) err
942
954
& t ,
943
955
)
944
956
}
957
+
958
+ // AvailableExplorers returns a struct containing all available block explorers for each coin.
959
+ func (backend * Backend ) AvailableExplorers () config.AvailableBlockExplorers {
960
+ return config .AvailableExplorers
961
+ }
0 commit comments