diff --git a/configs/coins/bcash.json b/configs/coins/bcash.json index d150cd5f..115f33fe 100644 --- a/configs/coins/bcash.json +++ b/configs/coins/bcash.json @@ -44,7 +44,7 @@ "system_user": "blockbook-bcash", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "", "block_chain": { "parse": true, diff --git a/configs/coins/bcash_testnet.json b/configs/coins/bcash_testnet.json index 1e539894..4287d2ba 100644 --- a/configs/coins/bcash_testnet.json +++ b/configs/coins/bcash_testnet.json @@ -44,7 +44,7 @@ "system_user": "blockbook-bcash", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "", "block_chain": { "parse": true, diff --git a/configs/coins/bgold.json b/configs/coins/bgold.json index eea10626..3cb4d0e9 100644 --- a/configs/coins/bgold.json +++ b/configs/coins/bgold.json @@ -239,7 +239,7 @@ "system_user": "blockbook-bgold", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "-dbmaxopenfiles=128", "block_chain": { "parse": true, diff --git a/configs/coins/bitcoin.json b/configs/coins/bitcoin.json index b781d956..97798bd8 100644 --- a/configs/coins/bitcoin.json +++ b/configs/coins/bitcoin.json @@ -47,7 +47,7 @@ "system_user": "blockbook-bitcoin", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "-dbcache=1073741824", "block_chain": { "parse": true, diff --git a/configs/coins/bitcoin_testnet.json b/configs/coins/bitcoin_testnet.json index 880fbaa5..a2ef7e0d 100644 --- a/configs/coins/bitcoin_testnet.json +++ b/configs/coins/bitcoin_testnet.json @@ -47,7 +47,7 @@ "system_user": "blockbook-bitcoin", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "", "block_chain": { "parse": true, diff --git a/configs/coins/zcash.json b/configs/coins/zcash.json index a95543f8..d55165d8 100644 --- a/configs/coins/zcash.json +++ b/configs/coins/zcash.json @@ -47,7 +47,7 @@ "system_user": "blockbook-zcash", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "", "block_chain": { "parse": true, diff --git a/configs/coins/zcash_testnet.json b/configs/coins/zcash_testnet.json index 43774a1e..5f6d2ca4 100644 --- a/configs/coins/zcash_testnet.json +++ b/configs/coins/zcash_testnet.json @@ -47,7 +47,7 @@ "system_user": "blockbook-zcash", "internal_binding_template": ":{{.Ports.BlockbookInternal}}", "public_binding_template": ":{{.Ports.BlockbookPublic}}", - "explorer_url": "/explorer", + "explorer_url": "", "additional_params": "", "block_chain": { "parse": true, diff --git a/docs/config.md b/docs/config.md index af3f5cd0..61e76710 100644 --- a/docs/config.md +++ b/docs/config.md @@ -79,7 +79,7 @@ Good examples of coin configuration are * `system_user` – User used to run Blockbook service. See convention note in [build guide](/docs/build.md#on-naming-conventions-and-versioning). * `internal_binding_template` – Template for *-internal* parameter. See note on templates below. * `public_binding_template` – Template for *-public* parameter. See note on templates below. - * `explorer_url` – URL of blockchain explorer. + * `explorer_url` – URL of blockchain explorer. Leave empty for internal explorer. * `additional_params` – Additional params of exec command (see [Dogecoin definition](configs/coins/dogecoin.json)). * `block_chain` – Configuration of BlockChain type that ensures communication with back-end service. All options must be tweaked for each individual coin separely. diff --git a/server/public.go b/server/public.go index fe48701f..0a089f53 100644 --- a/server/public.go +++ b/server/public.go @@ -25,20 +25,21 @@ const txsInAPI = 1000 // PublicServer is a handle to public http server type PublicServer struct { - binding string - certFiles string - socketio *SocketIoServer - https *http.Server - db *db.RocksDB - txCache *db.TxCache - chain bchain.BlockChain - chainParser bchain.BlockChainParser - api *api.Worker - explorerURL string - metrics *common.Metrics - is *common.InternalState - templates []*template.Template - debug bool + binding string + certFiles string + socketio *SocketIoServer + https *http.Server + db *db.RocksDB + txCache *db.TxCache + chain bchain.BlockChain + chainParser bchain.BlockChainParser + api *api.Worker + explorerURL string + internalExplorer bool + metrics *common.Metrics + is *common.InternalState + templates []*template.Template + debug bool } // NewPublicServer creates new public server http interface to blockbook and returns its handle @@ -63,19 +64,20 @@ func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bch } s := &PublicServer{ - binding: binding, - certFiles: certFiles, - https: https, - api: api, - socketio: socketio, - db: db, - txCache: txCache, - chain: chain, - chainParser: chain.GetChainParser(), - explorerURL: explorerURL, - metrics: metrics, - is: is, - debug: debugMode, + binding: binding, + certFiles: certFiles, + https: https, + api: api, + socketio: socketio, + db: db, + txCache: txCache, + chain: chain, + chainParser: chain.GetChainParser(), + explorerURL: explorerURL, + internalExplorer: explorerURL == "", + metrics: metrics, + is: is, + debug: debugMode, } s.templates = parseTemplates() @@ -106,15 +108,18 @@ func (s *PublicServer) ConnectFullPublicInterface() { _, path := splitBinding(s.binding) // support for tests of socket.io interface serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/"))) - // redirect to wallet requests for tx and address, possibly to external site - serveMux.HandleFunc(path+"tx/", s.txRedirect) - serveMux.HandleFunc(path+"address/", s.addressRedirect) - // explorer - serveMux.HandleFunc(path+"explorer/tx/", s.htmlTemplateHandler(s.explorerTx)) - serveMux.HandleFunc(path+"explorer/address/", s.htmlTemplateHandler(s.explorerAddress)) - serveMux.HandleFunc(path+"explorer/search/", s.htmlTemplateHandler(s.explorerSearch)) - serveMux.HandleFunc(path+"explorer/blocks", s.htmlTemplateHandler(s.explorerBlocks)) - serveMux.HandleFunc(path+"explorer/block/", s.htmlTemplateHandler(s.explorerBlock)) + if s.internalExplorer { + // internal explorer handlers + serveMux.HandleFunc(path+"tx/", s.htmlTemplateHandler(s.explorerTx)) + serveMux.HandleFunc(path+"address/", s.htmlTemplateHandler(s.explorerAddress)) + serveMux.HandleFunc(path+"search/", s.htmlTemplateHandler(s.explorerSearch)) + serveMux.HandleFunc(path+"blocks", s.htmlTemplateHandler(s.explorerBlocks)) + serveMux.HandleFunc(path+"block/", s.htmlTemplateHandler(s.explorerBlock)) + } else { + // redirect to wallet requests for tx and address, possibly to external site + serveMux.HandleFunc(path+"tx/", s.txRedirect) + serveMux.HandleFunc(path+"address/", s.addressRedirect) + } // API calls serveMux.HandleFunc(path+"api/block-index/", s.jsonHandler(s.apiBlockIndex)) serveMux.HandleFunc(path+"api/tx/", s.jsonHandler(s.apiTx)) @@ -147,17 +152,13 @@ func (s *PublicServer) OnNewTxAddr(txid string, addr string, isOutput bool) { } func (s *PublicServer) txRedirect(w http.ResponseWriter, r *http.Request) { - if s.explorerURL != "" { - http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302) - s.metrics.ExplorerViews.With(common.Labels{"action": "tx-redirect"}).Inc() - } + http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302) + s.metrics.ExplorerViews.With(common.Labels{"action": "tx-redirect"}).Inc() } func (s *PublicServer) addressRedirect(w http.ResponseWriter, r *http.Request) { - if s.explorerURL != "" { - http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302) - s.metrics.ExplorerViews.With(common.Labels{"action": "address-redirect"}).Inc() - } + http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302) + s.metrics.ExplorerViews.With(common.Labels{"action": "address-redirect"}).Inc() } func splitBinding(binding string) (addr string, path string) { @@ -221,8 +222,9 @@ func (s *PublicServer) jsonHandler(handler func(r *http.Request) (interface{}, e func (s *PublicServer) newTemplateData() *TemplateData { return &TemplateData{ - CoinName: s.is.Coin, - CoinShortcut: s.is.CoinShortcut, + CoinName: s.is.Coin, + CoinShortcut: s.is.CoinShortcut, + InternalExplorer: s.internalExplorer, } } @@ -296,19 +298,20 @@ const ( ) type TemplateData struct { - CoinName string - CoinShortcut string - Address *api.Address - AddrStr string - Tx *api.Tx - Error *api.ApiError - Blocks *api.Blocks - Block *api.Block - Info *api.SystemInfo - Page int - PrevPage int - NextPage int - PagingRange []int + CoinName string + CoinShortcut string + InternalExplorer bool + Address *api.Address + AddrStr string + Tx *api.Tx + Error *api.ApiError + Blocks *api.Blocks + Block *api.Block + Info *api.SystemInfo + Page int + PrevPage int + NextPage int + PagingRange []int } func parseTemplates() []*template.Template { @@ -453,20 +456,20 @@ func (s *PublicServer) explorerSearch(w http.ResponseWriter, r *http.Request) (t if len(q) > 0 { block, err = s.api.GetBlock(q, 0, 1) if err == nil { - http.Redirect(w, r, joinURL("/explorer/block/", block.Hash), 302) + http.Redirect(w, r, joinURL("/block/", block.Hash), 302) return noTpl, nil, nil } bestheight, _, err = s.db.GetBestBlock() if err == nil { tx, err = s.api.GetTransaction(q, bestheight, false) if err == nil { - http.Redirect(w, r, joinURL("/explorer/tx/", tx.Txid), 302) + http.Redirect(w, r, joinURL("/tx/", tx.Txid), 302) return noTpl, nil, nil } } address, err = s.api.GetAddress(q, 0, 1, true) if err == nil { - http.Redirect(w, r, joinURL("/explorer/address/", address.AddrStr), 302) + http.Redirect(w, r, joinURL("/address/", address.AddrStr), 302) return noTpl, nil, nil } } diff --git a/static/css/main.css b/static/css/main.css index 834db317..b18df624 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -135,7 +135,7 @@ h3 { .line-top { border-top: 1px solid #EAEAEA; - padding: 15px 0 0; + padding: 10px 0 0; } .line-mid { @@ -157,6 +157,7 @@ h3 { white-space: nowrap; vertical-align: baseline; border-radius: .25em; + margin-top: 5px; } .txvalues:not(:last-child) { diff --git a/static/templates/address.html b/static/templates/address.html index 7300d079..7a56e729 100644 --- a/static/templates/address.html +++ b/static/templates/address.html @@ -2,8 +2,8 @@

Address {{formatAmount $addr.Balance}} {{$cs}}

-
- {{$addr.AddrStr}} +
+ {{$addr.AddrStr}}

Confirmed

diff --git a/static/templates/base.html b/static/templates/base.html index c732992f..05bebd41 100644 --- a/static/templates/base.html +++ b/static/templates/base.html @@ -14,8 +14,7 @@