mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
UI changes for rewards
This commit is contained in:
parent
f9b1ed77b4
commit
3a9affe2a0
10 changed files with 224 additions and 6 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",
|
||||
|
|
|
|||
|
|
@ -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.data.Coinbase}</span>
|
||||
</div>
|
||||
)
|
||||
};
|
||||
|
||||
export default blocksCoinbaseHeader;
|
||||
|
|
@ -10,6 +10,11 @@ class AccountTransactionTable extends Component {
|
|||
return <ErrorHandler />
|
||||
}else {
|
||||
table = this.props.data.map((data, i) => {
|
||||
console.log(this.props.data)
|
||||
// const total = this.props.data
|
||||
// .map(num => num.Balance / 10000000000000000000)
|
||||
// .reduce((acc, cur) => acc + cur ,0);
|
||||
const conversion = data.Cost / 10000000000000000000;
|
||||
return <DetailAccountsTable
|
||||
key={`${data.TxHash}${i}`}
|
||||
age={data.Age}
|
||||
|
|
@ -18,7 +23,7 @@ class AccountTransactionTable extends Component {
|
|||
to={data.To}
|
||||
from={data.From}
|
||||
value={data.Amount}
|
||||
cost={data.Cost}
|
||||
cost={conversion}
|
||||
addr={this.props.addr}
|
||||
detailTransactionHandler={this.props.transactionDetailHandler}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ class BlocksTable extends Component {
|
|||
TxCount={data.TxCount}
|
||||
Reward={conversion}
|
||||
detailBlockHandler={this.props.detailBlockHandler}
|
||||
getBlocksMined={this.props.getBlocksMined}
|
||||
/>
|
||||
});
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ 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>TBD</td>
|
||||
|
|
|
|||
|
|
@ -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}><Link to="/blocks/mined" onClick={() => props.getBlocksMined(props.Coinbase)}>{props.Coinbase}</Link></td>
|
||||
<td>{props.GasUsed}</td>
|
||||
<td>{props.GasLimit}</td>
|
||||
<td>TBD</td>
|
||||
<td>{props.Reward}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
)
|
||||
}
|
||||
|
||||
export default MinedBlockTable;
|
||||
|
|
@ -18,7 +18,8 @@ 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";
|
||||
|
|
@ -33,6 +34,7 @@ class App extends Component {
|
|||
blockDetailData: [],
|
||||
transactionDetailData: [],
|
||||
accountDetailData: [],
|
||||
blocksMined: [],
|
||||
blockTransactions: [],
|
||||
reqAccount: ''
|
||||
};
|
||||
|
|
@ -78,6 +80,18 @@ class App extends Component {
|
|||
}
|
||||
};
|
||||
|
||||
getBlocksMined = async(coinbase) => {
|
||||
console.log("THIS RAN")
|
||||
try {
|
||||
const response = await axios.get(`http://localhost:8080/api/get_blocks_mined/${coinbase}`)
|
||||
console.log(response.data);
|
||||
await this.setState({ blocksMined: response.data })
|
||||
}
|
||||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
|
|
@ -102,6 +116,7 @@ class App extends Component {
|
|||
<div>
|
||||
<BlockHeader/>
|
||||
<BlocksRow
|
||||
getBlocksMined={this.getBlocksMined}
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailBlockHandler={this.detailBlockHandler}/>
|
||||
</div>}
|
||||
|
|
@ -135,8 +150,8 @@ class App extends Component {
|
|||
|
||||
<Route path="/block/transactions" exact render={({match}) =>
|
||||
<div>
|
||||
{/*<BlockDetailHeader*/}
|
||||
{/*blockNumber={this.state.blockTransactions.BlockNumber}/>*/}
|
||||
<BlockDetailHeader
|
||||
blockNumber={this.state.blockTransactions.BlockNumber}/>
|
||||
<BlockTxs
|
||||
data={this.state.blockTransactions}
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
|
|
@ -146,6 +161,17 @@ class App extends Component {
|
|||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/mined/blocks" exact render={({match}) =>
|
||||
<div>
|
||||
<BlockCoinbaseHeader
|
||||
data={this.state.blocksMined}/>
|
||||
<BlocksMinedTable
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
getBlocksMined={this.getBlocksMined}
|
||||
data={this.state.blocksMined}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/account/detail" exact render={({match}) =>
|
||||
<div>
|
||||
<AccountDetailHeader
|
||||
|
|
|
|||
|
|
@ -739,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue