From d989e428272810f4c120de0f17586c9cfd2b8a75 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Fri, 20 Apr 2018 16:39:09 -0400 Subject: [PATCH] sending getAllBlocks to client successfully --- blockExplorerApi/handler.go | 12 ++++++------ shyftdb/shyft_database_util.go | 30 ++++++++++++------------------ 2 files changed, 18 insertions(+), 24 deletions(-) diff --git a/blockExplorerApi/handler.go b/blockExplorerApi/handler.go index ddc2a5abf4..59d34429ce 100644 --- a/blockExplorerApi/handler.go +++ b/blockExplorerApi/handler.go @@ -100,16 +100,16 @@ func GetAllBlocks(w http.ResponseWriter, r *http.Request) { return } - out, err := json.Marshal(block3) - if err != nil { - http.Error(w, err.Error(), 500) - return - } + // out, err := json.Marshal(block3) + // if err != nil { + // http.Error(w, err.Error(), 500) + // return + // } w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) - fmt.Fprintln(w, "block", string(out)) + fmt.Fprintln(w, "blocksss", block3) } //GetInternalTransactions gets internal txs diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 3c3a405548..be2a95a4a0 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -26,7 +26,10 @@ type SBlock struct { //blockRes struct type blockRes struct { - Blocks []SBlock + hash string + coinbase string + number int + Blocks []SBlock } //ShyftTxEntry structure @@ -270,8 +273,7 @@ func WriteMinerReward(db *leveldb.DB, block *types.Block) { ////////// //GetAllBlocks returns []SBlock blocks for API func GetAllBlocks(sqldb *sql.DB) []SBlock { - var arr []SBlock - fmt.Println("HERE+++++++++++") + var arr blockRes rows, err := sqldb.Query(` SELECT number, @@ -282,8 +284,6 @@ func GetAllBlocks(sqldb *sql.DB) []SBlock { fmt.Println("err") } - fmt.Println("ROWS") - fmt.Println(rows) defer rows.Close() for rows.Next() { @@ -295,21 +295,15 @@ func GetAllBlocks(sqldb *sql.DB) []SBlock { &hash, &coinbase, ) - sblock := SBlock{hash: hash, number: num, coinbase: coinbase} - arr := append(arr, sblock) - fmt.Println("++++++++++++++++", arr) - // fmt.Println("++++++++++++++++", hash) - // fmt.Println("++++++++++++++++", coinbase) - - // } - // err = rows.Err() - // if err != nil { - // return err - // } - + arr.Blocks = append(arr.Blocks, SBlock{ + hash: hash, + number: num, + coinbase: coinbase, + }) } + fmt.Println("++++++++++++++++", arr.Blocks) - return arr + return arr.Blocks } //GetBlock queries to send single block info