mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
sending getAllBlocks to client successfully
This commit is contained in:
parent
18bc415b0d
commit
d989e42827
2 changed files with 18 additions and 24 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -26,6 +26,9 @@ type SBlock struct {
|
|||
|
||||
//blockRes struct
|
||||
type blockRes struct {
|
||||
hash string
|
||||
coinbase string
|
||||
number int
|
||||
Blocks []SBlock
|
||||
}
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue