mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
writing contract address when isContract is true
This commit is contained in:
parent
97e2d5f603
commit
79e140e4cf
2 changed files with 56 additions and 41 deletions
|
|
@ -26,6 +26,7 @@ CREATE TABLE IF NOT EXISTS txs (
|
||||||
txFee numeric,
|
txFee numeric,
|
||||||
nonce numeric,
|
nonce numeric,
|
||||||
isContract bool,
|
isContract bool,
|
||||||
|
txStatus text,
|
||||||
data bytea
|
data bytea
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -118,31 +118,31 @@ type SendAndReceive struct {
|
||||||
blockNonce := block.Nonce()
|
blockNonce := block.Nonce()
|
||||||
|
|
||||||
// Convert the receipts into their storage form and serialize them
|
// Convert the receipts into their storage form and serialize them
|
||||||
storageReceipts := make([]*types.ReceiptForStorage, len(receipts))
|
//storageReceipts := make([]*types.ReceiptForStorage, len(receipts))
|
||||||
for i, receipt := range receipts {
|
//for i, receipt := range receipts {
|
||||||
storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
|
// storageReceipts[i] = (*types.ReceiptForStorage)(receipt)
|
||||||
var txHashFromReciept = (*types.ReceiptForStorage)(receipt).TxHash
|
// var txHashFromReciept = (*types.ReceiptForStorage)(receipt).TxHash
|
||||||
var statusFromReciept = (*types.ReceiptForStorage)(receipt).Status
|
// //var statusFromReciept = (*types.ReceiptForStorage)(receipt).Status
|
||||||
var contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress
|
// var contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress
|
||||||
if statusFromReciept == 1 {
|
// //if statusFromReciept == 1 {
|
||||||
fmt.Println("THIS IS statusFromReciept", "SUCCESS", statusFromReciept)
|
// // fmt.Println("THIS IS statusFromReciept", "SUCCESS", statusFromReciept)
|
||||||
}
|
// //}
|
||||||
if statusFromReciept == 0 {
|
// //if statusFromReciept == 0 {
|
||||||
fmt.Println("THIS IS statusFromReciept", "FAIL", statusFromReciept)
|
// // fmt.Println("THIS IS statusFromReciept", "FAIL", statusFromReciept)
|
||||||
}
|
// //}
|
||||||
|
//
|
||||||
if block.Transactions()[0].To() == nil {
|
// if block.Transactions()[0].To() == nil {
|
||||||
updateSQLStatement := `UPDATE txs SET to_addr = ($2) WHERE txHash = ($1)`
|
// updateSQLStatement := `UPDATE txs SET to_addr = ($2) WHERE txHash = ($1)`
|
||||||
_, error := sqldb.Exec(updateSQLStatement, txHashFromReciept.String(), contractAddressFromReciept.String())
|
// _, error := sqldb.Exec(updateSQLStatement, txHashFromReciept.String(), contractAddressFromReciept.String())
|
||||||
if error != nil {
|
// if error != nil {
|
||||||
panic(error)
|
// panic(error)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
fmt.Println("THIS IS txHashFromReciept", txHashFromReciept.String())
|
// //fmt.Println("THIS IS txHashFromReciept", txHashFromReciept.String())
|
||||||
fmt.Println("THIS IS contractAddressFromReciept", contractAddressFromReciept.String())
|
// //fmt.Println("THIS IS contractAddressFromReciept", contractAddressFromReciept.String())
|
||||||
}
|
//}
|
||||||
|
|
||||||
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -159,7 +159,7 @@ type SendAndReceive struct {
|
||||||
if block.Transactions().Len() > 0 {
|
if block.Transactions().Len() > 0 {
|
||||||
for _, tx := range block.Transactions() {
|
for _, tx := range block.Transactions() {
|
||||||
//WriteMinerRewards(sqldb, block)
|
//WriteMinerRewards(sqldb, block)
|
||||||
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String())
|
WriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts)
|
||||||
if block.Transactions()[0].To() != nil {
|
if block.Transactions()[0].To() != nil {
|
||||||
WriteFromBalance(sqldb, tx)
|
WriteFromBalance(sqldb, tx)
|
||||||
}
|
}
|
||||||
|
|
@ -173,7 +173,7 @@ type SendAndReceive struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
//WriteTransactions writes to sqldb
|
//WriteTransactions writes to sqldb
|
||||||
func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string) error {
|
func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt) error {
|
||||||
txData := ShyftTxEntry{
|
txData := ShyftTxEntry{
|
||||||
TxHash: tx.Hash(),
|
TxHash: tx.Hash(),
|
||||||
From: tx.From(),
|
From: tx.From(),
|
||||||
|
|
@ -198,11 +198,25 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
|
||||||
data := txData.Data
|
data := txData.Data
|
||||||
to := txData.To
|
to := txData.To
|
||||||
var isContract bool
|
var isContract bool
|
||||||
|
var statusFromReciept string
|
||||||
|
|
||||||
if (to == nil){
|
if (to == nil){
|
||||||
|
var contractAddressFromReciept string
|
||||||
|
for _, receipt := range receipts {
|
||||||
|
statusReciept := (*types.ReceiptForStorage)(receipt).Status
|
||||||
|
contractAddressFromReciept = (*types.ReceiptForStorage)(receipt).ContractAddress.String()
|
||||||
|
if statusReciept == 1 {
|
||||||
|
statusFromReciept = "SUCCESS"
|
||||||
|
}
|
||||||
|
if statusReciept == 0 {
|
||||||
|
statusFromReciept = "FAIL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var retNonce string
|
var retNonce string
|
||||||
isContract = true
|
isContract = true
|
||||||
sqlStatement := `INSERT INTO txs(txhash, from_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11)) RETURNING nonce`
|
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, txStatus, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13)) RETURNING nonce`
|
||||||
qerr := sqldb.QueryRow(sqlStatement, txHash, from, blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce)
|
qerr := sqldb.QueryRow(sqlStatement, txHash, from, contractAddressFromReciept, blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, statusFromReciept, data).Scan(&retNonce)
|
||||||
|
|
||||||
if qerr != nil {
|
if qerr != nil {
|
||||||
panic(qerr)
|
panic(qerr)
|
||||||
|
|
@ -210,8 +224,18 @@ func WriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha
|
||||||
} else {
|
} else {
|
||||||
var retNonce string
|
var retNonce string
|
||||||
isContract = false
|
isContract = false
|
||||||
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12)) RETURNING nonce`
|
for _, receipt := range receipts {
|
||||||
qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, data).Scan(&retNonce)
|
statusReciept := (*types.ReceiptForStorage)(receipt).Status
|
||||||
|
if statusReciept == 1 {
|
||||||
|
statusFromReciept = "SUCCESS"
|
||||||
|
}
|
||||||
|
if statusReciept == 0 {
|
||||||
|
statusFromReciept = "FAIL"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, txfee, nonce, isContract, txStatus, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13)) RETURNING nonce`
|
||||||
|
qerr := sqldb.QueryRow(sqlStatement, txHash, from, to.Hex(), blockHasher, blockNumber, amount, gasPrice, gas, txFee, nonce, isContract, statusFromReciept, data).Scan(&retNonce)
|
||||||
|
|
||||||
if qerr != nil {
|
if qerr != nil {
|
||||||
panic(qerr)
|
panic(qerr)
|
||||||
|
|
@ -243,13 +267,6 @@ func WriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||||
err := sqldb.QueryRow(sqlExistsStatement, fromAddr).Scan(&response)
|
err := sqldb.QueryRow(sqlExistsStatement, fromAddr).Scan(&response)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
fmt.Println("NO ROWS RAN")
|
|
||||||
//i, err := strconv.Atoi(accountNonceSen)
|
|
||||||
//if err != nil {
|
|
||||||
// fmt.Println(err)
|
|
||||||
//}
|
|
||||||
//fmt.Println("accountnonce", i)
|
|
||||||
//fmt.Println(reflect.TypeOf(i))
|
|
||||||
sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr`
|
sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr`
|
||||||
insertErr := sqldb.QueryRow(sqlStatement, fromAddr, amount, accountNonceSen).Scan(&fromAddr)
|
insertErr := sqldb.QueryRow(sqlStatement, fromAddr, amount, accountNonceSen).Scan(&fromAddr)
|
||||||
if insertErr != nil {
|
if insertErr != nil {
|
||||||
|
|
@ -321,13 +338,10 @@ func WriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||||
err := sqldb.QueryRow(sqlExistsStatement, toAddr).Scan(&response)
|
err := sqldb.QueryRow(sqlExistsStatement, toAddr).Scan(&response)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
fmt.Println("NO ROWS RAN")
|
|
||||||
i, err := strconv.Atoi(accountNonceRec)
|
i, err := strconv.Atoi(accountNonceRec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
//fmt.Println("accountnonce", i)
|
|
||||||
//fmt.Println(reflect.TypeOf(i))
|
|
||||||
sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr`
|
sqlStatement := `INSERT INTO accounts(addr, balance, txCountAccount) VALUES(($1), ($2), ($3)) RETURNING addr`
|
||||||
insertErr := sqldb.QueryRow(sqlStatement, toAddr, amount, i).Scan(&toAddr)
|
insertErr := sqldb.QueryRow(sqlStatement, toAddr, amount, i).Scan(&toAddr)
|
||||||
if insertErr != nil {
|
if insertErr != nil {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue