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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
out, err := json.Marshal(block3)
|
// out, err := json.Marshal(block3)
|
||||||
if err != nil {
|
// if err != nil {
|
||||||
http.Error(w, err.Error(), 500)
|
// http.Error(w, err.Error(), 500)
|
||||||
return
|
// return
|
||||||
}
|
// }
|
||||||
|
|
||||||
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, "block", string(out))
|
fmt.Fprintln(w, "blocksss", block3)
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetInternalTransactions gets internal txs
|
//GetInternalTransactions gets internal txs
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,9 @@ type SBlock struct {
|
||||||
|
|
||||||
//blockRes struct
|
//blockRes struct
|
||||||
type blockRes struct {
|
type blockRes struct {
|
||||||
|
hash string
|
||||||
|
coinbase string
|
||||||
|
number int
|
||||||
Blocks []SBlock
|
Blocks []SBlock
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -270,8 +273,7 @@ func WriteMinerReward(db *leveldb.DB, block *types.Block) {
|
||||||
//////////
|
//////////
|
||||||
//GetAllBlocks returns []SBlock blocks for API
|
//GetAllBlocks returns []SBlock blocks for API
|
||||||
func GetAllBlocks(sqldb *sql.DB) []SBlock {
|
func GetAllBlocks(sqldb *sql.DB) []SBlock {
|
||||||
var arr []SBlock
|
var arr blockRes
|
||||||
fmt.Println("HERE+++++++++++")
|
|
||||||
rows, err := sqldb.Query(`
|
rows, err := sqldb.Query(`
|
||||||
SELECT
|
SELECT
|
||||||
number,
|
number,
|
||||||
|
|
@ -282,8 +284,6 @@ func GetAllBlocks(sqldb *sql.DB) []SBlock {
|
||||||
fmt.Println("err")
|
fmt.Println("err")
|
||||||
|
|
||||||
}
|
}
|
||||||
fmt.Println("ROWS")
|
|
||||||
fmt.Println(rows)
|
|
||||||
defer rows.Close()
|
defer rows.Close()
|
||||||
|
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
|
|
@ -295,21 +295,15 @@ func GetAllBlocks(sqldb *sql.DB) []SBlock {
|
||||||
&hash,
|
&hash,
|
||||||
&coinbase,
|
&coinbase,
|
||||||
)
|
)
|
||||||
sblock := SBlock{hash: hash, number: num, coinbase: coinbase}
|
arr.Blocks = append(arr.Blocks, SBlock{
|
||||||
arr := append(arr, sblock)
|
hash: hash,
|
||||||
fmt.Println("++++++++++++++++", arr)
|
number: num,
|
||||||
// fmt.Println("++++++++++++++++", hash)
|
coinbase: coinbase,
|
||||||
// fmt.Println("++++++++++++++++", coinbase)
|
})
|
||||||
|
|
||||||
// }
|
|
||||||
// err = rows.Err()
|
|
||||||
// if err != nil {
|
|
||||||
// return err
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
fmt.Println("++++++++++++++++", arr.Blocks)
|
||||||
|
|
||||||
return arr
|
return arr.Blocks
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetBlock queries to send single block info
|
//GetBlock queries to send single block info
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue