Add initial tx explorer template + favicon
This commit is contained in:
parent
94873f4d86
commit
b52b861db2
@ -8,6 +8,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,6 +33,7 @@ type PublicServer struct {
|
|||||||
explorerURL string
|
explorerURL string
|
||||||
metrics *common.Metrics
|
metrics *common.Metrics
|
||||||
is *common.InternalState
|
is *common.InternalState
|
||||||
|
txTpl *template.Template
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewPublicServerS creates new public server http interface to blockbook and returns its handle
|
// NewPublicServerS creates new public server http interface to blockbook and returns its handle
|
||||||
@ -69,6 +71,8 @@ func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bch
|
|||||||
is: is,
|
is: is,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// favicon
|
||||||
|
serveMux.Handle(path+"favicon.ico", http.FileServer(http.Dir("./static/")))
|
||||||
// support for tests of socket.io interface
|
// support for tests of socket.io interface
|
||||||
serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/")))
|
serveMux.Handle(path+"test.html", http.FileServer(http.Dir("./static/")))
|
||||||
// redirect to Bitcore for details of transaction
|
// redirect to Bitcore for details of transaction
|
||||||
@ -76,12 +80,16 @@ func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bch
|
|||||||
serveMux.HandleFunc(path+"address/", s.addressRedirect)
|
serveMux.HandleFunc(path+"address/", s.addressRedirect)
|
||||||
// explorer
|
// explorer
|
||||||
serveMux.HandleFunc(path+"explorer/tx/", s.explorerTx)
|
serveMux.HandleFunc(path+"explorer/tx/", s.explorerTx)
|
||||||
// API call used to detect state of Blockbook
|
// API calls
|
||||||
serveMux.HandleFunc(path+"api/block-index/", s.apiBlockIndex)
|
serveMux.HandleFunc(path+"api/block-index/", s.apiBlockIndex)
|
||||||
|
serveMux.HandleFunc(path+"api/tx/", s.apiTx)
|
||||||
// handle socket.io
|
// handle socket.io
|
||||||
serveMux.Handle(path+"socket.io/", socketio.GetHandler())
|
serveMux.Handle(path+"socket.io/", socketio.GetHandler())
|
||||||
// default handler
|
// default handler
|
||||||
serveMux.HandleFunc(path, s.index)
|
serveMux.HandleFunc(path, s.index)
|
||||||
|
|
||||||
|
s.txTpl = template.Must(template.New("tx").ParseFiles("./static/templates/tx.html", "./static/templates/base.html"))
|
||||||
|
|
||||||
return s, nil
|
return s, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -151,20 +159,22 @@ func (s *PublicServer) addressRedirect(w http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
func (s *PublicServer) explorerTx(w http.ResponseWriter, r *http.Request) {
|
func (s *PublicServer) explorerTx(w http.ResponseWriter, r *http.Request) {
|
||||||
var tx *api.Tx
|
var tx *api.Tx
|
||||||
var err error
|
|
||||||
if i := strings.LastIndexByte(r.URL.Path, '/'); i > 0 {
|
if i := strings.LastIndexByte(r.URL.Path, '/'); i > 0 {
|
||||||
txid := r.URL.Path[i+1:]
|
txid := r.URL.Path[i+1:]
|
||||||
bestheight, _, err := s.db.GetBestBlock()
|
bestheight, _, err := s.db.GetBestBlock()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
tx, err = s.api.GetTransaction(txid, bestheight, true)
|
tx, err = s.api.GetTransaction(txid, bestheight, true)
|
||||||
}
|
} else {
|
||||||
}
|
|
||||||
if err == nil {
|
|
||||||
buf, err := json.MarshalIndent(tx, "", " ")
|
|
||||||
if err != nil {
|
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
}
|
}
|
||||||
w.Write(buf)
|
}
|
||||||
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
|
data := struct {
|
||||||
|
CoinName string
|
||||||
|
Tx *api.Tx
|
||||||
|
}{s.is.Coin, tx}
|
||||||
|
if err := s.txTpl.ExecuteTemplate(w, "base.html", data); err != nil {
|
||||||
|
glog.Error(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,6 +209,7 @@ func (s *PublicServer) index(w http.ResponseWriter, r *http.Request) {
|
|||||||
LastMempoolTime: mt,
|
LastMempoolTime: mt,
|
||||||
About: blockbookAbout,
|
About: blockbookAbout,
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
buf, err := json.MarshalIndent(a, "", " ")
|
buf, err := json.MarshalIndent(a, "", " ")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
glog.Error(err)
|
glog.Error(err)
|
||||||
@ -231,6 +242,25 @@ func (s *PublicServer) apiBlockIndex(w http.ResponseWriter, r *http.Request) {
|
|||||||
BlockHash: hash,
|
BlockHash: hash,
|
||||||
About: blockbookAbout,
|
About: blockbookAbout,
|
||||||
}
|
}
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
json.NewEncoder(w).Encode(r)
|
json.NewEncoder(w).Encode(r)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *PublicServer) apiTx(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var tx *api.Tx
|
||||||
|
var err error
|
||||||
|
if i := strings.LastIndexByte(r.URL.Path, '/'); i > 0 {
|
||||||
|
txid := r.URL.Path[i+1:]
|
||||||
|
bestheight, _, err := s.db.GetBestBlock()
|
||||||
|
if err == nil {
|
||||||
|
tx, err = s.api.GetTransaction(txid, bestheight, true)
|
||||||
|
} else {
|
||||||
|
glog.Error(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
w.Header().Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
json.NewEncoder(w).Encode(tx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
BIN
static/favicon.ico
Normal file
BIN
static/favicon.ico
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 856 B |
17
static/templates/base.html
Normal file
17
static/templates/base.html
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8">
|
||||||
|
<meta name="viewport" content="width=device-width,initial-scale=1.0">
|
||||||
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
|
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||||
|
<meta name="description" content="TREZOR {{.CoinName}} Explorer">
|
||||||
|
<title>TREZOR {{.CoinName}} Explorer</title>
|
||||||
|
</head>
|
||||||
|
|
||||||
|
<body>
|
||||||
|
{{template "tx" .Tx}}
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
3
static/templates/tx.html
Normal file
3
static/templates/tx.html
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
{{define "tx"}}
|
||||||
|
{{.Txid}}
|
||||||
|
{{end}}
|
||||||
@ -4,8 +4,7 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
|
||||||
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm"
|
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
|
||||||
crossorigin="anonymous">
|
|
||||||
<style>
|
<style>
|
||||||
.row {
|
.row {
|
||||||
margin-top: 1%;
|
margin-top: 1%;
|
||||||
@ -415,4 +414,4 @@
|
|||||||
document.getElementById('serverAddress').value = window.location.protocol.replace("http", "ws") + "//" + window.location.host;
|
document.getElementById('serverAddress').value = window.location.protocol.replace("http", "ws") + "//" + window.location.host;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
Loading…
Reference in New Issue
Block a user