mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
added rewards to UI
This commit is contained in:
parent
8e6ff5f621
commit
f9b1ed77b4
11 changed files with 140 additions and 34 deletions
|
|
@ -26,9 +26,9 @@ class AccountTable extends Component {
|
|||
const sorted = [...this.state.data];
|
||||
sorted.sort((a, b) => a.Balance > b.Balance);
|
||||
const table = sorted.reverse().map((data, i) => {
|
||||
const conversion = data.Balance / 1000000000000000000;
|
||||
const conversion = data.Balance / 10000000000000000000;
|
||||
const total = sorted
|
||||
.map(num => num.Balance / 1000000000000000000)
|
||||
.map(num => num.Balance / 10000000000000000000)
|
||||
.reduce((acc, cur) => acc + cur ,0);
|
||||
const percentage = ( (conversion / total) *100);
|
||||
return <AccountsTable
|
||||
|
|
|
|||
|
|
@ -14,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);
|
||||
|
|
@ -24,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}
|
||||
|
|
@ -34,6 +35,7 @@ class BlocksTable extends Component {
|
|||
GasLimit={data.GasLimit}
|
||||
UncleCount={data.UncleCount}
|
||||
TxCount={data.TxCount}
|
||||
Reward={conversion}
|
||||
detailBlockHandler={this.props.detailBlockHandler}
|
||||
/>
|
||||
});
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ const BlockTable = (props) => {
|
|||
<td>{props.GasUsed}</td>
|
||||
<td>{props.GasLimit}</td>
|
||||
<td>TBD</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,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,7 +34,8 @@ 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}
|
||||
/>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ 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={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>
|
||||
|
|
|
|||
|
|
@ -11,6 +11,8 @@ 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';
|
||||
|
|
@ -31,6 +33,7 @@ class App extends Component {
|
|||
blockDetailData: [],
|
||||
transactionDetailData: [],
|
||||
accountDetailData: [],
|
||||
blockTransactions: [],
|
||||
reqAccount: ''
|
||||
};
|
||||
}
|
||||
|
|
@ -65,6 +68,16 @@ class App extends Component {
|
|||
}
|
||||
};
|
||||
|
||||
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 })
|
||||
}
|
||||
catch(error) {
|
||||
console.log(error)
|
||||
}
|
||||
};
|
||||
|
||||
render() {
|
||||
return (
|
||||
<BrowserRouter>
|
||||
|
|
@ -79,6 +92,7 @@ class App extends Component {
|
|||
<div>
|
||||
<TransactionHeader />
|
||||
<TransactionRow
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailTransactionHandler={this.detailTransactionHandler}
|
||||
detailAccountHandler={this.detailAccountHandler}/>
|
||||
</div>}
|
||||
|
|
@ -87,7 +101,9 @@ class App extends Component {
|
|||
<Route path="/blocks" exact render={({match}) =>
|
||||
<div>
|
||||
<BlockHeader/>
|
||||
<BlocksRow detailBlockHandler={this.detailBlockHandler}/>
|
||||
<BlocksRow
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailBlockHandler={this.detailBlockHandler}/>
|
||||
</div>}
|
||||
/>
|
||||
|
||||
|
|
@ -112,10 +128,24 @@ 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.blockTransactions.BlockNumber}/>*/}
|
||||
<BlockTxs
|
||||
data={this.state.blockTransactions}
|
||||
getBlockTransactions={this.getBlockTransactions}
|
||||
detailTransactionHandler={this.detailTransactionHandler}
|
||||
detailAccountHandler={this.detailAccountHandler}/>
|
||||
|
||||
</div>}
|
||||
/>
|
||||
|
||||
<Route path="/account/detail" exact render={({match}) =>
|
||||
<div>
|
||||
<AccountDetailHeader
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in a new issue