From 361841e460122679fb93b9346758969083bbb7f7 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Thu, 10 May 2018 15:19:24 -0400 Subject: [PATCH] added timestamp of blocks to postgres db --- shyftDb/postgres_setup/create_tables.psql | 1 + shyftdb/shyft_database_util.go | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/shyftDb/postgres_setup/create_tables.psql b/shyftDb/postgres_setup/create_tables.psql index d2be84603b..e80c608779 100644 --- a/shyftDb/postgres_setup/create_tables.psql +++ b/shyftDb/postgres_setup/create_tables.psql @@ -5,6 +5,7 @@ CREATE TABLE IF NOT EXISTS blocks ( gasLimit numeric, txCount numeric, uncleCount numeric, + age timestamp, number bigint ); diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 4ee853e39e..a99596c802 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -6,8 +6,8 @@ import ( "math/big" "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/core/types" - - + "time" + "strconv" "database/sql" "log" @@ -91,11 +91,16 @@ func WriteBlock(sqldb *sql.DB, block *types.Block) error { 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) + + i, err := strconv.ParseInt(block.Time().String(), 10, 64) + if err != nil { + 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` + qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age).Scan(&number) if qerr != nil { panic(qerr) }