mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
updated API requests
This commit is contained in:
parent
fff2271833
commit
d7b426e9ca
6 changed files with 183 additions and 17 deletions
|
|
@ -57,6 +57,30 @@ func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, txs)
|
fmt.Fprintln(w, txs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllTransactions gets txs
|
||||||
|
func GetAllTransactionsFromBlock(w http.ResponseWriter, r *http.Request) {
|
||||||
|
vars := mux.Vars(r)
|
||||||
|
blockNumber := vars["blockNumber"]
|
||||||
|
connStr := "user=postgres dbname=shyftdb sslmode=disable"
|
||||||
|
blockExplorerDb, err := sql.Open("postgres", connStr)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
txsFromBlock := shyftdb.GetAllTransactionsFromBlock(blockExplorerDb, blockNumber)
|
||||||
|
|
||||||
|
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, txsFromBlock)
|
||||||
|
}
|
||||||
|
|
||||||
// GetAccount gets balance
|
// GetAccount gets balance
|
||||||
func GetAccount(w http.ResponseWriter, r *http.Request) {
|
func GetAccount(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
|
|
@ -161,15 +185,22 @@ func GetAllBlocks(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, block3)
|
fmt.Fprintln(w, block3)
|
||||||
}
|
}
|
||||||
|
|
||||||
//func GetRecentBlock(w http.ResponseWriter, r *http.Request) {
|
func GetRecentBlock(w http.ResponseWriter, r *http.Request) {
|
||||||
// connStr := "user=postgres dbname=shyftdb sslmode=disable"
|
connStr := "user=postgres dbname=shyftdb sslmode=disable"
|
||||||
// blockExplorerDb, err := sql.Open("postgres", connStr)
|
blockExplorerDb, err := sql.Open("postgres", connStr)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
//
|
mostRecentBlock := shyftdb.GetRecentBlock(blockExplorerDb)
|
||||||
//
|
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, mostRecentBlock)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
//GetInternalTransactions gets internal txs
|
//GetInternalTransactions gets internal txs
|
||||||
func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
|
func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,18 @@ var routes = Routes{
|
||||||
"/api/get_transaction/{txHash}",
|
"/api/get_transaction/{txHash}",
|
||||||
GetTransaction,
|
GetTransaction,
|
||||||
},
|
},
|
||||||
//Route{
|
Route{
|
||||||
// Name: "GetRecentBlock",
|
Name: "GetRecentBlock",
|
||||||
// Method: "GET",
|
Method: "GET",
|
||||||
// Pattern: "/api/get_recent_block",
|
Pattern: "/api/get_recent_block",
|
||||||
// HandlerFunc: GetRecentBlock,
|
HandlerFunc: GetRecentBlock,
|
||||||
//},
|
},
|
||||||
|
Route{
|
||||||
|
Name: "GetAllTransactionsFromBlock",
|
||||||
|
Method: "GET",
|
||||||
|
Pattern: "/api/get_all_transactions_from_block/{blockNumber}",
|
||||||
|
HandlerFunc: GetAllTransactionsFromBlock,
|
||||||
|
},
|
||||||
Route{
|
Route{
|
||||||
"GetInternalTransactions",
|
"GetInternalTransactions",
|
||||||
"GET",
|
"GET",
|
||||||
|
|
|
||||||
|
|
@ -249,7 +249,6 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis, sqldb *sql.DB) (*par
|
||||||
if genesis != nil && genesis.Config == nil {
|
if genesis != nil && genesis.Config == nil {
|
||||||
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
|
return params.AllEthashProtocolChanges, common.Hash{}, errGenesisNoConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just commit the new block if there is no stored genesis block.
|
// Just commit the new block if there is no stored genesis block.
|
||||||
stored := GetCanonicalHash(db, 0)
|
stored := GetCanonicalHash(db, 0)
|
||||||
if (stored == common.Hash{}) {
|
if (stored == common.Hash{}) {
|
||||||
|
|
|
||||||
|
|
@ -57,4 +57,9 @@ th {
|
||||||
width: 25px;
|
width: 25px;
|
||||||
height: 25px;
|
height: 25px;
|
||||||
margin-left: 15px;
|
margin-left: 15px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.disabled {
|
||||||
|
pointer-events: none;
|
||||||
|
color: black;
|
||||||
}
|
}
|
||||||
|
|
@ -4,11 +4,18 @@ import arrow from '../../assets/arrow_right.png';
|
||||||
import { Link } from 'react-router-dom'
|
import { Link } from 'react-router-dom'
|
||||||
|
|
||||||
const TransactionTable = (props) => {
|
const TransactionTable = (props) => {
|
||||||
|
let flag;
|
||||||
|
if(props.txHash.indexOf("GENESIS") != -1) {
|
||||||
|
flag = false
|
||||||
|
}else {
|
||||||
|
flag = true
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr>
|
<tr>
|
||||||
<td className={classes.addressTag}>
|
<td className={classes.addressTag}>
|
||||||
<Link to="/transaction/details" onClick={() => props.detailTransactionHandler(props.txHash)}>
|
<Link to="/transaction/details" className={flag ? "" : classes.disabled} onClick={() => props.detailTransactionHandler(props.txHash)}>
|
||||||
{props.txHash}</Link>
|
{props.txHash}</Link>
|
||||||
</td>
|
</td>
|
||||||
<td>{props.blockNumber}</td>
|
<td>{props.blockNumber}</td>
|
||||||
|
|
|
||||||
|
|
@ -588,6 +588,124 @@ func GetBlock(sqldb *sql.DB, blockNumber string) string {
|
||||||
return string(json)
|
return string(json)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetRecentBlock(sqldb *sql.DB) string {
|
||||||
|
sqlStatement := `SELECT * FROM blocks WHERE number=(SELECT MAX(number) FROM blocks);`
|
||||||
|
row := sqldb.QueryRow(sqlStatement)
|
||||||
|
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 num string
|
||||||
|
row.Scan(
|
||||||
|
&hash,
|
||||||
|
&coinbase,
|
||||||
|
&gasUsed,
|
||||||
|
&gasLimit,
|
||||||
|
&txCount,
|
||||||
|
&uncleCount,
|
||||||
|
&age,
|
||||||
|
&parentHash,
|
||||||
|
&uncleHash,
|
||||||
|
&difficulty,
|
||||||
|
&size,
|
||||||
|
&nonce,
|
||||||
|
&num,)
|
||||||
|
|
||||||
|
block := 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,
|
||||||
|
Number: num,
|
||||||
|
}
|
||||||
|
json, _ := json.Marshal(block)
|
||||||
|
return string(json)
|
||||||
|
}
|
||||||
|
|
||||||
|
func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
|
||||||
|
var arr txRes
|
||||||
|
var txx string
|
||||||
|
sqlStatement := `SELECT * FROM txs WHERE blockNumber=$1`
|
||||||
|
rows, err := sqldb.Query(sqlStatement, blockNumber)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("err")
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
for rows.Next() {
|
||||||
|
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
|
||||||
|
err = rows.Scan(
|
||||||
|
&txhash,
|
||||||
|
&to_addr,
|
||||||
|
&from_addr,
|
||||||
|
&blockhash,
|
||||||
|
&blocknumber,
|
||||||
|
&amount,
|
||||||
|
&gasprice,
|
||||||
|
&gas,
|
||||||
|
&gasLimit,
|
||||||
|
&txfee,
|
||||||
|
&nonce,
|
||||||
|
&status,
|
||||||
|
&isContract,
|
||||||
|
&age,
|
||||||
|
&data,
|
||||||
|
)
|
||||||
|
|
||||||
|
arr.TxEntry = append(arr.TxEntry, ShyftTxEntryPretty{
|
||||||
|
TxHash: txhash,
|
||||||
|
To: to_addr,
|
||||||
|
From: from_addr,
|
||||||
|
BlockHash: blockhash,
|
||||||
|
BlockNumber: blocknumber,
|
||||||
|
Amount: amount,
|
||||||
|
GasPrice: gasprice,
|
||||||
|
Gas: gas,
|
||||||
|
GasLimit: gasLimit,
|
||||||
|
Cost: txfee,
|
||||||
|
Nonce: nonce,
|
||||||
|
Status: status,
|
||||||
|
IsContract: isContract,
|
||||||
|
Age: age,
|
||||||
|
Data: data,
|
||||||
|
})
|
||||||
|
|
||||||
|
tx, _ := json.Marshal(arr.TxEntry)
|
||||||
|
newtx := string(tx)
|
||||||
|
txx = newtx
|
||||||
|
}
|
||||||
|
return txx
|
||||||
|
}
|
||||||
|
|
||||||
//GetAllTransactions getter fn for API
|
//GetAllTransactions getter fn for API
|
||||||
func GetAllTransactions(sqldb *sql.DB) string {
|
func GetAllTransactions(sqldb *sql.DB) string {
|
||||||
var arr txRes
|
var arr txRes
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue