@@ -22,6 +22,7 @@ import (
2222 "net/url"
2323 "os"
2424 "path/filepath"
25+ "reflect"
2526 "strings"
2627 "time"
2728
@@ -71,14 +72,7 @@ var fixedURLWhitelist = []string{
7172 "https://shiftcrypto.support/" ,
7273 // Exchange rates.
7374 "https://www.coingecko.com/" ,
74- // Block explorers.
75- "https://blockstream.info/tx/" ,
76- "https://blockstream.info/testnet/tx/" ,
77- "https://sochain.com/tx/LTCTEST/" ,
78- "https://blockchair.com/litecoin/transaction/" ,
79- "https://etherscan.io/tx/" ,
80- "https://goerli.etherscan.io/tx/" ,
81- "https://sepolia.etherscan.io/tx/" ,
75+
8276 // Moonpay onramp
8377 "https://www.moonpay.com/" ,
8478 "https://support.moonpay.com/" ,
@@ -490,43 +484,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
490484 servers := backend .defaultElectrumXServers (code )
491485 coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
492486 case code == coinpkg .CodeTBTC :
487+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
493488 servers := backend .defaultElectrumXServers (code )
494489 coin = btc .NewCoin (coinpkg .CodeTBTC , "Bitcoin Testnet" , "TBTC" , btcFormatUnit , & chaincfg .TestNet3Params , dbFolder , servers ,
495- "https://blockstream.info/testnet/tx/" , backend .socksProxy )
490+ blockExplorerPrefix , backend .socksProxy )
496491 case code == coinpkg .CodeBTC :
492+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
497493 servers := backend .defaultElectrumXServers (code )
498494 coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
499- "https://blockstream.info/tx/" , backend .socksProxy )
495+ blockExplorerPrefix , backend .socksProxy )
500496 case code == coinpkg .CodeTLTC :
497+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
501498 servers := backend .defaultElectrumXServers (code )
502499 coin = btc .NewCoin (coinpkg .CodeTLTC , "Litecoin Testnet" , "TLTC" , coinpkg .BtcUnitDefault , & ltc .TestNet4Params , dbFolder , servers ,
503- "https://sochain.com/tx/LTCTEST/" , backend .socksProxy )
500+ blockExplorerPrefix , backend .socksProxy )
504501 case code == coinpkg .CodeLTC :
502+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
505503 servers := backend .defaultElectrumXServers (code )
506504 coin = btc .NewCoin (coinpkg .CodeLTC , "Litecoin" , "LTC" , coinpkg .BtcUnitDefault , & ltc .MainNetParams , dbFolder , servers ,
507- "https://blockchair.com/litecoin/transaction/" , backend .socksProxy )
505+ blockExplorerPrefix , backend .socksProxy )
508506 case code == coinpkg .CodeETH :
507+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
509508 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
510509 coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
511- "https://etherscan.io/tx/" ,
510+ blockExplorerPrefix ,
512511 etherScan ,
513512 nil )
514513 case code == coinpkg .CodeGOETH :
514+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
515515 etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
516516 coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
517- "https://goerli.etherscan.io/tx/" ,
517+ blockExplorerPrefix ,
518518 etherScan ,
519519 nil )
520520 case code == coinpkg .CodeSEPETH :
521+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
521522 etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
522523 coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
523- "https://sepolia.etherscan.io/tx/" ,
524+ blockExplorerPrefix ,
524525 etherScan ,
525526 nil )
526527 case erc20Token != nil :
528+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
527529 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
528530 coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
529- "https://etherscan.io/tx/" ,
531+ blockExplorerPrefix ,
530532 etherScan ,
531533 erc20Token .token ,
532534 )
@@ -827,6 +829,16 @@ func (backend *Backend) SystemOpen(url string) error {
827829 }
828830 }
829831
832+ // Block explorers are not defined in the fixedURLWhiteList but in AvailableBlockexplorers.
833+ var allAvailableExplorers = reflect .ValueOf (config .AvailableExplorers )
834+ for i := 0 ; i < allAvailableExplorers .NumField (); i ++ {
835+ coinAvailableExplorers := allAvailableExplorers .Field (i ).Interface ().([]config.BlockExplorer )
836+ for _ , explorer := range coinAvailableExplorers {
837+ if strings .HasPrefix (url , explorer .Url ) {
838+ return backend .environment .SystemOpen (url )
839+ }
840+ }
841+ }
830842 return errp .Newf ("Blocked /open with url: %s" , url )
831843}
832844
@@ -997,4 +1009,10 @@ func (backend *Backend) ExportLogs() error {
9971009 return err
9981010 }
9991011 return nil
1012+
1013+ }
1014+
1015+ // AvailableExplorers returns a struct containing all available block explorers for each coin.
1016+ func (backend * Backend ) AvailableExplorers () config.AvailableBlockExplorers {
1017+ return config .AvailableExplorers
10001018}
0 commit comments