Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explorer V2 #202

Merged
merged 3 commits into from
Oct 4, 2017
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ rebuilddb.conf
cmd/rebuilddb/rebuilddb
cmd/scanblocks/scanblocks
fullscan.json
*.swp
*.swo
CURRENT
LOCK
LOG
Expand Down
4 changes: 2 additions & 2 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
ISC License

Copyright (c) 2017, Jonathan Chappelow
Copyright (c) 2017, The dcrdata developers
Copyright (c) 2015-2016 The Decred developers

Permission to use, copy, modify, and/or distribute this software for any
Expand Down
41 changes: 11 additions & 30 deletions apimiddleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,26 +168,6 @@ func (c *appContext) BlockHashPathAndIndexCtx(next http.Handler) http.Handler {
})
}

func (c *appContext) BlockHashPathOrIndexCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hash := chi.URLParam(r, "blockhash")
height, _ := c.BlockData.GetBlockHeight(hash)
idx, err := strconv.ParseInt(hash, 10, 0)
if err == nil {
height = idx
hash, err = c.BlockData.GetBlockHash(idx)
if err != nil {
apiLog.Errorf("GetBlockHash(%d) failed: %v", idx, err)
http.NotFound(w, r)
return
}
}
ctx := context.WithValue(r.Context(), ctxBlockHash, hash)
ctx = context.WithValue(ctx, ctxBlockIndex, height)
next.ServeHTTP(w, r.WithContext(ctx))
})
}

// TransactionHashCtx returns a http.HandlerFunc that embeds the value at the url
// part {txid} into the request context
func TransactionHashCtx(next http.Handler) http.Handler {
Expand Down Expand Up @@ -224,16 +204,6 @@ func AddressPathCtx(next http.Handler) http.Handler {
})
}

// SearchPathCtx returns a http.HandlerFunc that embeds the value at the url part
// {search} into the request context
func SearchPathCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
str := chi.URLParam(r, "search")
ctx := context.WithValue(r.Context(), ctxSearch, str)
next.ServeHTTP(w, r.WithContext(ctx))
})
}

// apiDocs generates a middleware with a "docs" in the context containing a
// map of the routers handlers, etc.
func apiDocs(mux *chi.Mux) func(next http.Handler) http.Handler {
Expand All @@ -248,6 +218,17 @@ func apiDocs(mux *chi.Mux) func(next http.Handler) http.Handler {
}
}

// SearchPathCtx returns a http.HandlerFunc that embeds the value at the url part
// {search} into the request context (Still need this for the error page)
// TODO: make new error system
func SearchPathCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
str := chi.URLParam(r, "search")
ctx := context.WithValue(r.Context(), ctxSearch, str)
next.ServeHTTP(w, r.WithContext(ctx))
})
}

// APIDirectory is the actual handler used with apiDocs
// (e.g. mux.With(apiDocs(mux)).HandleFunc("/help", APIDirectory))
func APIDirectory(w http.ResponseWriter, r *http.Request) {
Expand Down
2 changes: 0 additions & 2 deletions apiroutes.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ type APIDataSource interface {
GetHeader(idx int) *dcrjson.GetBlockHeaderVerboseResult
GetBlockVerbose(idx int, verboseTx bool) *dcrjson.GetBlockVerboseResult
GetBlockVerboseByHash(hash string, verboseTx bool) *dcrjson.GetBlockVerboseResult
GetBlockVerboseWithStakeTxDetails(hash string) *apitypes.BlockDataWithTxType
GetRawTransaction(txid string) *apitypes.Tx
GetRawTransactionWithPrevOutAddresses(txid string) (*apitypes.Tx, [][]string)
GetExplorerTxData(txid string) *apitypes.ExplorerTxData
GetVoteInfo(txid string) (*apitypes.VoteInfo, error)
GetAllTxIn(txid string) []*apitypes.TxIn
GetAllTxOut(txid string) []*apitypes.TxOut
Expand Down
Loading