mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
added missing block fields and modified blocks table
This commit is contained in:
parent
c8d1ceea7b
commit
3f0cf00b65
2 changed files with 15 additions and 4 deletions
|
|
@ -1,6 +1,10 @@
|
|||
CREATE TABLE IF NOT EXISTS blocks (
|
||||
hash text primary key,
|
||||
coinbase text,
|
||||
gasUsed numeric,
|
||||
gasLimit numeric,
|
||||
txCount numeric,
|
||||
uncleCount numeric,
|
||||
number bigint
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -87,8 +87,15 @@ type SendAndReceive struct {
|
|||
func WriteBlock(sqldb *sql.DB, block *types.Block) error {
|
||||
coinbase := block.Header().Coinbase.String()
|
||||
number := block.Header().Number.String()
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number) VALUES(($1), ($2), ($3)) RETURNING number`
|
||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number).Scan(&number)
|
||||
gasUsed := block.Header().GasUsed
|
||||
gasLimit := block.Header().GasLimit
|
||||
txCount := block.Transactions().Len()
|
||||
uncleCount := len(block.Uncles())
|
||||
age := block.Time()
|
||||
fmt.Println("TIMESTAMP+++++++", age)
|
||||
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txcount, uncleCount) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7)) RETURNING number`
|
||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, txCount, uncleCount).Scan(&number)
|
||||
if qerr != nil {
|
||||
panic(qerr)
|
||||
}
|
||||
|
|
@ -126,7 +133,7 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
|
|||
gas := txData.Gas
|
||||
data := txData.Data
|
||||
to := txData.To
|
||||
if(to == nil){
|
||||
if to == nil{
|
||||
var retNonce string
|
||||
sqlStatement := `INSERT INTO txs(txhash, from_addr, blockhash, amount, gasprice, gas, nonce, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8)) RETURNING nonce`
|
||||
qerr := sqldb.QueryRow(sqlStatement, txHash, from, blockHasher, amount, gasPrice, gas, nonce, data).Scan(&retNonce)
|
||||
|
|
|
|||
Loading…
Reference in a new issue