before pull

This commit is contained in:
Dustin Brickwood 2018-04-20 10:25:06 -04:00
parent 21eaf052af
commit d974aad0d5
2 changed files with 44 additions and 68 deletions

View file

@ -2,84 +2,71 @@ package main
///@NOTE Shyft handler functions when endpoints are hit ///@NOTE Shyft handler functions when endpoints are hit
import ( import (
"encoding/json"
"fmt" "fmt"
logger "log" logger "log"
"net/http" "net/http"
"github.com/ethereum/go-ethereum/log" shyftdb "github.com/ethereum/go-ethereum/shyftdb"
"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/opt"
"github.com/syndtr/goleveldb/leveldb/util"
) )
// GetAllTransactions gets txs // GetTransaction gets txs
func GetAllTransactions(w http.ResponseWriter, r *http.Request) { func GetTransaction(w http.ResponseWriter, r *http.Request) {
db, err := leveldb.OpenFile(`../shyftData/geth/blockExplorerDb/`, nil) // vars := mux.Vars(r)
if err != nil { // address := vars["address"]
return
}
var data []byte
iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil)
for iter.Next() {
logger.Printf("%s\t%s", "\nALL TX VALUE: ", string(iter.Value())) //tx := shyftdb.GetTransaction()
data = append(iter.Value())
}
logger.Print("outside loop", data)
iter.Release()
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)
json.NewEncoder(w).Encode(data) //fmt.Fprintln(w, "Get All Transactions", addresses)
}
// GetAllTransactions gets txs
func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
//txs := shyftdb.GetAllTransactions()
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
//fmt.Fprintln(w, "Get All Transactions", address)
} }
// GetBalance gets balance // GetBalance gets balance
func GetBalance(w http.ResponseWriter, r *http.Request) { func GetBalance(w http.ResponseWriter, r *http.Request) {
// vars := mux.Vars(r) // vars := mux.Vars(r)
// address := vars["address"] // address := vars["address"]
address := "0x43ec6d0942f7faef069f7f63d0384a27f529b062" //addressBytes := []byte(address)
addressBytes := []byte(address)
db, err := leveldb.OpenFile(`../shyftData/geth/blockExplorerDb/`, nil)
if err != nil {
return
}
// 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") w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(bodyString) //fmt.Fprintln(w, "Get Balances", addresses)
} }
// GetBalances gets balances // GetBalances gets balances
func GetBalances(w http.ResponseWriter, r *http.Request) { func GetBalances(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
addresses := vars["addresses"]
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 Balances", addresses) //fmt.Fprintln(w, "Get Balances", addresses)
} }
// GetBlocksMined get blocks mined //GetBlock returns block json
func GetBlocksMined(w http.ResponseWriter, r *http.Request) { func GetBlock(w http.ResponseWriter, r *http.Request) {
logger.Print("Check logs") //block := shyftdb.GetBlock()
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
//fmt.Fprintln(w, "block", block)
}
// GetAllBlocks response
func GetAllBlocks(w http.ResponseWriter, r *http.Request) {
blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", &opt.Options{ blockExplorerDb, err := leveldb.OpenFile("./shyftData/geth/blockExplorerDb/", &opt.Options{
ErrorIfMissing: true, ErrorIfMissing: true,
ReadOnly: true, ReadOnly: true,
@ -93,18 +80,7 @@ func GetBlocksMined(w http.ResponseWriter, r *http.Request) {
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", blocks) fmt.Fprintln(w, "blocks", blocks)
}
// GetTransactions gets txs
func GetTransactions(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
address := vars["address"]
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
w.WriteHeader(http.StatusOK)
fmt.Fprintln(w, "Get Transactions", address)
} }
//GetInternalTransactions gets internal txs //GetInternalTransactions gets internal txs
@ -115,7 +91,7 @@ func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
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, "GetInternalTransactions", address) fmt.Fprintln(w, "Get InternalTransactions", address)
} }
//GetInternalTransactionsHash gets internal txs hash //GetInternalTransactionsHash gets internal txs hash

View file

@ -28,23 +28,23 @@ var routes = Routes{
GetBalances, GetBalances,
}, },
Route{ Route{
"GetBlocksMined", "GetAllBlocks",
"GET", "GET",
"/api/get_blocks_mined", "/api/get_all_blocks",
GetBlocksMined, GetAllBlocks,
},
Route{
"GetTransactions",
"GET",
"/api/get_transactions/{address}",
GetTransactions,
}, },
Route{ Route{
"GetAllTransactions", "GetAllTransactions",
"GET", "GET",
"/api/get_all_transactions/", "/api/get_all_transactions",
GetAllTransactions, GetAllTransactions,
}, },
Route{
"GetTransaction",
"GET",
"/api/get_transaction/{address}",
GetTransaction,
},
Route{ Route{
"GetInternalTransactions", "GetInternalTransactions",
"GET", "GET",