write txs successfully writing to db

This commit is contained in:
Dustin Brickwood 2018-04-23 11:44:39 -04:00
parent d995a67b9c
commit d35259e1c5

View file

@ -95,32 +95,19 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
Nonce: tx.Nonce(), Nonce: tx.Nonce(),
Data: tx.Data(), Data: tx.Data(),
} }
// var encodedData bytes.Buffer
// encoder := gob.NewEncoder(&encodedData) txHash := txData.TxHash.Hex()
// if err := encoder.Encode(txData); err != nil { from := txData.From.Hex()
// log.Crit("Faild to encode TX data", "err", err) to := txData.To.Hex()
// }
txHash := txData.TxHash
from := txData.From
to := txData.To
blockHasher := txData.BlockHash blockHasher := txData.BlockHash
amount := txData.Amount amount := txData.Amount.String()
gasPrice := txData.GasPrice gasPrice := txData.GasPrice.String()
nonce := txData.Nonce nonce := txData.Nonce
gas := txData.Gas gas := txData.Gas
data := txData.Data 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` 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, from, to, blockHasher, amount, gasPrice, nonce, gas, data).Scan(&nonce) //.Scan(&fun) qerr := sqldb.QueryRow(sqlStatement, txHash, to, from, blockHasher, amount, gasPrice, gas, nonce, data).Scan(&nonce)
if qerr != nil { if qerr != nil {
panic(qerr) panic(qerr)
} }