mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
api routes and handler
This commit is contained in:
parent
636cba146f
commit
be2b731d83
2 changed files with 41 additions and 25 deletions
|
|
@ -4,24 +4,58 @@ package main
|
|||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
logger "log"
|
||||
"net/http"
|
||||
|
||||
"github.com/ethereum/go-ethereum/log"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/syndtr/goleveldb/leveldb"
|
||||
"github.com/syndtr/goleveldb/leveldb/util"
|
||||
)
|
||||
|
||||
// GetAllTransactions gets txs
|
||||
func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
address := vars["address"]
|
||||
// addressBytes := []byte(address)
|
||||
db, err := leveldb.OpenFile(`../shyftData/geth/blockExplorerDb/`, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
var data []byte
|
||||
iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil)
|
||||
for iter.Next() {
|
||||
|
||||
blockExplorerDb, err := leveldb.OpenFile(`../shyftData/geth/blockExplorerDb/`, nil)
|
||||
logger.Printf("%s\t%s", "\nALL TX VALUE: ", string(iter.Value()))
|
||||
data = append(iter.Value())
|
||||
}
|
||||
|
||||
logger.Print("outside loop", data)
|
||||
iter.Release()
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
json.NewEncoder(w).Encode(data)
|
||||
}
|
||||
|
||||
// GetBalance gets balance
|
||||
func GetBalance(w http.ResponseWriter, r *http.Request) {
|
||||
// vars := mux.Vars(r)
|
||||
// address := vars["address"]
|
||||
address := "0x43ec6d0942f7faef069f7f63d0384a27f529b062"
|
||||
addressBytes := []byte(address)
|
||||
|
||||
db, err := leveldb.OpenFile(`../shyftData/geth/blockExplorerDb/`, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
data, err := blockExplorerDb.Get([]byte(address), nil)
|
||||
// if err := db.Put(addressBytes, []byte("Golang BABY WOOOOOOOOO! BARBADOS"), nil); err != nil {
|
||||
// log.Crit("Failed to store TX", "err", err)
|
||||
// }
|
||||
|
||||
data, err := db.Get(addressBytes, nil)
|
||||
if err != nil {
|
||||
log.Crit("Could not retrieve block", "err", err)
|
||||
}
|
||||
|
||||
bodyString := string(data)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
|
|
@ -30,18 +64,6 @@ func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
|
|||
json.NewEncoder(w).Encode(bodyString)
|
||||
}
|
||||
|
||||
// GetBalance gets balance
|
||||
func GetBalance(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
address := vars["address"]
|
||||
//addressBytes := []byte(address)
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
json.NewEncoder(w).Encode(address)
|
||||
}
|
||||
|
||||
// GetBalances gets balances
|
||||
func GetBalances(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ var routes = Routes{
|
|||
Route{
|
||||
"GetBalance",
|
||||
"GET",
|
||||
"/api/get_balance/{address}",
|
||||
"/api/get_balance/",
|
||||
GetBalance,
|
||||
},
|
||||
Route{
|
||||
|
|
@ -42,7 +42,7 @@ var routes = Routes{
|
|||
Route{
|
||||
"GetAllTransactions",
|
||||
"GET",
|
||||
"/api/get_all_transactions/{address}",
|
||||
"/api/get_all_transactions/",
|
||||
GetAllTransactions,
|
||||
},
|
||||
Route{
|
||||
|
|
@ -57,10 +57,4 @@ var routes = Routes{
|
|||
"/api/get_internal_transactions_hash/{transactions_hash}",
|
||||
GetInternalTransactionsHash,
|
||||
},
|
||||
// Route{
|
||||
// "PostTestData",
|
||||
// "POST",
|
||||
// "/api/post_test_data/",
|
||||
// PostTestData,
|
||||
// },
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue