From d35259e1c5565680df6173896f0f4cd2b9cedfa6 Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Mon, 23 Apr 2018 11:44:39 -0400 Subject: [PATCH] write txs successfully writing to db --- shyftdb/shyft_database_util.go | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 2381be3dfa..71c56357a1 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -95,32 +95,19 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha Nonce: tx.Nonce(), Data: tx.Data(), } - // var encodedData bytes.Buffer - // encoder := gob.NewEncoder(&encodedData) - // if err := encoder.Encode(txData); err != nil { - // log.Crit("Faild to encode TX data", "err", err) - // } - txHash := txData.TxHash - from := txData.From - to := txData.To + + txHash := txData.TxHash.Hex() + from := txData.From.Hex() + to := txData.To.Hex() blockHasher := txData.BlockHash - amount := txData.Amount - gasPrice := txData.GasPrice + amount := txData.Amount.String() + gasPrice := txData.GasPrice.String() nonce := txData.Nonce gas := txData.Gas data := txData.Data - fmt.Println("+++++++++txHash", txHash) - fmt.Println("+++++++++from", from) - fmt.Println("+++++++++to", to) - fmt.Println("+++++++++BLOCKHASHER", blockHasher) - fmt.Println("+++++++++amount", amount) - fmt.Println("+++++++++gas Price", gasPrice) - fmt.Println("+++++++++nonce", nonce) - fmt.Println("+++++++++Gas", gas) - fmt.Println("+++++++++Data", data) - sqlStatement := `INSERT INTO txs(blockHasher, amount, gasPrice, none, gas, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6) RETURNING nonce` - qerr := sqldb.QueryRow(sqlStatement, txHash, from, to, blockHasher, amount, gasPrice, nonce, gas, data).Scan(&nonce) //.Scan(&fun) + sqlStatement := `INSERT INTO txs(txhash, to_addr, from_addr, blockhash, amount, gasprice, gas, nonce, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9)) RETURNING nonce` + qerr := sqldb.QueryRow(sqlStatement, txHash, to, from, blockHasher, amount, gasPrice, gas, nonce, data).Scan(&nonce) if qerr != nil { panic(qerr) }