diff --git a/server/public.go b/server/public.go index a9207822..7aae554a 100644 --- a/server/public.go +++ b/server/public.go @@ -87,6 +87,7 @@ func NewPublicServer(binding string, certFiles string, db *db.RocksDB, chain bch // 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.Handle(path+"static/", http.StripPrefix("/static/", http.FileServer(http.Dir("./static/")))) // API calls serveMux.HandleFunc(path+"api/block-index/", s.jsonHandler(s.apiBlockIndex)) @@ -319,6 +320,12 @@ func setTxToTemplateData(td *TemplateData, tx *api.Tx) *TemplateData { return td } +func (s *PublicServer) templateForTx(tx *api.Tx) (tpl, *TemplateData, error) { + data := s.newTemplateData() + data.Tx = tx + return txTpl, data, nil +} + func (s *PublicServer) explorerTx(r *http.Request) (tpl, *TemplateData, error) { var tx *api.Tx if i := strings.LastIndexByte(r.URL.Path, '/'); i > 0 { @@ -331,9 +338,16 @@ func (s *PublicServer) explorerTx(r *http.Request) (tpl, *TemplateData, error) { return errorTpl, nil, err } } + return s.templateForTx(tx) +} + +func (s *PublicServer) templateForAddress(address *api.Address) (tpl, *TemplateData, error) { data := s.newTemplateData() - data.Tx = tx - return txTpl, data, nil + data.AddrStr = address.AddrStr + data.Address = address + data.Page = address.Page + data.PagingRange, data.PrevPage, data.NextPage = getPagingRange(address.Page, address.TotalPages) + return addressTpl, data, nil } func (s *PublicServer) explorerAddress(r *http.Request) (tpl, *TemplateData, error) { @@ -349,12 +363,33 @@ func (s *PublicServer) explorerAddress(r *http.Request) (tpl, *TemplateData, err return errorTpl, nil, err } } - data := s.newTemplateData() - data.AddrStr = address.AddrStr - data.Address = address - data.Page = address.Page - data.PagingRange, data.PrevPage, data.NextPage = getPagingRange(address.Page, address.TotalPages) - return addressTpl, data, nil + return s.templateForAddress(address) +} + +func (s *PublicServer) explorerSearch(r *http.Request) (tpl, *TemplateData, error) { + q := strings.TrimSpace(r.URL.Query().Get("q")) + if len(q) > 0 { + } + var tx *api.Tx + var address *api.Address + var err error + if i := strings.LastIndexByte(r.URL.Path, '/'); i > 0 { + bestheight, _, err := s.db.GetBestBlock() + if err == nil { + tx, err = s.api.GetTransaction(q, bestheight, true) + if err == nil { + return s.templateForTx(tx) + } + } + address, err = s.api.GetAddress(q, 0, txsOnPage, false) + if err == nil { + return s.templateForAddress(address) + } + } + if err == nil { + err = api.NewApiError(fmt.Sprintf("No matching records found for '%v'", q), true) + } + return errorTpl, nil, err } func getPagingRange(page int, total int) ([]int, int, int) { diff --git a/static/css/main.css b/static/css/main.css index f2ad1378..53928a27 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -31,6 +31,23 @@ h3 { height: 16px; } +.navbar-form { + padding-left: 15px; + padding-bottom: 1px; +} + +.navbar-form .form-control { + background-color: gray; + color: #fff; + border-radius: 3px; + -webkit-border-radius: 3px; + -moz-border-radius: 3px; + border: 0; + -webkit-box-shadow: 1px 1px 0 0 rgba(255, 255, 255, .41), inset 1px 1px 3px 0 rgba(0, 0, 0, .10); + -moz-box-shadow: 1px 1px 0 0 rgba(255, 255, 255, .41), inset 1px 1px 3px 0 rgba(0, 0, 0, .10); + box-shadow: 1px 1px 0 0 rgba(255, 255, 255, .41), inset 1px 1px 3px 0 rgba(0, 0, 0, .10); +} + @media (min-width: 768px) { .container { max-width: 750px; @@ -47,6 +64,9 @@ h3 { .octicon { height: 24px; } + .navbar-form .form-control { + width: 350px; + } } @media (min-width: 1200px) { @@ -59,6 +79,9 @@ h3 { .octicon { height: 32px; } + .navbar-form .form-control { + width: 360px; + } } #header { @@ -194,6 +217,18 @@ h3 { padding-left: .25rem; } +::-webkit-input-placeholder { + color: #CCC!important; + font-style: italic; + font-size: 14px; +} + +::-moz-placeholder { + color: #CCC!important; + font-style: italic; + font-size: 14px; +} + .h-container { display: -webkit-box; display: -ms-flexbox; diff --git a/static/templates/base.html b/static/templates/base.html index 5ab2fb3e..2915944c 100644 --- a/static/templates/base.html +++ b/static/templates/base.html @@ -32,6 +32,11 @@ +