mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
internal Tx endpoint successfully fetching internal tx data
This commit is contained in:
parent
32f7862540
commit
68f829f12a
6 changed files with 70 additions and 59 deletions
|
|
@ -372,7 +372,7 @@ func InsertTx(sqldb *sql.DB, txData stypes.ShyftTxEntryPretty) {
|
||||||
//InsertInternalTx writes internal tx to Postgres Db
|
//InsertInternalTx writes internal tx to Postgres Db
|
||||||
func InsertInternalTx(sqldb *sql.DB, i stypes.InteralWrite) {
|
func InsertInternalTx(sqldb *sql.DB, i stypes.InteralWrite) {
|
||||||
var returnValue string
|
var returnValue string
|
||||||
sqlStatement := `INSERT INTO internaltxs(type, txhash, from_addr, to_addr, amount, gas, gasUsed, time, input, output) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING txHash`
|
sqlStatement := `INSERT INTO internaltxs(action, txhash, from_addr, to_addr, amount, gas, gasUsed, time, input, output) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING txHash`
|
||||||
qerr := sqldb.QueryRow(sqlStatement, i.Action, strings.ToLower(i.Hash), strings.ToLower(i.From), strings.ToLower(i.To), i.Value, i.Gas, i.GasUsed, i.Time, i.Input, i.Output).Scan(&returnValue)
|
qerr := sqldb.QueryRow(sqlStatement, i.Action, strings.ToLower(i.Hash), strings.ToLower(i.From), strings.ToLower(i.To), i.Value, i.Gas, i.GasUsed, i.Time, i.Input, i.Output).Scan(&returnValue)
|
||||||
if qerr != nil {
|
if qerr != nil {
|
||||||
fmt.Println(qerr)
|
fmt.Println(qerr)
|
||||||
|
|
|
||||||
|
|
@ -429,31 +429,43 @@ func SGetAllInternalTransactions(sqldb *sql.DB) string {
|
||||||
|
|
||||||
//GetInternalTransaction fn returns single tx
|
//GetInternalTransaction fn returns single tx
|
||||||
func SGetInternalTransaction(sqldb *sql.DB, txHash string) string {
|
func SGetInternalTransaction(sqldb *sql.DB, txHash string) string {
|
||||||
|
var arr stypes.InternalArray
|
||||||
|
var internaltx string
|
||||||
|
|
||||||
sqlStatement := `SELECT * FROM internaltxs WHERE txhash=$1;`
|
sqlStatement := `SELECT * FROM internaltxs WHERE txhash=$1;`
|
||||||
row := sqldb.QueryRow(sqlStatement, txHash)
|
rows, err := sqldb.Query(sqlStatement, txHash)
|
||||||
var txhash, action, to_addr, from_addr, amount, input, output string
|
if err != nil {
|
||||||
var id int
|
fmt.Println("err")
|
||||||
var gas, gasUsed uint64
|
|
||||||
var age string
|
|
||||||
|
|
||||||
row.Scan(
|
|
||||||
&id, &txhash, &action, &to_addr, &from_addr, &amount, &gas, &gasUsed, &age, &input, &output,
|
|
||||||
)
|
|
||||||
|
|
||||||
internaltx := stypes.InteralWrite{
|
|
||||||
ID: id,
|
|
||||||
Hash: txhash,
|
|
||||||
Action: action,
|
|
||||||
To: to_addr,
|
|
||||||
From: from_addr,
|
|
||||||
Value: amount,
|
|
||||||
Gas: gas,
|
|
||||||
GasUsed: gasUsed,
|
|
||||||
Time: age,
|
|
||||||
Input: input,
|
|
||||||
Output: output,
|
|
||||||
}
|
}
|
||||||
json, _ := json.Marshal(internaltx)
|
defer rows.Close()
|
||||||
|
|
||||||
return string(json)
|
for rows.Next() {
|
||||||
|
var txhash, action, to_addr, from_addr, amount, input, output string
|
||||||
|
var id int
|
||||||
|
var gas, gasUsed uint64
|
||||||
|
var age string
|
||||||
|
|
||||||
|
err = rows.Scan(
|
||||||
|
&id, &txhash, &action, &to_addr, &from_addr, &amount, &gas, &gasUsed, &age, &input, &output,
|
||||||
|
)
|
||||||
|
|
||||||
|
arr.InternalEntry = append(arr.InternalEntry, stypes.InteralWrite{
|
||||||
|
ID: id,
|
||||||
|
Hash: txhash,
|
||||||
|
Action: action,
|
||||||
|
To: to_addr,
|
||||||
|
From: from_addr,
|
||||||
|
Value: amount,
|
||||||
|
Gas: gas,
|
||||||
|
GasUsed: gasUsed,
|
||||||
|
Time: age,
|
||||||
|
Input: input,
|
||||||
|
Output: output,
|
||||||
|
})
|
||||||
|
|
||||||
|
tx, _ := json.Marshal(arr.InternalEntry)
|
||||||
|
newtx := string(tx)
|
||||||
|
internaltx = newtx
|
||||||
|
}
|
||||||
|
return internaltx
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package eth
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/ShyftNetwork/go-empyrean/common"
|
"github.com/ShyftNetwork/go-empyrean/common"
|
||||||
"github.com/ShyftNetwork/go-empyrean/params"
|
"github.com/ShyftNetwork/go-empyrean/params"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
\connect
|
\connect shyftdb;
|
||||||
shyftdb;
|
|
||||||
DROP TABLE internalTxs;
|
DROP TABLE internalTxs;
|
||||||
DROP TABLE txs;
|
DROP TABLE txs;
|
||||||
DROP TABLE blocks;
|
DROP TABLE blocks;
|
||||||
|
|
|
||||||
|
|
@ -195,36 +195,37 @@ func GetRecentBlock(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetInternalTransactions gets internal txs
|
//GetInternalTransactions gets internal txs
|
||||||
func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
|
func GetInternalTransactionsByHash(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
sqldb, err := core.DBConnection()
|
||||||
address := vars["address"]
|
|
||||||
|
|
||||||
// mostRecentBlock := core.SGetRecentBlock(sqldb)
|
vars := mux.Vars(r)
|
||||||
// if err != nil {
|
txHash := vars["txHash"]
|
||||||
// http.Error(w, err.Error(), 500)
|
|
||||||
// return
|
internalTxs := core.SGetInternalTransaction(sqldb, txHash)
|
||||||
// }
|
if err != nil {
|
||||||
|
http.Error(w, err.Error(), 500)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
fmt.Fprintln(w, "Get InternalTransactions", address)
|
fmt.Fprintln(w, internalTxs)
|
||||||
}
|
}
|
||||||
|
|
||||||
//GetInternalTransactionsHash gets internal txs hash
|
//GetInternalTransactionsHash gets internal txs hash
|
||||||
func GetInternalTransactionsHash(w http.ResponseWriter, r *http.Request) {
|
func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
sqldb, err := core.DBConnection()
|
||||||
transactionHash := vars["transaction_hash"]
|
|
||||||
|
|
||||||
//mostRecentBlock := core.SGetRecentBlock(sqldb)
|
internalTxs := core.SGetAllInternalTransactions(sqldb)
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// http.Error(w, err.Error(), 500)
|
http.Error(w, err.Error(), 500)
|
||||||
// return
|
return
|
||||||
// }
|
}
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
||||||
fmt.Fprintln(w, "Get Internal Transaction Hash", transactionHash)
|
fmt.Fprintln(w, internalTxs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func BroadcastTx(w http.ResponseWriter, r *http.Request) {
|
func BroadcastTx(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
|
||||||
|
|
@ -58,34 +58,34 @@ var routes = Routes{
|
||||||
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{
|
Route{
|
||||||
Name: "GetAllTransactionsFromBlock",
|
Name: "GetAllTransactionsFromBlock",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Pattern: "/api/get_all_transactions_from_block/{blockNumber}",
|
Pattern: "/api/get_all_transactions_from_block/{blockNumber}",
|
||||||
HandlerFunc: GetAllTransactionsFromBlock,
|
HandlerFunc: GetAllTransactionsFromBlock,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
Name: "GetAllBlocksMinedByAddress",
|
Name: "GetAllBlocksMinedByAddress",
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
Pattern: "/api/get_blocks_mined/{coinbase}",
|
Pattern: "/api/get_blocks_mined/{coinbase}",
|
||||||
HandlerFunc: GetAllBlocksMinedByAddress,
|
HandlerFunc: GetAllBlocksMinedByAddress,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"GetInternalTransactions",
|
"GetInternalTransactions",
|
||||||
"GET",
|
"GET",
|
||||||
"/api/get_internal_transactions/{address}",
|
"/api/get_internal_transactions/",
|
||||||
GetInternalTransactions,
|
GetInternalTransactions,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"GetInternalTransactionsHash",
|
"GetInternalTransactionsByHash",
|
||||||
"GET",
|
"GET",
|
||||||
"/api/get_internal_transactions_hash/{transactions_hash}",
|
"/api/get_internal_transactions/{txHash}",
|
||||||
GetInternalTransactionsHash,
|
GetInternalTransactionsByHash,
|
||||||
},
|
},
|
||||||
Route{
|
Route{
|
||||||
"BroadcastTx",
|
"BroadcastTx",
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue