mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
updated GetBlock handlers for API
This commit is contained in:
parent
361841e460
commit
2e39356a71
2 changed files with 62 additions and 20 deletions
|
|
@ -20,6 +20,11 @@ type SBlock struct {
|
|||
Hash string
|
||||
Coinbase string
|
||||
Number string
|
||||
GasUsed string
|
||||
GasLimit string
|
||||
TxCount string
|
||||
UncleCount string
|
||||
Age string
|
||||
}
|
||||
|
||||
//blockRes struct
|
||||
|
|
@ -97,9 +102,8 @@ func WriteBlock(sqldb *sql.DB, block *types.Block) error {
|
|||
panic(err)
|
||||
}
|
||||
age := time.Unix(i, 0)
|
||||
fmt.Println("TIME++++++++++++++", age)
|
||||
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txcount, uncleCount, age) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8)) RETURNING number`
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8)) RETURNING number`
|
||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age).Scan(&number)
|
||||
if qerr != nil {
|
||||
panic(qerr)
|
||||
|
|
@ -325,11 +329,18 @@ func WriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s
|
|||
func GetAllBlocks(sqldb *sql.DB) string {
|
||||
var arr blockRes
|
||||
var blockArr string
|
||||
|
||||
rows, err := sqldb.Query(`
|
||||
SELECT
|
||||
number,
|
||||
hash,
|
||||
coinbase
|
||||
coinbase,
|
||||
gasused,
|
||||
gaslimit,
|
||||
txcount,
|
||||
unclecount,
|
||||
age
|
||||
|
||||
FROM blocks`)
|
||||
if err != nil {
|
||||
fmt.Println("err")
|
||||
|
|
@ -340,16 +351,32 @@ func GetAllBlocks(sqldb *sql.DB) string {
|
|||
var num string
|
||||
var hash string
|
||||
var coinbase string
|
||||
var gasUsed string
|
||||
var gasLimit string
|
||||
var txCount string
|
||||
var uncleCount string
|
||||
var age string
|
||||
|
||||
err = rows.Scan(
|
||||
&num,
|
||||
&hash,
|
||||
&coinbase,
|
||||
&gasUsed,
|
||||
&gasLimit,
|
||||
&txCount,
|
||||
&uncleCount,
|
||||
&age,
|
||||
)
|
||||
|
||||
arr.Blocks = append(arr.Blocks, SBlock{
|
||||
Hash: hash,
|
||||
Number: num,
|
||||
Coinbase: coinbase,
|
||||
GasUsed: gasUsed,
|
||||
GasLimit: gasLimit,
|
||||
TxCount: txCount,
|
||||
UncleCount: uncleCount,
|
||||
Age: age,
|
||||
})
|
||||
|
||||
blocks, _ := json.Marshal(arr.Blocks)
|
||||
|
|
@ -367,12 +394,27 @@ func GetBlock(sqldb *sql.DB) string {
|
|||
var num string
|
||||
var hash string
|
||||
var coinbase string
|
||||
row.Scan(&num, &hash, &coinbase)
|
||||
var gasUsed string
|
||||
var gasLimit string
|
||||
var txCount string
|
||||
var uncleCount string
|
||||
var age string
|
||||
|
||||
row.Scan(&num, &hash, &coinbase, &gasUsed,
|
||||
&gasLimit,
|
||||
&txCount,
|
||||
&uncleCount,
|
||||
&age,)
|
||||
|
||||
block := SBlock{
|
||||
Hash: hash,
|
||||
Number: num,
|
||||
Coinbase: coinbase,
|
||||
GasUsed: gasUsed,
|
||||
GasLimit: gasLimit,
|
||||
TxCount: txCount,
|
||||
UncleCount: uncleCount,
|
||||
Age: age,
|
||||
}
|
||||
json, _ := json.Marshal(block)
|
||||
return string(json)
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ var firstAccount = web3.eth.accounts[0]
|
|||
var secondAccount = web3.eth.accounts[1]
|
||||
var thirdAccount = web3.eth.accounts[2]
|
||||
|
||||
for (var i = 0; i < 1; i++) {
|
||||
for (var i = 0; i < 10; i++) {
|
||||
console.log('\t\t' + (i + 1) + ' - Transactions')
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[1],
|
||||
|
|
@ -11,19 +11,19 @@ for (var i = 0; i < 1; i++) {
|
|||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
// web3.eth.sendTransaction({
|
||||
// from: web3.eth.accounts[1],
|
||||
// to: web3.eth.accounts[2],
|
||||
// value: 291,
|
||||
// gas: 50000,
|
||||
// gasPrice: 20
|
||||
// });
|
||||
//
|
||||
// web3.eth.sendTransaction({
|
||||
// from: web3.eth.accounts[0],
|
||||
// to: web3.eth.accounts[1],
|
||||
// value: 53039,
|
||||
// gas: 50000,
|
||||
// gasPrice: 20
|
||||
// });
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[0],
|
||||
to: web3.eth.accounts[2],
|
||||
value: 291,
|
||||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[0],
|
||||
to: web3.eth.accounts[1],
|
||||
value: 53039,
|
||||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
}
|
||||
Loading…
Reference in a new issue