From e5c2cd1eaf4b1da6c5a66f60bea8e853488aff8f Mon Sep 17 00:00:00 2001 From: Tim Williams Date: Thu, 26 Apr 2018 13:37:34 -0400 Subject: [PATCH] now allows contracts to be written as txes in the tx table --- shyftdb/shyft_database_util.go | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index f86381a83b..b7750fda01 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -102,19 +102,31 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha txHash := txData.TxHash.Hex() from := txData.From.Hex() - to := txData.To.Hex() blockHasher := txData.BlockHash amount := txData.Amount.String() gasPrice := txData.GasPrice.String() nonce := txData.Nonce gas := txData.Gas data := txData.Data + to := txData.To + 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) - 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) + if qerr != nil { + panic(qerr) + } + } else { + var retNonce string + sqlStatement := `INSERT INTO txs(txhash, from_addr, to_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.Hex(), blockHasher, amount, gasPrice, gas, nonce, data).Scan(&retNonce) + + if qerr != nil { + panic(qerr) + } } + return nil } @@ -393,4 +405,4 @@ func GetTransaction(sqldb *sql.DB) string { json, _ := json.Marshal(tx) return string(json) -} +} \ No newline at end of file