Add search for tx/address to explorer
This commit is contained in:
parent
a259d4713c
commit
c6462bb0e7
@ -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) {
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -32,6 +32,11 @@
|
||||
<span class="navbar-text">
|
||||
{{.CoinName}} Explorer
|
||||
</span>
|
||||
<span class="d-none d-md-flex navbar-form navbar-left">
|
||||
<form id="search" action="/explorer/search" method="get">
|
||||
<input name="q" type="text" class="form-control" placeholder="Search for block, transaction or address" focus="true">
|
||||
</form>
|
||||
</span>
|
||||
<ul class="navbar-nav flex-row ml-md-auto d-none d-md-flex">
|
||||
<li class="nav-item">
|
||||
<a href="https://trezor.io/" class="nav-link">TREZOR</a>
|
||||
|
||||
@ -28,7 +28,9 @@
|
||||
</td>
|
||||
</tr>
|
||||
{{- else -}}
|
||||
<tr><td>No Inputs</td></tr>
|
||||
<tr>
|
||||
<td>No Inputs</td>
|
||||
</tr>
|
||||
{{- end -}}
|
||||
</tbody>
|
||||
</table>
|
||||
@ -61,7 +63,9 @@
|
||||
</td>
|
||||
</tr>
|
||||
{{- else -}}
|
||||
<tr><td>No Outputs</td></tr>
|
||||
<tr>
|
||||
<td>No Outputs</td>
|
||||
</tr>
|
||||
{{- end -}}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user