updated getters and write fns for contextual data

This commit is contained in:
Dustin Brickwood 2018-05-16 15:23:08 -04:00
parent 844106b8d7
commit a7af9c9255
11 changed files with 94 additions and 74 deletions

View file

@ -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)

View file

@ -24,7 +24,7 @@ class BlocksTable extends Component {
render() {
const table = this.state.data.map((data, i) => {
return <BlockTable
key={data.Hash[i]}
key={`${data.TxHash}${i}`}
Hash={data.Hash}
Number={data.Number}
Coinbase={data.Coinbase}

View file

@ -5,7 +5,7 @@ import { Link } from 'react-router-dom'
const BlockTable = (props) => {
return (
<tbody key={props.key}>
<tbody>
<tr>
<td><Link to="/blocks/detail" onClick={() => props.detailBlockHandler(props.Number)}>
{props.Number}

View file

@ -8,6 +8,7 @@ class DetailBlockTable extends Component {
let combinedClasses = ['responsive-table', classes.table];
return (
<table className={combinedClasses.join(' ')}>
<tbody>
<tr>
<th scope="col">Height:</th>
<td>{data.Number}</td>
@ -68,6 +69,7 @@ class DetailBlockTable extends Component {
<th scope="col">Reward:</th>
<td>TBD</td>
</tr>
</tbody>
</table>
);
}

View file

@ -13,6 +13,11 @@ th {
padding-right: 10px;
}
td {
padding-left: 5px;
font-size: .5rem;
}
.addressTag {
display: inline-block;
vertical-align: bottom;

View file

@ -5,69 +5,64 @@ class DetailTransactionTable extends Component {
render() {
let data = this.props.data
console.log(data)
let combinedClasses = ['responsive-table', classes.table];
return (
<table className={combinedClasses.join(' ')}>
<tbody>
<tr>
<th scope="col">TxHash:</th>
<td>{data.TxHash}</td>
</tr>
<tr>
<th scope="col">Age:</th>
<th scope="col">TxReceipt Status:</th>
<td>{data.Status}</td>
</tr>
<tr>
<th scope="col">Block Height:</th>
<td>{data.BlockNumber}</td>
</tr>
<tr>
<th scope="col">TimeStamp:</th>
<td>{data.Age}</td>
</tr>
<tr>
<th scope="col">Txn:</th>
<td>{data.TxCount} transactions</td>
<th scope="col">From:</th>
<td>{data.From}</td>
</tr>
<tr>
<th scope="col">Block Hash:</th>
<td>{data.Hash}</td>
<th scope="col">To:</th>
<td>{ `${data.IsContract}` ? `${data.To} (Contract)` : `${data.To}` }</td>
</tr>
<tr>
<th scope="col">Parent Hash:</th>
<td>{data.ParentHash}</td>
<th scope="col">Value:</th>
<td>{data.Amount}</td>
</tr>
<tr>
<th scope="col">Uncle Hash:</th>
<td>{data.UncleHash}</td>
</tr>
<tr>
<th scope="col">Uncle Count:</th>
<td>{data.UncleCount}</td>
</tr>
<tr>
<th scope="col">Coinbase:</th>
<td>{data.Coinbase}</td>
</tr>
<tr>
<th scope="col">Difficulty:</th>
<td>{data.Difficulty}</td>
</tr>
<tr>
<th scope="col">GasUsed:</th>
<td>{data.GasUsed}</td>
</tr>
<tr>
<th scope="col">Size:</th>
<td>{data.Size}ytes</td>
</tr>
<tr>
<th scope="col">GasUsed:</th>
<td>{data.GasUsed}</td>
</tr>
<tr>
<th scope="col">GasLimit:</th>
<th scope="col">Gas Limit:</th>
<td>{data.GasLimit}</td>
</tr>
<tr>
<th scope="col">Gas Used By Txn:</th>
<td>{data.Gas}</td>
</tr>
<tr>
<th scope="col">Gas Price:</th>
<td>{data.GasPrice}</td>
</tr>
<tr>
<th scope="col">Actual Tx Cost/Fee:</th>
<td>{data.Cost}</td>
</tr>
<tr>
<th scope="col">Nonce:</th>
<td>{data.Nonce}</td>
</tr>
<tr>
<th scope="col">Reward:</th>
<td>TBD</td>
<th scope="col">Input Data:</th>
<td>{data.Data}</td>
</tr>
</tbody>
</table>
);
}

View file

@ -26,25 +26,28 @@ class TransactionTable extends Component {
const table = this.state.data.map((data, i) => {
return <TransactionsTable
key={data.TxHash[i]}
key={`${data.TxHash}${i}`}
age={data.Age}
txHash={data.TxHash}
blockNumber={data.BlockNumber}
to={data.To}
from={data.From}
value={data.Amount}
cost={data.Cost}
detailTransactionHandler={this.props.detailTransactionHandler}
/>
})
let combinedClasses = ['responsive-table', classes.table];
return (
<table className={combinedClasses.join(' ')}>
<table key={this.state.data.TxHash} className={combinedClasses.join(' ')}>
<thead className={classes.tHead}>
<tr>
<th scope="col">TxHash</th>
<th scope="col">Block</th>
<th scope="col">Age</th>
<th scope="col">From</th>
<th scope="col"></th>
<th scope="col">To</th>
<th scope="col">Value</th>
<th scope="col">TxFee</th>

View file

@ -4,6 +4,7 @@ import arrow from '../../assets/arrow_right.png';
import { Link } from 'react-router-dom'
const TransactionTable = (props) => {
console.log(props)
return (
<tbody>
<tr>
@ -12,10 +13,10 @@ const TransactionTable = (props) => {
{props.txHash}</Link>
</td>
<td>{props.blockNumber}</td>
<td>30 secs ago</td>
<td>{props.age}</td>
<td className={classes.fromTag}>{props.from}</td>
<img className={classes.arrow} src={arrow}/>
<td>{props.to}</td>
<td><img className={classes.arrow} src={arrow}/></td>
<td className={classes.toTag}>{props.to}</td>
<td>{props.value}</td>
<td>{props.cost}</td>
</tr>

View file

@ -32,8 +32,10 @@ class App extends Component {
}
detailTransactionHandler = async(txHash) => {
console.log("THIS RAN")
try {
const response = await axios.get(`http://localhost:8080/api/get_transaction/${txHash}`)
console.log("THIS IS RESPONSE", response)
await this.setState({ transactionDetailData: response.data })
}
catch(error) {

View file

@ -23,10 +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
);

View file

@ -78,10 +78,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,13 +102,7 @@ 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
func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) error {
coinbase := block.Header().Coinbase.String()
number := block.Header().Number.String()
gasUsed := block.Header().GasUsed
@ -134,7 +130,7 @@ type SendAndReceive struct {
if block.Transactions().Len() > 0 {
for _, tx := range block.Transactions() {
//WriteMinerRewards(sqldb, block)
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts)
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit)
if block.Transactions()[0].To() != nil {
WriteFromBalance(sqldb, tx)
}
@ -148,7 +144,7 @@ type SendAndReceive struct {
}
//WriteTransactions writes to sqldb
func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt) 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(),
@ -161,7 +157,8 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
Nonce: tx.Nonce(),
Data: tx.Data(),
}
fmt.Println("THIS IS AGE", age)
fmt.Println("THIS IS GAS LIMIT", gasLimit)
txHash := txData.TxHash.Hex()
from := txData.From.Hex()
blockHasher := txData.BlockHash
@ -190,8 +187,8 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
var retNonce string
isContract = true
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, txStatus, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13)) RETURNING nonce`
qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, statusFromReciept, 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)
@ -209,8 +206,8 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
}
}
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, txStatus, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13)) RETURNING nonce`
qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, statusFromReciept, 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, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, gasLimit, txFee, nonce, isContract, statusFromReciept, age,data).Scan(&retNonce)
if qerr != nil {
panic(qerr)
@ -612,10 +609,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,
@ -626,10 +625,12 @@ func GetAllTransactions(sqldb *sql.DB) string {
&amount,
&gasprice,
&gas,
&gasLimit,
&txfee,
&nonce,
&status,
&isContract,
&age,
&data,
)
@ -642,10 +643,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,
})
@ -668,24 +671,31 @@ func GetTransaction(sqldb *sql.DB, txHash string) 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,
@ -695,10 +705,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)