diff --git a/blockExplorerApi/handler.go b/blockExplorerApi/handler.go index abdc9acd31..2b5c3692c3 100644 --- a/blockExplorerApi/handler.go +++ b/blockExplorerApi/handler.go @@ -16,7 +16,6 @@ import ( func GetTransaction(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) txHash := vars["txHash"] - fmt.Println(txHash) connStr := "user=postgres dbname=shyftdb sslmode=disable" blockExplorerDb, err := sql.Open("postgres", connStr) if err != nil { @@ -24,7 +23,6 @@ func GetTransaction(w http.ResponseWriter, r *http.Request) { } getTxResponse := shyftdb.GetTransaction(blockExplorerDb, txHash) - fmt.Println(getTxResponse) if err != nil { http.Error(w, err.Error(), 500) diff --git a/shyftBlockExplorerUI/src/components/table/blocks/blockRows.js b/shyftBlockExplorerUI/src/components/table/blocks/blockRows.js index 1258db7b55..900f3cf1d5 100644 --- a/shyftBlockExplorerUI/src/components/table/blocks/blockRows.js +++ b/shyftBlockExplorerUI/src/components/table/blocks/blockRows.js @@ -24,7 +24,7 @@ class BlocksTable extends Component { render() { const table = this.state.data.map((data, i) => { return { return ( - + props.detailBlockHandler(props.Number)}> {props.Number} diff --git a/shyftBlockExplorerUI/src/components/table/blocks/blocksDetailsRow.js b/shyftBlockExplorerUI/src/components/table/blocks/blocksDetailsRow.js index 74c45681a1..dc881a5b9c 100644 --- a/shyftBlockExplorerUI/src/components/table/blocks/blocksDetailsRow.js +++ b/shyftBlockExplorerUI/src/components/table/blocks/blocksDetailsRow.js @@ -8,6 +8,7 @@ class DetailBlockTable extends Component { let combinedClasses = ['responsive-table', classes.table]; return ( + @@ -68,6 +69,7 @@ class DetailBlockTable extends Component { +
Height: {data.Number}Reward: TBD
); } diff --git a/shyftBlockExplorerUI/src/components/table/blocks/table.css b/shyftBlockExplorerUI/src/components/table/blocks/table.css index 38f3d87fed..8aa8995a54 100644 --- a/shyftBlockExplorerUI/src/components/table/blocks/table.css +++ b/shyftBlockExplorerUI/src/components/table/blocks/table.css @@ -13,6 +13,11 @@ th { padding-right: 10px; } +td { + padding-left: 5px; + font-size: .5rem; +} + .addressTag { display: inline-block; vertical-align: bottom; diff --git a/shyftBlockExplorerUI/src/components/table/transactions/transactionDetailsRow.js b/shyftBlockExplorerUI/src/components/table/transactions/transactionDetailsRow.js index a4d51fccb0..889bb3e33f 100644 --- a/shyftBlockExplorerUI/src/components/table/transactions/transactionDetailsRow.js +++ b/shyftBlockExplorerUI/src/components/table/transactions/transactionDetailsRow.js @@ -8,66 +8,60 @@ class DetailTransactionTable extends Component { let combinedClasses = ['responsive-table', classes.table]; return ( + - + + + + + + + + + - - + + - - + + - - + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + +
TxHash: {data.TxHash}
Age:TxReceipt Status:{data.Status}
Block Height:{data.BlockNumber}
TimeStamp: {data.Age}
Txn:{data.TxCount} transactionsFrom:{data.From}
Block Hash:{data.Hash}To:{ `${data.IsContract}` ? `${data.To} (Contract)` : `${data.To}` }
Parent Hash:{data.ParentHash}Value:{data.Amount}
Uncle Hash:{data.UncleHash}
Uncle Count:{data.UncleCount}
Coinbase:{data.Coinbase}
Difficulty:{data.Difficulty}
GasUsed:{data.GasUsed}
Size:{data.Size}ytes
GasUsed:{data.GasUsed}
GasLimit:Gas Limit: {data.GasLimit}
Gas Used By Txn:{data.Gas}
Gas Price:{data.GasPrice}
Actual Tx Cost/Fee:{data.Cost}
Nonce: {data.Nonce}
Reward:TBDInput Data:{data.Data}
); } diff --git a/shyftBlockExplorerUI/src/components/table/transactions/transactionRow.js b/shyftBlockExplorerUI/src/components/table/transactions/transactionRow.js index abde6e9bef..76bd341d5c 100644 --- a/shyftBlockExplorerUI/src/components/table/transactions/transactionRow.js +++ b/shyftBlockExplorerUI/src/components/table/transactions/transactionRow.js @@ -26,25 +26,28 @@ class TransactionTable extends Component { const table = this.state.data.map((data, i) => { return }) let combinedClasses = ['responsive-table', classes.table]; return ( - +
+ diff --git a/shyftBlockExplorerUI/src/components/table/transactions/transactionTable.js b/shyftBlockExplorerUI/src/components/table/transactions/transactionTable.js index f8fb0d1713..3f6c4d9fc2 100644 --- a/shyftBlockExplorerUI/src/components/table/transactions/transactionTable.js +++ b/shyftBlockExplorerUI/src/components/table/transactions/transactionTable.js @@ -12,10 +12,10 @@ const TransactionTable = (props) => { {props.txHash} - + - - + + diff --git a/shyftDb/postgres_setup/create_tables.psql b/shyftDb/postgres_setup/create_tables.psql index c24638c450..b0bdb516d3 100644 --- a/shyftDb/postgres_setup/create_tables.psql +++ b/shyftDb/postgres_setup/create_tables.psql @@ -23,9 +23,12 @@ CREATE TABLE IF NOT EXISTS txs ( amount numeric, gasprice numeric, gas numeric, + gasLimit numeric, txFee numeric, nonce numeric, + txStatus text, isContract bool, + age timestamp, data bytea ); diff --git a/shyftDb/shyft_database_util.go b/shyftDb/shyft_database_util.go index 136e248d48..c024cdd2b7 100644 --- a/shyftDb/shyft_database_util.go +++ b/shyftDb/shyft_database_util.go @@ -79,8 +79,12 @@ type ShyftTxEntryPretty struct { Amount uint64 GasPrice uint64 Gas uint64 + GasLimit uint64 Cost uint64 Nonce uint64 + Status string + IsContract bool + Age time.Time Data []byte } @@ -100,11 +104,11 @@ type SendAndReceive struct { //WriteBlock writes to block info to sql db func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) error { - //Need to create field in postgres db isContract : True || False - //Need to fix nonce numeric issue (attempt to reproduce and record) - //Need to update tx To Field where null with Contract Address - //Need to update account table with that Contract Address - //Need to update AccountNonce and Balance of Tx To field || Contract Address + //Need to create field in postgres db isContract : True || False + //Need to fix nonce numeric issue (attempt to reproduce and record) + //Need to update tx To Field where null with Contract Address + //Need to update account table with that Contract Address + //Need to update AccountNonce and Balance of Tx To field || Contract Address WriteMinerRewards(sqldb,block) coinbase := block.Header().Coinbase.String() number := block.Header().Number.String() @@ -118,33 +122,6 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er blockSize := block.Size().String() 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) if err != nil { panic(err) @@ -160,7 +137,7 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er if block.Transactions().Len() > 0 { for _, tx := range block.Transactions() { //WriteMinerRewards(sqldb, block) - WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String()) + WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit) if block.Transactions()[0].To() != nil { WriteFromBalance(sqldb, tx) } @@ -174,7 +151,7 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er } //WriteTransactions writes to sqldb -func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string) error { +func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error { txData := ShyftTxEntry{ TxHash: tx.Hash(), From: tx.From(), @@ -187,7 +164,6 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha Nonce: tx.Nonce(), Data: tx.Data(), } - txHash := txData.TxHash.Hex() from := txData.From.Hex() blockHasher := txData.BlockHash @@ -199,11 +175,25 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha data := txData.Data to := txData.To var isContract bool + var statusFromReciept string + if (to == nil){ + var contractAddressFromReciept string + for _, receipt := range receipts { + statusReciept := (*types.ReceiptForStorage)(receipt).Status + contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress.String() + if statusReciept == 1 { + statusFromReciept = "SUCCESS" + } + if statusReciept == 0 { + statusFromReciept = "FAIL" + } + } + var retNonce string isContract = true - sqlStatement := `INSERT INTO txs(txhash, from_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11)) RETURNING nonce` - qerr := sqldb.QueryRow(sqlStatement, txHash, from, blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce) + sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit,txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` + qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce) if qerr != nil { panic(qerr) @@ -211,8 +201,18 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha } else { var retNonce string isContract = false - sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12)) RETURNING nonce` - qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce) + for _, receipt := range receipts { + statusReciept := (*types.ReceiptForStorage)(receipt).Status + if statusReciept == 1 { + statusFromReciept = "SUCCESS" + } + if statusReciept == 0 { + statusFromReciept = "FAIL" + } + } + + sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit, txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` + qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce) if qerr != nil { panic(qerr) @@ -244,13 +244,6 @@ func WriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error { err := sqldb.QueryRow(sqlExistsStatement, fromAddr).Scan(&response) switch { case err == sql.ErrNoRows: - fmt.Println("NO ROWS RAN") - //i, err := strconv.Atoi(accountNonceSen) - //if err != nil { - // fmt.Println(err) - //} - //fmt.Println("accountnonce", i) - //fmt.Println(reflect.TypeOf(i)) sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr` insertErr := sqldb.QueryRow(sqlStatement, fromAddr, amount, accountNonceSen).Scan(&fromAddr) if insertErr != nil { @@ -308,8 +301,6 @@ func WriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndRe //WriteFromBalance writes senders balance to accounts db 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) toAddr := sendAndReceiveData.To fromAddr := sendAndReceiveData.From @@ -322,13 +313,10 @@ func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error { err := sqldb.QueryRow(sqlExistsStatement, toAddr).Scan(&response) switch { case err == sql.ErrNoRows: - fmt.Println("NO ROWS RAN") i, err := strconv.Atoi(accountNonceRec) if err != nil { fmt.Println(err) } - //fmt.Println("accountnonce", i) - //fmt.Println(reflect.TypeOf(i)) sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr` insertErr := sqldb.QueryRow(sqlStatement, toAddr, amount, i).Scan(&toAddr) if insertErr != nil { @@ -620,19 +608,7 @@ func GetAllTransactions(sqldb *sql.DB) string { var arr txRes var txx string rows, err := sqldb.Query(` - SELECT - txhash, - to_addr, - from_addr, - blockhash, - blocknumber, - amount, - gasprice, - gas, - txfee, - nonce, - data - FROM txs`) + SELECT * FROM txs`) if err != nil { fmt.Println("err") } @@ -646,8 +622,12 @@ func GetAllTransactions(sqldb *sql.DB) string { var amount uint64 var gasprice uint64 var gas uint64 + var gasLimit uint64 var txfee uint64 var nonce uint64 + var status string + var isContract bool + var age time.Time var data []byte err = rows.Scan( &txhash, @@ -658,8 +638,12 @@ func GetAllTransactions(sqldb *sql.DB) string { &amount, &gasprice, &gas, + &gasLimit, &txfee, &nonce, + &status, + &isContract, + &age, &data, ) @@ -672,8 +656,12 @@ func GetAllTransactions(sqldb *sql.DB) string { Amount: amount, GasPrice: gasprice, Gas: gas, + GasLimit: gasLimit, Cost: txfee, Nonce: nonce, + Status: status, + IsContract: isContract, + Age: age, Data: data, }) @@ -688,28 +676,38 @@ func GetAllTransactions(sqldb *sql.DB) string { func GetTransaction(sqldb *sql.DB, txHash string) string { sqlStatement := `SELECT * FROM txs WHERE txhash=$1;` row := sqldb.QueryRow(sqlStatement, txHash) - var txhash string - var to_addr string - var from_addr string - var blockhash string - var blocknumber string - var amount uint64 - var gasprice uint64 - var gas uint64 - var txfee uint64 - var nonce uint64 - var data []byte + var txhash string + var to_addr string + var from_addr string + var blockhash string + var blocknumber string + var amount uint64 + var gasprice uint64 + var gas uint64 + var gasLimit uint64 + var txfee uint64 + var nonce uint64 + var status string + var isContract bool + var age time.Time + var data []byte row.Scan( &txhash, &to_addr, &from_addr, &blockhash, + &blocknumber, &amount, &gasprice, &gas, + &gasLimit, &txfee, &nonce, + &status, + &isContract, + &age, &data) + tx := ShyftTxEntryPretty{ TxHash: txhash, To: to_addr, @@ -719,8 +717,12 @@ func GetTransaction(sqldb *sql.DB, txHash string) string { Amount: amount, GasPrice: gasprice, Gas: gas, + GasLimit: gasLimit, Cost: txfee, Nonce: nonce, + Status: status, + IsContract: isContract, + Age: age, Data: data, } json, _ := json.Marshal(tx) diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index 136e248d48..c024cdd2b7 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -79,8 +79,12 @@ type ShyftTxEntryPretty struct { Amount uint64 GasPrice uint64 Gas uint64 + GasLimit uint64 Cost uint64 Nonce uint64 + Status string + IsContract bool + Age time.Time Data []byte } @@ -100,11 +104,11 @@ type SendAndReceive struct { //WriteBlock writes to block info to sql db func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) error { - //Need to create field in postgres db isContract : True || False - //Need to fix nonce numeric issue (attempt to reproduce and record) - //Need to update tx To Field where null with Contract Address - //Need to update account table with that Contract Address - //Need to update AccountNonce and Balance of Tx To field || Contract Address + //Need to create field in postgres db isContract : True || False + //Need to fix nonce numeric issue (attempt to reproduce and record) + //Need to update tx To Field where null with Contract Address + //Need to update account table with that Contract Address + //Need to update AccountNonce and Balance of Tx To field || Contract Address WriteMinerRewards(sqldb,block) coinbase := block.Header().Coinbase.String() number := block.Header().Number.String() @@ -118,33 +122,6 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er blockSize := block.Size().String() 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) if err != nil { panic(err) @@ -160,7 +137,7 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er if block.Transactions().Len() > 0 { for _, tx := range block.Transactions() { //WriteMinerRewards(sqldb, block) - WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String()) + WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit) if block.Transactions()[0].To() != nil { WriteFromBalance(sqldb, tx) } @@ -174,7 +151,7 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er } //WriteTransactions writes to sqldb -func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string) error { +func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error { txData := ShyftTxEntry{ TxHash: tx.Hash(), From: tx.From(), @@ -187,7 +164,6 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha Nonce: tx.Nonce(), Data: tx.Data(), } - txHash := txData.TxHash.Hex() from := txData.From.Hex() blockHasher := txData.BlockHash @@ -199,11 +175,25 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha data := txData.Data to := txData.To var isContract bool + var statusFromReciept string + if (to == nil){ + var contractAddressFromReciept string + for _, receipt := range receipts { + statusReciept := (*types.ReceiptForStorage)(receipt).Status + contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress.String() + if statusReciept == 1 { + statusFromReciept = "SUCCESS" + } + if statusReciept == 0 { + statusFromReciept = "FAIL" + } + } + var retNonce string isContract = true - sqlStatement := `INSERT INTO txs(txhash, from_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11)) RETURNING nonce` - qerr := sqldb.QueryRow(sqlStatement, txHash, from, blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce) + sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit,txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` + qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce) if qerr != nil { panic(qerr) @@ -211,8 +201,18 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha } else { var retNonce string isContract = false - sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12)) RETURNING nonce` - qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce) + for _, receipt := range receipts { + statusReciept := (*types.ReceiptForStorage)(receipt).Status + if statusReciept == 1 { + statusFromReciept = "SUCCESS" + } + if statusReciept == 0 { + statusFromReciept = "FAIL" + } + } + + sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit, txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` + qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce) if qerr != nil { panic(qerr) @@ -244,13 +244,6 @@ func WriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error { err := sqldb.QueryRow(sqlExistsStatement, fromAddr).Scan(&response) switch { case err == sql.ErrNoRows: - fmt.Println("NO ROWS RAN") - //i, err := strconv.Atoi(accountNonceSen) - //if err != nil { - // fmt.Println(err) - //} - //fmt.Println("accountnonce", i) - //fmt.Println(reflect.TypeOf(i)) sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr` insertErr := sqldb.QueryRow(sqlStatement, fromAddr, amount, accountNonceSen).Scan(&fromAddr) if insertErr != nil { @@ -308,8 +301,6 @@ func WriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndRe //WriteFromBalance writes senders balance to accounts db 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) toAddr := sendAndReceiveData.To fromAddr := sendAndReceiveData.From @@ -322,13 +313,10 @@ func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error { err := sqldb.QueryRow(sqlExistsStatement, toAddr).Scan(&response) switch { case err == sql.ErrNoRows: - fmt.Println("NO ROWS RAN") i, err := strconv.Atoi(accountNonceRec) if err != nil { fmt.Println(err) } - //fmt.Println("accountnonce", i) - //fmt.Println(reflect.TypeOf(i)) sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr` insertErr := sqldb.QueryRow(sqlStatement, toAddr, amount, i).Scan(&toAddr) if insertErr != nil { @@ -620,19 +608,7 @@ func GetAllTransactions(sqldb *sql.DB) string { var arr txRes var txx string rows, err := sqldb.Query(` - SELECT - txhash, - to_addr, - from_addr, - blockhash, - blocknumber, - amount, - gasprice, - gas, - txfee, - nonce, - data - FROM txs`) + SELECT * FROM txs`) if err != nil { fmt.Println("err") } @@ -646,8 +622,12 @@ func GetAllTransactions(sqldb *sql.DB) string { var amount uint64 var gasprice uint64 var gas uint64 + var gasLimit uint64 var txfee uint64 var nonce uint64 + var status string + var isContract bool + var age time.Time var data []byte err = rows.Scan( &txhash, @@ -658,8 +638,12 @@ func GetAllTransactions(sqldb *sql.DB) string { &amount, &gasprice, &gas, + &gasLimit, &txfee, &nonce, + &status, + &isContract, + &age, &data, ) @@ -672,8 +656,12 @@ func GetAllTransactions(sqldb *sql.DB) string { Amount: amount, GasPrice: gasprice, Gas: gas, + GasLimit: gasLimit, Cost: txfee, Nonce: nonce, + Status: status, + IsContract: isContract, + Age: age, Data: data, }) @@ -688,28 +676,38 @@ func GetAllTransactions(sqldb *sql.DB) string { func GetTransaction(sqldb *sql.DB, txHash string) string { sqlStatement := `SELECT * FROM txs WHERE txhash=$1;` row := sqldb.QueryRow(sqlStatement, txHash) - var txhash string - var to_addr string - var from_addr string - var blockhash string - var blocknumber string - var amount uint64 - var gasprice uint64 - var gas uint64 - var txfee uint64 - var nonce uint64 - var data []byte + var txhash string + var to_addr string + var from_addr string + var blockhash string + var blocknumber string + var amount uint64 + var gasprice uint64 + var gas uint64 + var gasLimit uint64 + var txfee uint64 + var nonce uint64 + var status string + var isContract bool + var age time.Time + var data []byte row.Scan( &txhash, &to_addr, &from_addr, &blockhash, + &blocknumber, &amount, &gasprice, &gas, + &gasLimit, &txfee, &nonce, + &status, + &isContract, + &age, &data) + tx := ShyftTxEntryPretty{ TxHash: txhash, To: to_addr, @@ -719,8 +717,12 @@ func GetTransaction(sqldb *sql.DB, txHash string) string { Amount: amount, GasPrice: gasprice, Gas: gas, + GasLimit: gasLimit, Cost: txfee, Nonce: nonce, + Status: status, + IsContract: isContract, + Age: age, Data: data, } json, _ := json.Marshal(tx)
TxHash Block Age From To Value TxFee {props.blockNumber}30 secs ago{props.age} {props.from}{props.to}{props.to} {props.value} {props.cost}