mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 10:22:23 +00:00
added internal tx api endpoint
This commit is contained in:
parent
f345b88d07
commit
32f7862540
6 changed files with 91 additions and 4 deletions
|
|
@ -27,8 +27,9 @@ type SBlock struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type InteralWrite struct {
|
type InteralWrite struct {
|
||||||
|
ID int
|
||||||
Hash string
|
Hash string
|
||||||
Type string
|
Action string
|
||||||
From string
|
From string
|
||||||
To string
|
To string
|
||||||
Value string
|
Value string
|
||||||
|
|
@ -39,6 +40,10 @@ type InteralWrite struct {
|
||||||
Time string
|
Time string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type InternalArray struct {
|
||||||
|
InternalEntry []InteralWrite
|
||||||
|
}
|
||||||
|
|
||||||
//blockRes struct
|
//blockRes struct
|
||||||
type BlockRes struct {
|
type BlockRes struct {
|
||||||
hash string
|
hash string
|
||||||
|
|
|
||||||
|
|
@ -373,7 +373,7 @@ func InsertTx(sqldb *sql.DB, txData stypes.ShyftTxEntryPretty) {
|
||||||
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(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`
|
||||||
qerr := sqldb.QueryRow(sqlStatement, i.Type, 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)
|
||||||
panic(qerr)
|
panic(qerr)
|
||||||
|
|
|
||||||
|
|
@ -386,3 +386,74 @@ func SGetAccountTxs(sqldb *sql.DB, address string) string {
|
||||||
}
|
}
|
||||||
return txx
|
return txx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//GetAllInternalTransactions getter fn for API
|
||||||
|
func SGetAllInternalTransactions(sqldb *sql.DB) string {
|
||||||
|
var arr stypes.InternalArray
|
||||||
|
var internaltx string
|
||||||
|
rows, err := sqldb.Query(`SELECT * FROM internaltxs`)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("err")
|
||||||
|
}
|
||||||
|
defer rows.Close()
|
||||||
|
for rows.Next() {
|
||||||
|
var txhash, action, to_addr, from_addr, amount, input, output string
|
||||||
|
var gas, gasUsed uint64
|
||||||
|
var id int
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetInternalTransaction fn returns single tx
|
||||||
|
func SGetInternalTransaction(sqldb *sql.DB, txHash string) string {
|
||||||
|
sqlStatement := `SELECT * FROM internaltxs WHERE txhash=$1;`
|
||||||
|
row := sqldb.QueryRow(sqlStatement, txHash)
|
||||||
|
var txhash, action, to_addr, from_addr, amount, input, output string
|
||||||
|
var id int
|
||||||
|
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)
|
||||||
|
|
||||||
|
return string(json)
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -607,7 +607,7 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) {
|
||||||
|
|
||||||
iTx := stypes.InteralWrite{
|
iTx := stypes.InteralWrite{
|
||||||
Hash: hash.Hex(),
|
Hash: hash.Hex(),
|
||||||
Type: i.Type,
|
Action: i.Type,
|
||||||
From: i.From,
|
From: i.From,
|
||||||
To: i.To,
|
To: i.To,
|
||||||
Value: amount,
|
Value: amount,
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ CREATE TABLE IF NOT EXISTS contracts (
|
||||||
CREATE TABLE IF NOT EXISTS internalTxs (
|
CREATE TABLE IF NOT EXISTS internalTxs (
|
||||||
id SERIAL PRIMARY KEY,
|
id SERIAL PRIMARY KEY,
|
||||||
txHash text references txs(txHash),
|
txHash text references txs(txHash),
|
||||||
type text,
|
action text,
|
||||||
to_addr text,
|
to_addr text,
|
||||||
from_addr text,
|
from_addr text,
|
||||||
amount text,
|
amount text,
|
||||||
|
|
|
||||||
|
|
@ -199,6 +199,12 @@ func GetInternalTransactions(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
address := vars["address"]
|
address := vars["address"]
|
||||||
|
|
||||||
|
// mostRecentBlock := core.SGetRecentBlock(sqldb)
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
|
@ -210,6 +216,11 @@ func GetInternalTransactionsHash(w http.ResponseWriter, r *http.Request) {
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
transactionHash := vars["transaction_hash"]
|
transactionHash := vars["transaction_hash"]
|
||||||
|
|
||||||
|
//mostRecentBlock := core.SGetRecentBlock(sqldb)
|
||||||
|
// 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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue