fixed GetBlocks Handler

This commit is contained in:
Dustin Brickwood 2018-04-17 09:33:20 -04:00
commit 21eaf052af
2 changed files with 14 additions and 4 deletions

View file

@ -8,8 +8,10 @@ import (
"net/http" "net/http"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/shyftdb"
"github.com/gorilla/mux" "github.com/gorilla/mux"
"github.com/syndtr/goleveldb/leveldb" "github.com/syndtr/goleveldb/leveldb"
"github.com/syndtr/goleveldb/leveldb/opt"
"github.com/syndtr/goleveldb/leveldb/util" "github.com/syndtr/goleveldb/leveldb/util"
) )
@ -77,13 +79,21 @@ func GetBalances(w http.ResponseWriter, r *http.Request) {
// GetBlocksMined get blocks mined // GetBlocksMined get blocks mined
func GetBlocksMined(w http.ResponseWriter, r *http.Request) { func GetBlocksMined(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) logger.Print("Check logs")
address := vars["address"] blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", &opt.Options{
ErrorIfMissing: true,
ReadOnly: true,
})
if err != nil {
logger.Print(err)
return
}
blocks := shyftdb.GetAllBlocks(blockExplorerDb)
w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "Get Blocks Mined", address) fmt.Fprintln(w, "Get Blocks Mined", blocks)
} }
// GetTransactions gets txs // GetTransactions gets txs

View file

@ -30,7 +30,7 @@ var routes = Routes{
Route{ Route{
"GetBlocksMined", "GetBlocksMined",
"GET", "GET",
"/api/get_blocks_mined/{address}", "/api/get_blocks_mined",
GetBlocksMined, GetBlocksMined,
}, },
Route{ Route{