@@ -22,6 +22,7 @@ import (
22
22
"net/url"
23
23
"os"
24
24
"path/filepath"
25
+ "reflect"
25
26
"strings"
26
27
"time"
27
28
@@ -71,14 +72,7 @@ var fixedURLWhitelist = []string{
71
72
"https://shiftcrypto.support/" ,
72
73
// Exchange rates.
73
74
"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
+
82
76
// Moonpay onramp
83
77
"https://www.moonpay.com/" ,
84
78
"https://support.moonpay.com/" ,
@@ -490,43 +484,51 @@ func (backend *Backend) Coin(code coinpkg.Code) (coinpkg.Coin, error) {
490
484
servers := backend .defaultElectrumXServers (code )
491
485
coin = btc .NewCoin (coinpkg .CodeRBTC , "Bitcoin Regtest" , "RBTC" , coinpkg .BtcUnitDefault , & chaincfg .RegressionNetParams , dbFolder , servers , "" , backend .socksProxy )
492
486
case code == coinpkg .CodeTBTC :
487
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TBTC
493
488
servers := backend .defaultElectrumXServers (code )
494
489
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 )
496
491
case code == coinpkg .CodeBTC :
492
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .BTC
497
493
servers := backend .defaultElectrumXServers (code )
498
494
coin = btc .NewCoin (coinpkg .CodeBTC , "Bitcoin" , "BTC" , btcFormatUnit , & chaincfg .MainNetParams , dbFolder , servers ,
499
- "https://blockstream.info/tx/" , backend .socksProxy )
495
+ blockExplorerPrefix , backend .socksProxy )
500
496
case code == coinpkg .CodeTLTC :
497
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .TLTC
501
498
servers := backend .defaultElectrumXServers (code )
502
499
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 )
504
501
case code == coinpkg .CodeLTC :
502
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .LTC
505
503
servers := backend .defaultElectrumXServers (code )
506
504
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 )
508
506
case code == coinpkg .CodeETH :
507
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
509
508
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
510
509
coin = eth .NewCoin (etherScan , code , "Ethereum" , "ETH" , "ETH" , params .MainnetChainConfig ,
511
- "https://etherscan.io/tx/" ,
510
+ blockExplorerPrefix ,
512
511
etherScan ,
513
512
nil )
514
513
case code == coinpkg .CodeGOETH :
514
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .GOETH
515
515
etherScan := etherscan .NewEtherScan ("https://api-goerli.etherscan.io/api" , backend .etherScanHTTPClient )
516
516
coin = eth .NewCoin (etherScan , code , "Ethereum Goerli" , "GOETH" , "GOETH" , params .GoerliChainConfig ,
517
- "https://goerli.etherscan.io/tx/" ,
517
+ blockExplorerPrefix ,
518
518
etherScan ,
519
519
nil )
520
520
case code == coinpkg .CodeSEPETH :
521
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .SEPETH
521
522
etherScan := etherscan .NewEtherScan ("https://api-sepolia.etherscan.io/api" , backend .etherScanHTTPClient )
522
523
coin = eth .NewCoin (etherScan , code , "Ethereum Sepolia" , "SEPETH" , "SEPETH" , params .SepoliaChainConfig ,
523
- "https://sepolia.etherscan.io/tx/" ,
524
+ blockExplorerPrefix ,
524
525
etherScan ,
525
526
nil )
526
527
case erc20Token != nil :
528
+ blockExplorerPrefix := backend .config .AppConfig ().Backend .BlockExplorers .ETH
527
529
etherScan := etherscan .NewEtherScan ("https://api.etherscan.io/api" , backend .etherScanHTTPClient )
528
530
coin = eth .NewCoin (etherScan , erc20Token .code , erc20Token .name , erc20Token .unit , "ETH" , params .MainnetChainConfig ,
529
- "https://etherscan.io/tx/" ,
531
+ blockExplorerPrefix ,
530
532
etherScan ,
531
533
erc20Token .token ,
532
534
)
@@ -827,6 +829,16 @@ func (backend *Backend) SystemOpen(url string) error {
827
829
}
828
830
}
829
831
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
+ }
830
842
return errp .Newf ("Blocked /open with url: %s" , url )
831
843
}
832
844
@@ -997,4 +1009,10 @@ func (backend *Backend) ExportLogs() error {
997
1009
return err
998
1010
}
999
1011
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
1000
1018
}
0 commit comments