fixed db order

This commit is contained in:
Dustin Brickwood 2018-05-16 12:20:59 -04:00
parent 79e140e4cf
commit 844106b8d7
2 changed files with 17 additions and 44 deletions

View file

@ -25,8 +25,8 @@ CREATE TABLE IF NOT EXISTS txs (
gas numeric, gas numeric,
txFee numeric, txFee numeric,
nonce numeric, nonce numeric,
isContract bool,
txStatus text, txStatus text,
isContract bool,
data bytea data bytea
); );

View file

@ -80,6 +80,8 @@ type ShyftTxEntryPretty struct {
Gas uint64 Gas uint64
Cost uint64 Cost uint64
Nonce uint64 Nonce uint64
Status string
IsContract bool
Data []byte Data []byte
} }
@ -117,33 +119,6 @@ type SendAndReceive struct {
blockSize := block.Size().String() blockSize := block.Size().String()
blockNonce := block.Nonce() blockNonce := block.Nonce()
// Convert the receipts into their storage form and serialize them
//storageReceipts := make([]*types.ReceiptForStorage, len(receipts))
//for i, receipt := range receipts {
// storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
// var txHashFromReciept = (*types.ReceiptForStorage)(receipt).TxHash
// //var statusFromReciept = (*types.ReceiptForStorage)(receipt).Status
// var contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress
// //if statusFromReciept == 1 {
// // fmt.Println("THIS IS statusFromReciept", "SUCCESS", statusFromReciept)
// //}
// //if statusFromReciept == 0 {
// // fmt.Println("THIS IS statusFromReciept", "FAIL", statusFromReciept)
// //}
//
// if block.Transactions()[0].To() == nil {
// updateSQLStatement := `UPDATE txs SET to_addr = ($2) WHERE txHash = ($1)`
// _, error := sqldb.Exec(updateSQLStatement, txHashFromReciept.String(), contractAddressFromReciept.String())
// if error != nil {
// panic(error)
// }
// }
//
//
// //fmt.Println("THIS IS txHashFromReciept", txHashFromReciept.String())
// //fmt.Println("THIS IS contractAddressFromReciept", contractAddressFromReciept.String())
//}
i, err := strconv.ParseInt(block.Time().String(), 10, 64) i, err := strconv.ParseInt(block.Time().String(), 10, 64)
if err != nil { if err != nil {
panic(err) panic(err)
@ -324,8 +299,6 @@ func WriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndRe
//WriteFromBalance writes senders balance to accounts db //WriteFromBalance writes senders balance to accounts db
func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error { func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
//IF to address is nil (which means its contract creation)
//Need to create a condition (flag) check and then change how the nonce increment works
sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := WriteBalanceHelper(sqldb, tx) sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := WriteBalanceHelper(sqldb, tx)
toAddr := sendAndReceiveData.To toAddr := sendAndReceiveData.To
fromAddr := sendAndReceiveData.From fromAddr := sendAndReceiveData.From
@ -625,19 +598,7 @@ func GetAllTransactions(sqldb *sql.DB) string {
var arr txRes var arr txRes
var txx string var txx string
rows, err := sqldb.Query(` rows, err := sqldb.Query(`
SELECT SELECT * FROM txs`)
txhash,
to_addr,
from_addr,
blockhash,
blocknumber,
amount,
gasprice,
gas,
txfee,
nonce,
data
FROM txs`)
if err != nil { if err != nil {
fmt.Println("err") fmt.Println("err")
} }
@ -653,6 +614,8 @@ func GetAllTransactions(sqldb *sql.DB) string {
var gas uint64 var gas uint64
var txfee uint64 var txfee uint64
var nonce uint64 var nonce uint64
var status string
var isContract bool
var data []byte var data []byte
err = rows.Scan( err = rows.Scan(
&txhash, &txhash,
@ -665,6 +628,8 @@ func GetAllTransactions(sqldb *sql.DB) string {
&gas, &gas,
&txfee, &txfee,
&nonce, &nonce,
&status,
&isContract,
&data, &data,
) )
@ -679,6 +644,8 @@ func GetAllTransactions(sqldb *sql.DB) string {
Gas: gas, Gas: gas,
Cost: txfee, Cost: txfee,
Nonce: nonce, Nonce: nonce,
Status: status,
IsContract: isContract,
Data: data, Data: data,
}) })
@ -703,6 +670,8 @@ func GetTransaction(sqldb *sql.DB, txHash string) string {
var gas uint64 var gas uint64
var txfee uint64 var txfee uint64
var nonce uint64 var nonce uint64
var status string
var isContract bool
var data []byte var data []byte
row.Scan( row.Scan(
&txhash, &txhash,
@ -714,6 +683,8 @@ func GetTransaction(sqldb *sql.DB, txHash string) string {
&gas, &gas,
&txfee, &txfee,
&nonce, &nonce,
&status,
&isContract,
&data) &data)
tx := ShyftTxEntryPretty{ tx := ShyftTxEntryPretty{
TxHash: txhash, TxHash: txhash,
@ -726,6 +697,8 @@ func GetTransaction(sqldb *sql.DB, txHash string) string {
Gas: gas, Gas: gas,
Cost: txfee, Cost: txfee,
Nonce: nonce, Nonce: nonce,
Status: status,
IsContract: isContract,
Data: data, Data: data,
} }
json, _ := json.Marshal(tx) json, _ := json.Marshal(tx)