mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
commit
0f9bbd2e62
27 changed files with 504 additions and 71 deletions
|
|
@ -74,13 +74,34 @@ func GetAllTransactionsFromBlock(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintln(w, txsFromBlock)
|
||||
}
|
||||
|
||||
func GetAllBlocksMinedByAddress(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
coinbase := vars["coinbase"]
|
||||
connStr := "user=postgres dbname=shyftdb sslmode=disable"
|
||||
blockExplorerDb, err := sql.Open("postgres", connStr)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
blocksMined := shyftdb.GetAllBlocksMinedByAddress(blockExplorerDb, coinbase)
|
||||
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), 500)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
fmt.Fprintln(w, blocksMined)
|
||||
}
|
||||
|
||||
// GetAccount gets balance
|
||||
func GetAccount(w http.ResponseWriter, r *http.Request) {
|
||||
vars := mux.Vars(r)
|
||||
|
|
|
|||
|
|
@ -69,6 +69,12 @@ var routes = Routes{
|
|||
Pattern: "/api/get_all_transactions_from_block/{blockNumber}",
|
||||
HandlerFunc: GetAllTransactionsFromBlock,
|
||||
},
|
||||
Route{
|
||||
Name: "GetAllBlocksMinedByAddress",
|
||||
Method: "GET",
|
||||
Pattern: "/api/get_blocks_mined/{coinbase}",
|
||||
HandlerFunc: GetAllBlocksMinedByAddress,
|
||||
},
|
||||
Route{
|
||||
"GetInternalTransactions",
|
||||
"GET",
|
||||
|
|
|
|||
|
|
@ -161,6 +161,11 @@ func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) {
|
|||
number := block.Header().Number.String()
|
||||
gasUsed := block.Header().GasUsed
|
||||
gasLimit := block.Header().GasLimit
|
||||
gasPrice := 0
|
||||
txFee := 0
|
||||
txStatus := ""
|
||||
isContract := false
|
||||
data:= ""
|
||||
addr := k.String()
|
||||
txCountAccount := v.Nonce +1
|
||||
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
||||
|
|
@ -179,8 +184,8 @@ func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) {
|
|||
}
|
||||
|
||||
var retNonce string
|
||||
sqlGenTxStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gas, gasLimit, nonce,age) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING nonce`
|
||||
insertError := sqldb.QueryRow(sqlGenTxStatement, txHash, GENESIS, addr, block.Header().Hash().Hex(), number, v.Balance.String(), gasUsed, gasLimit, txCountAccount, age).Scan(&retNonce)
|
||||
sqlGenTxStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount,gasPrice, gas, gasLimit,txFee,nonce,txstatus, iscontract,age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
|
||||
insertError := sqldb.QueryRow(sqlGenTxStatement, txHash, GENESIS, addr, block.Header().Hash().Hex(), number, v.Balance.String(), gasPrice, gasUsed, gasLimit, txFee,txCountAccount,txStatus, isContract, age, data).Scan(&retNonce)
|
||||
if insertError != nil {
|
||||
panic(insertError)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
<title>React App</title>
|
||||
<title>Block Explorer</title>
|
||||
</head>
|
||||
<body>
|
||||
<noscript>
|
||||
|
|
|
|||
67
shyftBlockExplorerUI/src/components/UI materials/loading.css
Normal file
67
shyftBlockExplorerUI/src/components/UI materials/loading.css
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
.Loader,
|
||||
.Loader:before,
|
||||
.Loader:after {
|
||||
border-radius: 50%;
|
||||
}
|
||||
.Loader {
|
||||
color: #521751;
|
||||
font-size: 11px;
|
||||
text-indent: -99999em;
|
||||
margin: 55px auto;
|
||||
position: relative;
|
||||
width: 10em;
|
||||
height: 10em;
|
||||
box-shadow: inset 0 0 0 1em;
|
||||
-webkit-transform: translateZ(0);
|
||||
-ms-transform: translateZ(0);
|
||||
transform: translateZ(0);
|
||||
}
|
||||
.Loader:before,
|
||||
.Loader:after {
|
||||
position: absolute;
|
||||
content: '';
|
||||
}
|
||||
.Loader:before {
|
||||
width: 5.2em;
|
||||
height: 10.2em;
|
||||
background: #fff;
|
||||
border-radius: 10.2em 0 0 10.2em;
|
||||
top: -0.1em;
|
||||
left: -0.1em;
|
||||
-webkit-transform-origin: 5.2em 5.1em;
|
||||
transform-origin: 5.2em 5.1em;
|
||||
-webkit-animation: load2 2s infinite ease 1.5s;
|
||||
animation: load2 2s infinite ease 1.5s;
|
||||
}
|
||||
.Loader:after {
|
||||
width: 5.2em;
|
||||
height: 10.2em;
|
||||
background: #fff;
|
||||
border-radius: 0 10.2em 10.2em 0;
|
||||
top: -0.1em;
|
||||
left: 5.1em;
|
||||
-webkit-transform-origin: 0px 5.1em;
|
||||
transform-origin: 0px 5.1em;
|
||||
-webkit-animation: load2 2s infinite ease;
|
||||
animation: load2 2s infinite ease;
|
||||
}
|
||||
@-webkit-keyframes load2 {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
@keyframes load2 {
|
||||
0% {
|
||||
-webkit-transform: rotate(0deg);
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
100% {
|
||||
-webkit-transform: rotate(360deg);
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
import React from 'react';
|
||||
import classes from './loading.css';
|
||||
|
||||
const loading = () => (
|
||||
<div className={classes.Loader}>Loading...</div>
|
||||
);
|
||||
|
||||
export default loading;
|
||||
|
|
@ -10,6 +10,8 @@
|
|||
}
|
||||
|
||||
.Greeting {
|
||||
padding-top: 5%;
|
||||
padding-bottom: 5%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ const home = props => {
|
|||
return (
|
||||
<div className={classes.Home}>
|
||||
<span className={classes.Greeting}>THIS IS A WIP</span>
|
||||
<div className={classes.ButtonNav}>
|
||||
<div>
|
||||
<div className={classes.Transactions}>
|
||||
<Link to="/transactions"><button className="btn btn-primary">Transactions</button></Link>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,11 +2,15 @@ import React from 'react';
|
|||
import classes from '../nav.css';
|
||||
|
||||
const accountsDetailHeader = (props) => {
|
||||
const total = props.data
|
||||
.map(num => Number(num.Amount) / 10000000000000000000)
|
||||
.reduce((acc, cur) => acc + cur ,0);
|
||||
return (
|
||||
<div className={classes.Secondary}>
|
||||
<span className={classes.Transactions}>Account# {props.addr}</span>
|
||||
<span className={classes.Transactions}>Total Value: {total}</span>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export default accountsDetailHeader;
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
import React from 'react';
|
||||
import classes from '../nav.css';
|
||||
|
||||
const blocksCoinbaseHeader = (props) => {
|
||||
return (
|
||||
<div className={classes.Secondary}>
|
||||
<span className={classes.Transactions}>Coinbase: {props.coinbase}</span>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
export default blocksCoinbaseHeader;
|
||||
|
|
@ -21,15 +21,27 @@ class AccountTable extends Component {
|
|||
}
|
||||
|
||||
render() {
|
||||
const table = this.state.data.map((data, i) => {
|
||||
|
||||
let startNum = 1;
|
||||
const sorted = [...this.state.data];
|
||||
sorted.sort((a, b) => Number(a.Balance) > Number(b.Balance));
|
||||
console.log(sorted);
|
||||
const table = sorted.reverse().map((data, i) => {
|
||||
const conversion = Number(data.Balance) / 10000000000000000000;
|
||||
const total = sorted
|
||||
.map(num => Number(num.Balance) / 10000000000000000000)
|
||||
.reduce((acc, cur) => acc + cur ,0);
|
||||
const percentage = ( (conversion / total) *100);
|
||||
return <AccountsTable
|
||||
key={`${data.addr}${i}`}
|
||||
Rank={startNum++}
|
||||
Percentage={percentage.toFixed(2)}
|
||||
Addr={data.Addr}
|
||||
Balance={data.Balance}
|
||||
Balance={conversion}
|
||||
TxCountAccount={data.TxCountAccount}
|
||||
detailAccountHandler={this.props.detailAccountHandler}
|
||||
/>
|
||||
})
|
||||
});
|
||||
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
return (
|
||||
|
|
|
|||
|
|
@ -6,16 +6,16 @@ const AccountsTable = (props) => {
|
|||
return (
|
||||
<tbody>
|
||||
<tr>
|
||||
<td>1</td>
|
||||
<td>{props.Rank}</td>
|
||||
<td className={classes.addressTag}><Link to="/account/detail" onClick={() => props.detailAccountHandler(props.Addr)}>
|
||||
{props.Addr}
|
||||
</Link></td>
|
||||
<td>{props.Balance}</td>
|
||||
<td>12.01%</td>
|
||||
<td>{props.Percentage}%</td>
|
||||
<td>{props.TxCountAccount}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export default AccountsTable;
|
||||
|
|
|
|||
|
|
@ -10,6 +10,8 @@ class AccountTransactionTable extends Component {
|
|||
return <ErrorHandler />
|
||||
}else {
|
||||
table = this.props.data.map((data, i) => {
|
||||
const costConversion = data.Cost / 10000000000000000000;
|
||||
const amountConversion = data.Amount / 10000000000000000000;
|
||||
return <DetailAccountsTable
|
||||
key={`${data.TxHash}${i}`}
|
||||
age={data.Age}
|
||||
|
|
@ -17,8 +19,8 @@ class AccountTransactionTable extends Component {
|
|||
blockNumber={data.BlockNumber}
|
||||
to={data.To}
|
||||
from={data.From}
|
||||
value={data.Amount}
|
||||
cost={data.Cost}
|
||||
value={amountConversion}
|
||||
cost={costConversion}
|
||||
addr={this.props.addr}
|
||||
detailTransactionHandler={this.props.transactionDetailHandler}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -9,11 +9,17 @@ const DetailAccountsTable = (props) => {
|
|||
}else {
|
||||
flag = false
|
||||
}
|
||||
let genFlag;
|
||||
if(props.txHash.indexOf("GENESIS") !== -1) {
|
||||
genFlag = false
|
||||
}else {
|
||||
genFlag = true
|
||||
}
|
||||
return (
|
||||
<tbody>
|
||||
<tr>
|
||||
<td className={classes.addressTag}>
|
||||
<Link to="/transaction/details" onClick={() => props.detailTransactionHandler(props.txHash)}>
|
||||
<Link to="/transaction/details" className={genFlag ? "" : classes.disabled} onClick={() => props.detailTransactionHandler(props.txHash)}>
|
||||
{props.txHash}</Link>
|
||||
</td>
|
||||
<td>{props.blockNumber}</td>
|
||||
|
|
@ -26,6 +32,6 @@ const DetailAccountsTable = (props) => {
|
|||
</tr>
|
||||
</tbody>
|
||||
)
|
||||
}
|
||||
};
|
||||
|
||||
export default DetailAccountsTable;
|
||||
|
|
|
|||
|
|
@ -77,4 +77,9 @@ th {
|
|||
text-transform: uppercase;
|
||||
text-align: center;
|
||||
vertical-align: middle;
|
||||
}
|
||||
|
||||
.disabled {
|
||||
pointer-events: none;
|
||||
color: black;
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
import React, { Component } from 'react';
|
||||
import BlockTable from './blockTable';
|
||||
import Loading from '../../UI materials/loading'
|
||||
import classes from './table.css';
|
||||
import axios from "axios/index";
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ class BlocksTable extends Component {
|
|||
|
||||
async componentDidMount() {
|
||||
try {
|
||||
const response = await axios.get("http://localhost:8080/api/get_all_blocks")
|
||||
const response = await axios.get("http://localhost:8080/api/get_all_blocks");
|
||||
await this.setState({data: response.data});
|
||||
} catch (err) {
|
||||
console.log(err);
|
||||
|
|
@ -23,6 +24,7 @@ class BlocksTable extends Component {
|
|||
|
||||
render() {
|
||||
const table = this.state.data.map((data, i) => {
|
||||
const conversion = data.Rewards / 10000000000000000000;
|
||||
return <BlockTable
|
||||
key={`${data.TxHash}${i}`}
|
||||
Hash={data.Hash}
|
||||
|
|
@ -33,9 +35,11 @@ class BlocksTable extends Component {
|
|||
GasLimit={data.GasLimit}
|
||||
UncleCount={data.UncleCount}
|
||||
TxCount={data.TxCount}
|
||||
Reward={conversion}
|
||||
detailBlockHandler={this.props.detailBlockHandler}
|
||||
getBlocksMined={this.props.getBlocksMined}
|
||||
/>
|
||||
})
|
||||
});
|
||||
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
return (
|
||||
|
|
@ -54,7 +58,7 @@ class BlocksTable extends Component {
|
|||
<th scope="col">Reward</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{table}
|
||||
{table}
|
||||
</table>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,11 +13,11 @@ const BlockTable = (props) => {
|
|||
<td>{props.Age}</td>
|
||||
<td>{props.TxCount}</td>
|
||||
<td>{props.UncleCount}</td>
|
||||
<td className={classes.addressTag}>{props.Coinbase}</td>
|
||||
<td className={classes.addressTag}><Link to="/mined/blocks" onClick={() => props.getBlocksMined(props.Coinbase)}>{props.Coinbase}</Link></td>
|
||||
<td>{props.GasUsed}</td>
|
||||
<td>{props.GasLimit}</td>
|
||||
<td>12.01</td>
|
||||
<td>3.2</td>
|
||||
<td>TBD</td>
|
||||
<td>{props.Reward}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
)
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
import React, { Component } from 'react';
|
||||
import classes from './table.css';
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
class DetailBlockTable extends Component {
|
||||
|
||||
render() {
|
||||
let data = this.props.data
|
||||
let data = this.props.data;
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
return (
|
||||
<table className={combinedClasses.join(' ')}>
|
||||
|
|
@ -19,7 +20,7 @@ class DetailBlockTable extends Component {
|
|||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Txn:</th>
|
||||
<td>{data.TxCount} transactions</td>
|
||||
<td><Link to="/block/transactions" onClick={() => this.props.getBlockTransactions(data.Number)}>{data.TxCount} transactions</Link></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Block Hash:</th>
|
||||
|
|
@ -67,7 +68,7 @@ class DetailBlockTable extends Component {
|
|||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Reward:</th>
|
||||
<td>TBD</td>
|
||||
<td>{data.Rewards}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,55 @@
|
|||
import React, { Component } from 'react';
|
||||
import MinedBlockTable from './blocksMinedTable';
|
||||
import Loading from '../../UI materials/loading'
|
||||
import classes from './table.css';
|
||||
|
||||
class BlocksMinedTable extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: []
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
const table = this.props.data.map((data, i) => {
|
||||
const conversion = data.Rewards / 10000000000000000000;
|
||||
return <MinedBlockTable
|
||||
key={`${data.Hash}${i}`}
|
||||
Hash={data.Hash}
|
||||
Number={data.Number}
|
||||
Coinbase={data.Coinbase}
|
||||
Age={data.Age}
|
||||
GasUsed={data.GasUsed}
|
||||
GasLimit={data.GasLimit}
|
||||
UncleCount={data.UncleCount}
|
||||
TxCount={data.TxCount}
|
||||
Reward={conversion}
|
||||
detailBlockHandler={this.props.detailBlockHandler}
|
||||
getBlocksMined={this.props.getBlocksMined}
|
||||
/>
|
||||
});
|
||||
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
return (
|
||||
<table className={combinedClasses.join(' ')}>
|
||||
<thead className={classes.tHead}>
|
||||
<tr>
|
||||
<th scope="col">Height</th>
|
||||
<th scope="col">Block Hash</th>
|
||||
<th scope="col">Age</th>
|
||||
<th scope="col">Txn</th>
|
||||
<th scope="col">Uncles</th>
|
||||
<th scope="col">Coinbase</th>
|
||||
<th scope="col">GasUsed</th>
|
||||
<th scope="col">GasLimit</th>
|
||||
<th scope="col">Avg.GasPrice</th>
|
||||
<th scope="col">Reward</th>
|
||||
</tr>
|
||||
</thead>
|
||||
{table}
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default BlocksMinedTable;
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
import React from 'react';
|
||||
import classes from './table.css';
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
const MinedBlockTable = (props) => {
|
||||
return (
|
||||
<tbody>
|
||||
<tr>
|
||||
<td><Link to="/blocks/detail" onClick={() => props.detailBlockHandler(props.Number)}>
|
||||
{props.Number}
|
||||
</Link></td>
|
||||
<td className={classes.addressTag}>{props.Hash}</td>
|
||||
<td>{props.Age}</td>
|
||||
<td>{props.TxCount}</td>
|
||||
<td>{props.UncleCount}</td>
|
||||
<td className={classes.addressTag}>{props.Coinbase}</td>
|
||||
<td>{props.GasUsed}</td>
|
||||
<td>{props.GasLimit}</td>
|
||||
<td>TBD</td>
|
||||
<td>{props.Reward}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
)
|
||||
};
|
||||
|
||||
export default MinedBlockTable;
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
import React, { Component } from 'react';
|
||||
import TransactionsTable from './transactionTable';
|
||||
import classes from './table.css';
|
||||
|
||||
class BlockTransactionTable extends Component {
|
||||
constructor(props) {
|
||||
super(props);
|
||||
this.state = {
|
||||
data: []
|
||||
};
|
||||
}
|
||||
|
||||
render() {
|
||||
const table = this.props.data.map((data, i) => {
|
||||
const conversion = data.Cost / 10000000000000000000;
|
||||
return <TransactionsTable
|
||||
key={`${data.TxHash}${i}`}
|
||||
age={data.Age}
|
||||
txHash={data.TxHash}
|
||||
blockNumber={data.BlockNumber}
|
||||
to={data.To}
|
||||
from={data.From}
|
||||
value={data.Amount}
|
||||
cost={conversion}
|
||||
getBlockTransactions={this.props.getBlockTransactions}
|
||||
detailTransactionHandler={this.props.detailTransactionHandler}
|
||||
detailAccountHandler={this.props.detailAccountHandler}
|
||||
/>
|
||||
})
|
||||
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
return (
|
||||
<table key={this.props.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>
|
||||
</tr>
|
||||
</thead>
|
||||
{table}
|
||||
</table>
|
||||
);
|
||||
}
|
||||
}
|
||||
export default BlockTransactionTable;
|
||||
|
|
@ -6,6 +6,7 @@ class DetailTransactionTable extends Component {
|
|||
render() {
|
||||
let data = this.props.data
|
||||
let combinedClasses = ['responsive-table', classes.table];
|
||||
const conversion = data.Cost / 10000000000000000000;
|
||||
return (
|
||||
<table className={combinedClasses.join(' ')}>
|
||||
<tbody>
|
||||
|
|
@ -51,7 +52,7 @@ class DetailTransactionTable extends Component {
|
|||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Actual Tx Cost/Fee:</th>
|
||||
<td>{data.Cost}</td>
|
||||
<td>{conversion}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<th scope="col">Nonce:</th>
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ class TransactionTable extends Component {
|
|||
render() {
|
||||
|
||||
const table = this.state.data.map((data, i) => {
|
||||
const conversion = data.Cost / 10000000000000000000;
|
||||
return <TransactionsTable
|
||||
key={`${data.TxHash}${i}`}
|
||||
age={data.Age}
|
||||
|
|
@ -33,8 +34,10 @@ class TransactionTable extends Component {
|
|||
to={data.To}
|
||||
from={data.From}
|
||||
value={data.Amount}
|
||||
cost={data.Cost}
|
||||
cost={conversion}
|
||||
getBlockTransactions={this.props.getBlockTransactions}
|
||||
detailTransactionHandler={this.props.detailTransactionHandler}
|
||||
detailAccountHandler={this.props.detailAccountHandler}
|
||||
/>
|
||||
})
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import { Link } from 'react-router-dom'
|
|||
|
||||
const TransactionTable = (props) => {
|
||||
let flag;
|
||||
if(props.txHash.indexOf("GENESIS") != -1) {
|
||||
if(props.txHash.indexOf("GENESIS") !== -1) {
|
||||
flag = false
|
||||
}else {
|
||||
flag = true
|
||||
|
|
@ -18,11 +18,11 @@ const TransactionTable = (props) => {
|
|||
<Link to="/transaction/details" className={flag ? "" : classes.disabled} onClick={() => props.detailTransactionHandler(props.txHash)}>
|
||||
{props.txHash}</Link>
|
||||
</td>
|
||||
<td>{props.blockNumber}</td>
|
||||
<td><Link to="/block/transactions" onClick={() => props.getBlockTransactions(props.blockNumber)}>{props.blockNumber}</Link></td>
|
||||
<td>{props.age}</td>
|
||||
<td className={classes.fromTag}>{props.from}</td>
|
||||
<td className={flag ? classes.fromTag : classes.disabled }><Link to="/account/detail" onClick={() => props.detailAccountHandler(props.from)}>{props.from}</Link></td>
|
||||
<td><img className={classes.arrow} src={arrow} alt="arrow"/></td>
|
||||
<td className={classes.toTag}>{props.to}</td>
|
||||
<td className={classes.toTag}><Link to="/account/detail" onClick={() => props.detailAccountHandler(props.to)}>{props.to}</Link></td>
|
||||
<td>{props.value}</td>
|
||||
<td>{props.cost}</td>
|
||||
</tr>
|
||||
|
|
|
|||
|
|
@ -11,12 +11,15 @@ import TransactionRow from '../components/table/transactions/transactionRow';
|
|||
import TransactionHeader from "../components/nav/transactionHeader/transactionHeader";
|
||||
import TransactionDetailHeader from "../components/nav/transactionHeader/transactionDetailHeader";
|
||||
import DetailTransactionTable from "../components/table/transactions/transactionDetailsRow";
|
||||
import BlockTxs from "../components/table/transactions/blockTx";
|
||||
|
||||
///**BLOCKS**///
|
||||
import BlocksRow from '../components/table/blocks/blockRows';
|
||||
import DetailBlockTable from '../components/table/blocks/blocksDetailsRow';
|
||||
import BlockDetailHeader from "../components/nav/blockHeaders/blockDetailHeader";
|
||||
import BlockHeader from "../components/nav/blockHeaders/blockHeader";
|
||||
|
||||
import BlocksMinedTable from "../components/table/blocks/blocksMined";
|
||||
import BlockCoinbaseHeader from "../components/nav/blockHeaders/blockCoinbaseHeader";
|
||||
///**ACCOUNTS**///
|
||||
import AccountsRow from '../components/table/accounts/accountRows';
|
||||
import DetailAccountsTable from "../components/table/accounts/detailAccountsRow";
|
||||
|
|
@ -31,6 +34,8 @@ class App extends Component {
|
|||
blockDetailData: [],
|
||||
transactionDetailData: [],
|
||||
accountDetailData: [],
|
||||
blocksMined: [],
|
||||
blockTransactions: [],
|
||||
reqAccount: ''
|
||||
};
|
||||
}
|
||||
|
|
@ -43,7 +48,7 @@ class App extends Component {
|
|||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
detailTransactionHandler = async(txHash) => {
|
||||
try {
|
||||
|
|
@ -53,7 +58,7 @@ class App extends Component {
|
|||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
detailAccountHandler = async(addr) => {
|
||||
try {
|
||||
|
|
@ -63,7 +68,27 @@ class App extends Component {
|
|||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getBlockTransactions = async(blockNumber) => {
|
||||
try {
|
||||
const response = await axios.get(`http://localhost:8080/api/get_all_transactions_from_block/${blockNumber}`)
|
||||
await this.setState({ blockTransactions: response.data, reqBlockNum: blockNumber })
|
||||
}
|
||||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
};
|
||||
|
||||
getBlocksMined = async(coinbase) => {
|
||||
try {
|
||||
const response = await axios.get(`http://localhost:8080/api/get_blocks_mined/${coinbase}`)
|
||||
await this.setState({ blocksMined: response.data, reqCoinbase: coinbase })
|
||||
}
|
||||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
|
|
@ -78,14 +103,20 @@ class App extends Component {
|
|||
<Route path="/transactions" render={({match}) =>
|
||||
<div>
|
||||
<TransactionHeader />
|
||||
<TransactionRow detailTransactionHandler={this.detailTransactionHandler}/>
|
||||
<TransactionRow
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailTransactionHandler={this.detailTransactionHandler}
|
||||
detailAccountHandler={this.detailAccountHandler}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/blocks" exact render={({match}) =>
|
||||
<div>
|
||||
<BlockHeader/>
|
||||
<BlocksRow detailBlockHandler={this.detailBlockHandler}/>
|
||||
<BlocksRow
|
||||
getBlocksMined={this.getBlocksMined}
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailBlockHandler={this.detailBlockHandler}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
|
|
@ -110,14 +141,40 @@ class App extends Component {
|
|||
<BlockDetailHeader
|
||||
blockNumber={this.state.blockDetailData.Number}/>
|
||||
<DetailBlockTable
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
data={this.state.blockDetailData}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/block/transactions" exact render={({match}) =>
|
||||
<div>
|
||||
<BlockDetailHeader
|
||||
blockNumber={this.state.reqBlockNum}/>
|
||||
<BlockTxs
|
||||
data={this.state.blockTransactions}
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailTransactionHandler={this.detailTransactionHandler}
|
||||
detailAccountHandler={this.detailAccountHandler}/>
|
||||
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/mined/blocks" exact render={({match}) =>
|
||||
<div>
|
||||
<BlockCoinbaseHeader
|
||||
coinbase={this.state.reqCoinbase}/>
|
||||
<BlocksMinedTable
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
getBlocksMined={this.getBlocksMined}
|
||||
data={this.state.blocksMined}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/account/detail" exact render={({match}) =>
|
||||
<div>
|
||||
<AccountDetailHeader
|
||||
addr={this.state.reqAccount}/>
|
||||
addr={this.state.reqAccount}
|
||||
data={this.state.accountDetailData}/>
|
||||
<DetailAccountsTable
|
||||
transactionDetailHandler={this.detailTransactionHandler}
|
||||
addr={this.state.reqAccount}
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ CREATE TABLE IF NOT EXISTS blocks (
|
|||
difficulty bigint,
|
||||
size text,
|
||||
nonce numeric,
|
||||
rewards numeric,
|
||||
number bigint
|
||||
);
|
||||
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ type SBlock struct {
|
|||
Difficulty string
|
||||
Size string
|
||||
Nonce string
|
||||
Rewards string
|
||||
}
|
||||
|
||||
//blockRes struct
|
||||
|
|
@ -76,10 +77,10 @@ type ShyftTxEntryPretty struct {
|
|||
From string
|
||||
BlockHash string
|
||||
BlockNumber string
|
||||
Amount uint64
|
||||
Amount string
|
||||
GasPrice uint64
|
||||
Gas uint64
|
||||
GasLimit uint64
|
||||
GasLimit string
|
||||
Cost uint64
|
||||
Nonce uint64
|
||||
Status string
|
||||
|
|
@ -104,12 +105,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
|
||||
WriteMinerRewards(sqldb,block)
|
||||
rewards := WriteMinerRewards(sqldb,block)
|
||||
coinbase := block.Header().Coinbase.String()
|
||||
number := block.Header().Number.String()
|
||||
gasUsed := block.Header().GasUsed
|
||||
|
|
@ -128,15 +124,14 @@ func WriteBlock(sqldb *sql.DB, block *types.Block, receipts []*types.Receipt) er
|
|||
}
|
||||
age := time.Unix(i, 0)
|
||||
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age, parentHash, uncleHash, difficulty, size, nonce) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12),($13)) RETURNING number`
|
||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age, parentHash, uncleHash, blockDifficulty, blockSize, blockNonce).Scan(&number)
|
||||
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age, parentHash, uncleHash, difficulty, size, rewards, nonce) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12),($13), ($14)) RETURNING number`
|
||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age, parentHash, uncleHash, blockDifficulty, blockSize, rewards, blockNonce).Scan(&number)
|
||||
if qerr != nil {
|
||||
panic(qerr)
|
||||
}
|
||||
|
||||
if block.Transactions().Len() > 0 {
|
||||
for _, tx := range block.Transactions() {
|
||||
//WriteMinerRewards(sqldb, block)
|
||||
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit)
|
||||
if block.Transactions()[0].To() != nil {
|
||||
WriteFromBalance(sqldb, tx)
|
||||
|
|
@ -411,7 +406,7 @@ func WriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s
|
|||
// uncle blocks, account balance updates based on reorgs, diverges that get dropped.
|
||||
// Reason for this is because the accounts are not deterministic like the block and tx hashes.
|
||||
// @TODO: Calculate reorg
|
||||
func WriteMinerRewards(sqldb *sql.DB, block *types.Block) {
|
||||
func WriteMinerRewards(sqldb *sql.DB, block *types.Block) string {
|
||||
minerAddr := block.Coinbase().String()
|
||||
shyftConduitAddress := Rewards.ShyftNetworkConduitAddress.String()
|
||||
// Calculate the total gas used in the block
|
||||
|
|
@ -443,9 +438,18 @@ func WriteMinerRewards(sqldb *sql.DB, block *types.Block) {
|
|||
|
||||
StoreReward(sqldb, minerAddr, totalMinerReward)
|
||||
StoreReward(sqldb, shyftConduitAddress, Rewards.ShyftNetworkBlockReward)
|
||||
var uncRewards = new(big.Int)
|
||||
for i := 0; i < len(uncleAddrs); i++ {
|
||||
uncRewards := uncleRewards[i]
|
||||
fmt.Println(uncRewards)
|
||||
StoreReward(sqldb, uncleAddrs[i], uncleRewards[i])
|
||||
}
|
||||
|
||||
fullRewardValue := new(big.Int)
|
||||
fullRewardValue.Add(totalMinerReward, Rewards.ShyftNetworkBlockReward)
|
||||
fullRewardValue.Add(fullRewardValue, uncRewards)
|
||||
|
||||
return fullRewardValue.String()
|
||||
}
|
||||
|
||||
func StoreReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||
|
|
@ -497,16 +501,7 @@ func GetAllBlocks(sqldb *sql.DB) string {
|
|||
var arr blockRes
|
||||
var blockArr string
|
||||
rows, err := sqldb.Query(`
|
||||
SELECT
|
||||
hash,
|
||||
coinbase,
|
||||
gasused,
|
||||
gaslimit,
|
||||
txcount,
|
||||
unclecount,
|
||||
age,
|
||||
number
|
||||
FROM blocks`)
|
||||
SELECT * FROM blocks`)
|
||||
if err != nil {
|
||||
fmt.Println("err")
|
||||
}
|
||||
|
|
@ -520,6 +515,12 @@ func GetAllBlocks(sqldb *sql.DB) string {
|
|||
var txCount string
|
||||
var uncleCount string
|
||||
var age string
|
||||
var parentHash string
|
||||
var uncleHash string
|
||||
var difficulty string
|
||||
var size string
|
||||
var nonce string
|
||||
var rewards string
|
||||
var num string
|
||||
|
||||
err = rows.Scan(
|
||||
|
|
@ -530,8 +531,13 @@ func GetAllBlocks(sqldb *sql.DB) string {
|
|||
&txCount,
|
||||
&uncleCount,
|
||||
&age,
|
||||
&num,
|
||||
)
|
||||
&parentHash,
|
||||
&uncleHash,
|
||||
&difficulty,
|
||||
&size,
|
||||
&nonce,
|
||||
&rewards,
|
||||
&num,)
|
||||
|
||||
arr.Blocks = append(arr.Blocks, SBlock{
|
||||
Hash: hash,
|
||||
|
|
@ -541,6 +547,12 @@ func GetAllBlocks(sqldb *sql.DB) string {
|
|||
TxCount: txCount,
|
||||
UncleCount: uncleCount,
|
||||
Age: age,
|
||||
ParentHash:parentHash,
|
||||
UncleHash:uncleHash,
|
||||
Difficulty:difficulty,
|
||||
Size: size,
|
||||
Nonce:nonce,
|
||||
Rewards: rewards,
|
||||
Number: num,
|
||||
})
|
||||
|
||||
|
|
@ -568,6 +580,7 @@ func GetBlock(sqldb *sql.DB, blockNumber string) string {
|
|||
var difficulty string
|
||||
var size string
|
||||
var nonce string
|
||||
var rewards string
|
||||
var num string
|
||||
row.Scan(
|
||||
&hash,
|
||||
|
|
@ -582,6 +595,7 @@ func GetBlock(sqldb *sql.DB, blockNumber string) string {
|
|||
&difficulty,
|
||||
&size,
|
||||
&nonce,
|
||||
&rewards,
|
||||
&num,)
|
||||
|
||||
block := SBlock{
|
||||
|
|
@ -597,6 +611,7 @@ func GetBlock(sqldb *sql.DB, blockNumber string) string {
|
|||
Difficulty:difficulty,
|
||||
Size: size,
|
||||
Nonce:nonce,
|
||||
Rewards: rewards,
|
||||
Number: num,
|
||||
}
|
||||
json, _ := json.Marshal(block)
|
||||
|
|
@ -618,6 +633,7 @@ func GetRecentBlock(sqldb *sql.DB) string {
|
|||
var difficulty string
|
||||
var size string
|
||||
var nonce string
|
||||
var rewards string
|
||||
var num string
|
||||
row.Scan(
|
||||
&hash,
|
||||
|
|
@ -632,6 +648,7 @@ func GetRecentBlock(sqldb *sql.DB) string {
|
|||
&difficulty,
|
||||
&size,
|
||||
&nonce,
|
||||
&rewards,
|
||||
&num,)
|
||||
|
||||
block := SBlock{
|
||||
|
|
@ -647,6 +664,7 @@ func GetRecentBlock(sqldb *sql.DB) string {
|
|||
Difficulty:difficulty,
|
||||
Size: size,
|
||||
Nonce:nonce,
|
||||
Rewards: rewards,
|
||||
Number: num,
|
||||
}
|
||||
json, _ := json.Marshal(block)
|
||||
|
|
@ -656,7 +674,7 @@ func GetRecentBlock(sqldb *sql.DB) string {
|
|||
func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
|
||||
var arr txRes
|
||||
var txx string
|
||||
sqlStatement := `SELECT * FROM txs WHERE blockNumber=$1`
|
||||
sqlStatement := `SELECT * FROM txs WHERE blocknumber=$1`
|
||||
rows, err := sqldb.Query(sqlStatement, blockNumber)
|
||||
if err != nil {
|
||||
fmt.Println("err")
|
||||
|
|
@ -668,10 +686,10 @@ func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
|
|||
var from_addr string
|
||||
var blockhash string
|
||||
var blocknumber string
|
||||
var amount uint64
|
||||
var amount string
|
||||
var gasprice uint64
|
||||
var gas uint64
|
||||
var gasLimit uint64
|
||||
var gasLimit string
|
||||
var txfee uint64
|
||||
var nonce uint64
|
||||
var status string
|
||||
|
|
@ -721,6 +739,72 @@ func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
|
|||
return txx
|
||||
}
|
||||
|
||||
func GetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string {
|
||||
var arr blockRes
|
||||
var blockArr string
|
||||
sqlStatement := `SELECT * FROM blocks WHERE coinbase=$1`
|
||||
rows, err := sqldb.Query(sqlStatement, coinbase)
|
||||
if err != nil {
|
||||
fmt.Println("err")
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
for rows.Next() {
|
||||
var hash string
|
||||
var coinbase string
|
||||
var gasUsed string
|
||||
var gasLimit string
|
||||
var txCount string
|
||||
var uncleCount string
|
||||
var age string
|
||||
var parentHash string
|
||||
var uncleHash string
|
||||
var difficulty string
|
||||
var size string
|
||||
var nonce string
|
||||
var rewards string
|
||||
var num string
|
||||
|
||||
err = rows.Scan(
|
||||
&hash,
|
||||
&coinbase,
|
||||
&gasUsed,
|
||||
&gasLimit,
|
||||
&txCount,
|
||||
&uncleCount,
|
||||
&age,
|
||||
&parentHash,
|
||||
&uncleHash,
|
||||
&difficulty,
|
||||
&size,
|
||||
&nonce,
|
||||
&rewards,
|
||||
&num,)
|
||||
|
||||
arr.Blocks = append(arr.Blocks, SBlock{
|
||||
Hash: hash,
|
||||
Coinbase: coinbase,
|
||||
GasUsed: gasUsed,
|
||||
GasLimit: gasLimit,
|
||||
TxCount: txCount,
|
||||
UncleCount: uncleCount,
|
||||
Age: age,
|
||||
ParentHash:parentHash,
|
||||
UncleHash:uncleHash,
|
||||
Difficulty:difficulty,
|
||||
Size: size,
|
||||
Nonce:nonce,
|
||||
Rewards: rewards,
|
||||
Number: num,
|
||||
})
|
||||
|
||||
blocks, _ := json.Marshal(arr.Blocks)
|
||||
blocksFmt := string(blocks)
|
||||
blockArr = blocksFmt
|
||||
}
|
||||
return blockArr
|
||||
}
|
||||
|
||||
//GetAllTransactions getter fn for API
|
||||
func GetAllTransactions(sqldb *sql.DB) string {
|
||||
var arr txRes
|
||||
|
|
@ -737,10 +821,10 @@ func GetAllTransactions(sqldb *sql.DB) string {
|
|||
var from_addr string
|
||||
var blockhash string
|
||||
var blocknumber string
|
||||
var amount uint64
|
||||
var amount string
|
||||
var gasprice uint64
|
||||
var gas uint64
|
||||
var gasLimit uint64
|
||||
var gasLimit string
|
||||
var txfee uint64
|
||||
var nonce uint64
|
||||
var status string
|
||||
|
|
@ -799,10 +883,10 @@ func GetTransaction(sqldb *sql.DB, txHash string) string {
|
|||
var from_addr string
|
||||
var blockhash string
|
||||
var blocknumber string
|
||||
var amount uint64
|
||||
var amount string
|
||||
var gasprice uint64
|
||||
var gas uint64
|
||||
var gasLimit uint64
|
||||
var gasLimit string
|
||||
var txfee uint64
|
||||
var nonce uint64
|
||||
var status string
|
||||
|
|
@ -924,10 +1008,10 @@ func GetAccountTxs(sqldb *sql.DB, address string) string {
|
|||
var from_addr string
|
||||
var blockhash string
|
||||
var blocknumber string
|
||||
var amount uint64
|
||||
var amount string
|
||||
var gasprice uint64
|
||||
var gas uint64
|
||||
var gasLimit uint64
|
||||
var gasLimit string
|
||||
var txfee uint64
|
||||
var nonce uint64
|
||||
var status string
|
||||
|
|
|
|||
Loading…
Reference in a new issue