@@ -23,6 +23,7 @@ import (
2323 "net/url"
2424 "os"
2525 "path/filepath"
26+ "reflect"
2627 "strings"
2728 "time"
2829
@@ -73,13 +74,6 @@ var fixedURLWhitelist = []string{
7374 "https://shiftcrypto.support/" ,
7475 // Exchange rates.
7576 "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/" ,
8377 // Moonpay onramp
8478 "https://www.moonpay.com/" ,
8579 "https://support.moonpay.com/" ,
@@ -486,43 +480,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
486480 servers := backend .defaultElectrumXServers (code )
487481 coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
488482 case code == coinpkg .CodeTBTC :
483+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
489484 servers := backend .defaultElectrumXServers (code )
490485 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 )
492487 case code == coinpkg .CodeBTC :
488+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
493489 servers := backend .defaultElectrumXServers (code )
494490 coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
495- "https://blockstream.info/tx/" , backend .socksProxy )
491+ blockExplorerPrefix , backend .socksProxy )
496492 case code == coinpkg .CodeTLTC :
493+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
497494 servers := backend .defaultElectrumXServers (code )
498495 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 )
500497 case code == coinpkg .CodeLTC :
498+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
501499 servers := backend .defaultElectrumXServers (code )
502500 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 )
504502 case code == coinpkg .CodeETH :
503+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
505504 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
506505 coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
507- "https://etherscan.io/tx/" ,
506+ blockExplorerPrefix ,
508507 etherScan ,
509508 nil )
510509 case code == coinpkg .CodeGOETH :
510+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
511511 etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
512512 coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
513- "https://goerli.etherscan.io/tx/" ,
513+ blockExplorerPrefix ,
514514 etherScan ,
515515 nil )
516516 case code == coinpkg .CodeSEPETH :
517+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
517518 etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
518519 coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
519- "https://sepolia.etherscan.io/tx/" ,
520+ blockExplorerPrefix ,
520521 etherScan ,
521522 nil )
522523 case erc20Token != nil :
524+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
523525 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
524526 coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
525- "https://etherscan.io/tx/" ,
527+ blockExplorerPrefix ,
526528 etherScan ,
527529 erc20Token .token ,
528530 )
@@ -906,6 +908,16 @@ func (backend *Backend) SystemOpen(url string) error {
906908 }
907909 }
908910
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+ }
909921 return errp .Newf ("Blocked /open with url: %s" , url )
910922}
911923
@@ -1029,3 +1041,8 @@ func (backend *Backend) SetWatchonly(rootFingerprint []byte, watchonly bool) err
10291041 & t ,
10301042 )
10311043}
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