@@ -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/" ,
@@ -485,43 +479,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
485479 servers := backend .defaultElectrumXServers (code )
486480 coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
487481 case code == coinpkg .CodeTBTC :
482+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
488483 servers := backend .defaultElectrumXServers (code )
489484 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 )
491486 case code == coinpkg .CodeBTC :
487+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
492488 servers := backend .defaultElectrumXServers (code )
493489 coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
494- "https://blockstream.info/tx/" , backend .socksProxy )
490+ blockExplorerPrefix , backend .socksProxy )
495491 case code == coinpkg .CodeTLTC :
492+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
496493 servers := backend .defaultElectrumXServers (code )
497494 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 )
499496 case code == coinpkg .CodeLTC :
497+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
500498 servers := backend .defaultElectrumXServers (code )
501499 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 )
503501 case code == coinpkg .CodeETH :
502+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
504503 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
505504 coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
506- "https://etherscan.io/tx/" ,
505+ blockExplorerPrefix ,
507506 etherScan ,
508507 nil )
509508 case code == coinpkg .CodeGOETH :
509+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
510510 etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
511511 coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
512- "https://goerli.etherscan.io/tx/" ,
512+ blockExplorerPrefix ,
513513 etherScan ,
514514 nil )
515515 case code == coinpkg .CodeSEPETH :
516+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
516517 etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
517518 coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
518- "https://sepolia.etherscan.io/tx/" ,
519+ blockExplorerPrefix ,
519520 etherScan ,
520521 nil )
521522 case erc20Token != nil :
523+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
522524 etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
523525 coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
524- "https://etherscan.io/tx/" ,
526+ blockExplorerPrefix ,
525527 etherScan ,
526528 erc20Token .token ,
527529 )
@@ -905,6 +907,16 @@ func (backend *Backend) SystemOpen(url string) error {
905907 }
906908 }
907909
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+ }
908920 return errp .Newf ("Blocked /open with url: %s" , url )
909921}
910922
@@ -1028,3 +1040,8 @@ func (backend *Backend) SetWatchonly(rootFingerprint []byte, watchonly bool) err
10281040 & t ,
10291041 )
10301042}
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