mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
refactored gen write functions for internals
This commit is contained in:
parent
dc379b811c
commit
3f6bdfc0e4
2 changed files with 120 additions and 132 deletions
139
core/genesis.go
139
core/genesis.go
|
|
@ -24,7 +24,6 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/big"
|
"math/big"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"github.com/ShyftNetwork/go-empyrean/common"
|
"github.com/ShyftNetwork/go-empyrean/common"
|
||||||
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
|
||||||
|
|
@ -143,75 +142,25 @@ func (e *GenesisMismatchError) Error() string {
|
||||||
//WriteShyftGen writes the genesis block to Shyft db
|
//WriteShyftGen writes the genesis block to Shyft db
|
||||||
//@NOTE:SHYFT
|
//@NOTE:SHYFT
|
||||||
func WriteShyftGen(gen *Genesis, block *types.Block) {
|
func WriteShyftGen(gen *Genesis, block *types.Block) {
|
||||||
fmt.Println("IN WRITE GEN")
|
|
||||||
sqldb, _ := DBConnection()
|
sqldb, _ := DBConnection()
|
||||||
|
|
||||||
for k, v := range gen.Alloc {
|
for k, v := range gen.Alloc {
|
||||||
addr := k.String()
|
_, _, err := AccountExists(sqldb, k.String())
|
||||||
|
|
||||||
//var response string
|
|
||||||
//sqlExistsStatement := `SELECT balance from accounts WHERE addr = ($1)`
|
|
||||||
//err := sqldb.QueryRow(sqlExistsStatement, addr).Scan(&response)
|
|
||||||
fmt.Println("[GENESIS]", strings.ToLower(addr))
|
|
||||||
_, _, err := AccountExists(sqldb, addr)
|
|
||||||
fmt.Println("[]ACCOUNT EXISTS ERR", err)
|
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
//number := block.Header().Number.String()
|
var toAddr *common.Address
|
||||||
//gasUsed := block.Header().GasUsed
|
var data []byte
|
||||||
//gasLimit := block.Header().GasLimit
|
var cost, gasPrice uint64
|
||||||
//gasPrice := 0
|
//Initializing proper types for tx struct
|
||||||
//txFee := 0
|
toAddr = &k
|
||||||
//txStatus := ""
|
cost = 0
|
||||||
//isContract := false
|
gasPrice = 0
|
||||||
//data := ""
|
//Appending GENESIS to address stored as txHash and From Addr
|
||||||
addr := k.String()
|
Genesis := []string{"GENESIS_", k.String()}
|
||||||
|
GENESIS := "GENESIS"
|
||||||
|
txHash := strings.Join(Genesis, k.String())
|
||||||
|
//Create the accountNonce, set to 1 (1 incoming tx), format type
|
||||||
accountNonce := v.Nonce + 1
|
accountNonce := v.Nonce + 1
|
||||||
//i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
|
||||||
//if err != nil {
|
|
||||||
// panic(err)
|
|
||||||
//}
|
|
||||||
//age := time.Unix(i, 0)
|
|
||||||
//Genesis := []string{"GENESIS_", addr}
|
|
||||||
//GENESIS := "GENESIS"
|
|
||||||
//txHash := strings.Join(Genesis, addr)
|
|
||||||
|
|
||||||
//sqlStatement := `INSERT INTO accounts(addr, balance, accountnonce) VALUES(($1), ($2), ($3)) RETURNING addr`
|
|
||||||
//insertErr := sqldb.QueryRow(sqlStatement, strings.ToLower(addr), v.Balance.String(), accountNonce).Scan(&addr)
|
|
||||||
//if insertErr != nil {
|
|
||||||
// panic(insertErr)
|
|
||||||
//}
|
|
||||||
|
|
||||||
accountNoncee := strconv.FormatUint(accountNonce, 10)
|
accountNoncee := strconv.FormatUint(accountNonce, 10)
|
||||||
CreateAccount(sqldb, addr, v.Balance.String(), accountNoncee)
|
|
||||||
|
|
||||||
//var retNonce string
|
|
||||||
//sqlGenTxStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount,gasPrice, gas, gasLimit,txFee,nonce,txstatus, iscontract,age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
|
|
||||||
//insertError := sqldb.QueryRow(sqlGenTxStatement, txHash, GENESIS, addr, block.Header().Hash().Hex(), number, v.Balance.String(), gasPrice, gasUsed, gasLimit, txFee, accountNonce, txStatus, isContract, age, data).Scan(&retNonce)
|
|
||||||
//if insertError != nil {
|
|
||||||
// panic(insertError)
|
|
||||||
//}
|
|
||||||
default:
|
|
||||||
log.Info("Found Genesis Block")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
|
|
||||||
|
|
||||||
sqldb, _ := DBConnection()
|
|
||||||
|
|
||||||
coinbase := block.Header().Coinbase.String()
|
|
||||||
number := block.Header().Number.String()
|
|
||||||
gasUsed := block.Header().GasUsed
|
|
||||||
gasLimit := block.Header().GasLimit
|
|
||||||
uncleCount := len(block.Uncles())
|
|
||||||
parentHash := block.ParentHash().String()
|
|
||||||
uncleHash := block.UncleHash().String()
|
|
||||||
blockDifficulty := block.Difficulty().String()
|
|
||||||
blockSize := block.Size().String()
|
|
||||||
blockNonce := block.Nonce()
|
|
||||||
genesisTxCount := len(gen.Alloc)
|
|
||||||
|
|
||||||
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -219,16 +168,62 @@ func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
|
||||||
}
|
}
|
||||||
age := time.Unix(i, 0)
|
age := time.Unix(i, 0)
|
||||||
|
|
||||||
var response string
|
txData := ShyftTxEntryPretty {
|
||||||
sqlExistsStatement := `SELECT hash from blocks WHERE hash= ($1)`
|
TxHash: txHash,
|
||||||
err = sqldb.QueryRow(sqlExistsStatement, block.Header().Hash().Hex()).Scan(&response)
|
From: GENESIS,
|
||||||
|
To: toAddr,
|
||||||
|
BlockHash: block.Header().Hash().Hex(),
|
||||||
|
BlockNumber:block.Header().Number.String(),
|
||||||
|
Amount: v.Balance.String(),
|
||||||
|
Cost: cost,
|
||||||
|
GasPrice: gasPrice,
|
||||||
|
GasLimit: block.GasLimit(),
|
||||||
|
Gas: block.GasUsed(),
|
||||||
|
Nonce: accountNonce,
|
||||||
|
Age: age,
|
||||||
|
Data: data,
|
||||||
|
Status: "SUCCESS",
|
||||||
|
IsContract: false,
|
||||||
|
}
|
||||||
|
//Create account and store tx
|
||||||
|
CreateAccount(sqldb, k.String(), v.Balance.String(), accountNoncee)
|
||||||
|
InsertTx(sqldb, txData)
|
||||||
|
|
||||||
|
default:
|
||||||
|
log.Info("Found Genesis Block")
|
||||||
|
}}
|
||||||
|
}
|
||||||
|
|
||||||
|
func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
|
||||||
|
sqldb, _ := DBConnection()
|
||||||
|
|
||||||
|
i, error := strconv.ParseInt(block.Time().String(), 10, 64)
|
||||||
|
if error != nil {
|
||||||
|
panic(error)
|
||||||
|
}
|
||||||
|
age := time.Unix(i, 0)
|
||||||
|
|
||||||
|
blockData := SBlock{
|
||||||
|
Hash: block.Header().Hash().Hex(),
|
||||||
|
Coinbase: block.Header().Coinbase.String(),
|
||||||
|
Number: block.Header().Number.String(),
|
||||||
|
GasUsed: block.Header().GasUsed,
|
||||||
|
GasLimit: block.Header().GasLimit,
|
||||||
|
TxCount: len(gen.Alloc),
|
||||||
|
UncleCount: len(block.Uncles()),
|
||||||
|
Age: age,
|
||||||
|
ParentHash: block.ParentHash().String(),
|
||||||
|
UncleHash: block.UncleHash().String(),
|
||||||
|
Difficulty: block.Difficulty().String(),
|
||||||
|
Size: block.Size().String(),
|
||||||
|
Nonce: block.Nonce(),
|
||||||
|
Rewards: "0",
|
||||||
|
}
|
||||||
|
|
||||||
|
err := BlockExists(sqldb, blockData.Hash)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
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`
|
InsertBlock(sqldb, blockData)
|
||||||
qerr := sqldb.QueryRow(sqlStatement, block.Header().Hash().Hex(), coinbase, number, gasUsed, gasLimit, genesisTxCount, uncleCount, age, parentHash, uncleHash, blockDifficulty, blockSize, blockNonce).Scan(&number)
|
|
||||||
if qerr != nil {
|
|
||||||
panic(qerr)
|
|
||||||
}
|
|
||||||
case err != nil:
|
case err != nil:
|
||||||
panic(err)
|
panic(err)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -11,7 +11,6 @@ import (
|
||||||
"github.com/ShyftNetwork/go-empyrean/core/types"
|
"github.com/ShyftNetwork/go-empyrean/core/types"
|
||||||
Rewards "github.com/ShyftNetwork/go-empyrean/consensus/ethash"
|
Rewards "github.com/ShyftNetwork/go-empyrean/consensus/ethash"
|
||||||
"github.com/ShyftNetwork/go-empyrean/shyfttracerinterface"
|
"github.com/ShyftNetwork/go-empyrean/shyfttracerinterface"
|
||||||
"fmt"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
@ -100,7 +99,14 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get miner rewards
|
||||||
rewards := swriteMinerRewards(sqldb,block)
|
rewards := swriteMinerRewards(sqldb,block)
|
||||||
|
//Format block time to be stored
|
||||||
|
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
age := time.Unix(i, 0)
|
||||||
|
|
||||||
blockData := SBlock{
|
blockData := SBlock{
|
||||||
Hash: block.Header().Hash().Hex(),
|
Hash: block.Header().Hash().Hex(),
|
||||||
|
|
@ -116,20 +122,12 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
||||||
Size: block.Size().String(),
|
Size: block.Size().String(),
|
||||||
Nonce: block.Nonce(),
|
Nonce: block.Nonce(),
|
||||||
Rewards: rewards,
|
Rewards: rewards,
|
||||||
}
|
|
||||||
|
|
||||||
i, err := strconv.ParseInt(block.Time().String(), 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
panic(err)
|
|
||||||
}
|
|
||||||
age := time.Unix(i, 0)
|
|
||||||
|
|
||||||
blockAge := SBlock {
|
|
||||||
Age: age,
|
Age: age,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//Inserts block data into DB
|
//Inserts block data into DB
|
||||||
InsertBlock(sqldb, blockData, blockAge)
|
InsertBlock(sqldb, blockData)
|
||||||
|
|
||||||
if block.Transactions().Len() > 0 {
|
if block.Transactions().Len() > 0 {
|
||||||
for _, tx := range block.Transactions() {
|
for _, tx := range block.Transactions() {
|
||||||
|
|
@ -149,24 +147,9 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
||||||
func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error {
|
func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Hash, blockNumber string, receipts []*types.Receipt, age time.Time, gasLimit uint64) error {
|
||||||
var isContract bool
|
var isContract bool
|
||||||
var statusFromReciept string
|
var statusFromReciept string
|
||||||
|
var toAddr *common.Address
|
||||||
var contractAddressFromReciept common.Address
|
var contractAddressFromReciept common.Address
|
||||||
|
|
||||||
txData := ShyftTxEntryPretty{
|
|
||||||
TxHash: tx.Hash().Hex(),
|
|
||||||
From: tx.From().Hex(),
|
|
||||||
To: tx.To(),
|
|
||||||
BlockHash: blockHash.Hex(),
|
|
||||||
BlockNumber: blockNumber,
|
|
||||||
Amount: tx.Value().String(),
|
|
||||||
Cost: tx.Cost().Uint64(),
|
|
||||||
GasPrice: tx.GasPrice().Uint64(),
|
|
||||||
GasLimit: gasLimit,
|
|
||||||
Gas: tx.Gas(),
|
|
||||||
Nonce: tx.Nonce(),
|
|
||||||
Age: age,
|
|
||||||
Data: tx.Data(),
|
|
||||||
}
|
|
||||||
|
|
||||||
if tx.To() == nil {
|
if tx.To() == nil {
|
||||||
for _, receipt := range receipts {
|
for _, receipt := range receipts {
|
||||||
statusReciept := (*types.ReceiptForStorage)(receipt).Status
|
statusReciept := (*types.ReceiptForStorage)(receipt).Status
|
||||||
|
|
@ -179,13 +162,7 @@ func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
isContract = true
|
isContract = true
|
||||||
contractData := ShyftTxEntryPretty{
|
toAddr = &contractAddressFromReciept
|
||||||
Status: statusFromReciept,
|
|
||||||
IsContract: isContract,
|
|
||||||
To: &contractAddressFromReciept,
|
|
||||||
}
|
|
||||||
//Insert Tx into DB
|
|
||||||
InsertTx(sqldb, txData, contractData)
|
|
||||||
} else {
|
} else {
|
||||||
isContract = false
|
isContract = false
|
||||||
for _, receipt := range receipts {
|
for _, receipt := range receipts {
|
||||||
|
|
@ -197,14 +174,28 @@ func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
|
||||||
statusFromReciept = "SUCCESS"
|
statusFromReciept = "SUCCESS"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
data := ShyftTxEntryPretty{
|
toAddr = tx.To()
|
||||||
|
}
|
||||||
|
|
||||||
|
txData := ShyftTxEntryPretty{
|
||||||
|
TxHash: tx.Hash().Hex(),
|
||||||
|
From: tx.From().Hex(),
|
||||||
|
To: toAddr,
|
||||||
|
BlockHash: blockHash.Hex(),
|
||||||
|
BlockNumber: blockNumber,
|
||||||
|
Amount: tx.Value().String(),
|
||||||
|
Cost: tx.Cost().Uint64(),
|
||||||
|
GasPrice: tx.GasPrice().Uint64(),
|
||||||
|
GasLimit: gasLimit,
|
||||||
|
Gas: tx.Gas(),
|
||||||
|
Nonce: tx.Nonce(),
|
||||||
|
Age: age,
|
||||||
|
Data: tx.Data(),
|
||||||
Status: statusFromReciept,
|
Status: statusFromReciept,
|
||||||
IsContract: isContract,
|
IsContract: isContract,
|
||||||
To: tx.To(),
|
|
||||||
}
|
|
||||||
//Insert Tx into DB
|
|
||||||
InsertTx(sqldb, txData, data)
|
|
||||||
}
|
}
|
||||||
|
//Inserts Tx into DB
|
||||||
|
InsertTx(sqldb, txData)
|
||||||
//Runs necessary functions for tracing internal transactions through tracers.go
|
//Runs necessary functions for tracing internal transactions through tracers.go
|
||||||
IShyftTracer.GetTracerToRun(tx.Hash())
|
IShyftTracer.GetTracerToRun(tx.Hash())
|
||||||
|
|
||||||
|
|
@ -309,16 +300,9 @@ func SWriteInternalTxBalances(sqldb *sql.DB, toAddr string, fromAddr string, amo
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
default:
|
default:
|
||||||
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, sendAndReceiveData.From)
|
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, sendAndReceiveData.From)
|
||||||
if err == sql.ErrNoRows {
|
|
||||||
fmt.Println("NOT IN ACCOUNTS TABLE", sendAndReceiveData.From)
|
|
||||||
fmt.Println("THIS RAN NO ERR FROM ADDR")
|
|
||||||
//accountNonce := "1"
|
|
||||||
//CreateAccount(sqldb, sendAndReceiveData.From, sendAndReceiveData.Amount, accountNonce)
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var newBalanceReceiver, newBalanceSender, newAccountNonceReceiver, newAccountNonceSender big.Int
|
var newBalanceReceiver, newBalanceSender, newAccountNonceReceiver, newAccountNonceSender big.Int
|
||||||
var nonceIncrement = big.NewInt(1)
|
var nonceIncrement = big.NewInt(1)
|
||||||
|
|
||||||
|
|
@ -404,7 +388,6 @@ func sstoreReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||||
addressBalance, accountNonce, err := AccountExists(sqldb, address)
|
addressBalance, accountNonce, err := AccountExists(sqldb, address)
|
||||||
|
|
||||||
if err == sql.ErrNoRows {
|
if err == sql.ErrNoRows {
|
||||||
fmt.Println("this ran", address)
|
|
||||||
// Addr does not exist, thus create new entry
|
// Addr does not exist, thus create new entry
|
||||||
// We convert totalReward into a string and postgres converts into number
|
// We convert totalReward into a string and postgres converts into number
|
||||||
CreateAccount(sqldb, address, reward.String(), "1")
|
CreateAccount(sqldb, address, reward.String(), "1")
|
||||||
|
|
@ -440,19 +423,17 @@ func sstoreReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||||
//DB Utility functions
|
//DB Utility functions
|
||||||
//////////////////////
|
//////////////////////
|
||||||
func CreateAccount (sqldb *sql.DB, addr string, balance string, accountNonce string) {
|
func CreateAccount (sqldb *sql.DB, addr string, balance string, accountNonce string) {
|
||||||
fmt.Println("[CREATE ACCOUNT]", strings.ToLower(addr))
|
sqlStatement := `INSERT INTO accounts(addr, balance, accountNonce) VALUES(($1), ($2), ($3)) RETURNING addr`
|
||||||
//sqlStatement := `INSERT INTO accounts(addr, balance, accountNonce) VALUES(($1), ($2), ($3)) RETURNING addr`
|
insertErr := sqldb.QueryRow(sqlStatement, strings.ToLower(addr), balance, accountNonce).Scan(&addr)
|
||||||
//insertErr := sqldb.QueryRow(sqlStatement, strings.ToLower(addr), balance, accountNonce).Scan(&addr)
|
if insertErr != nil {
|
||||||
//if insertErr != nil {
|
panic(insertErr)
|
||||||
// panic(insertErr)
|
}
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func AccountExists (sqldb *sql.DB, addr string) (string, string, error) {
|
func AccountExists (sqldb *sql.DB, addr string) (string, string, error) {
|
||||||
var addressBalance, accountNonce string
|
var addressBalance, accountNonce string
|
||||||
sqlExistsStatement := `SELECT balance, accountNonce from accounts WHERE addr = ($1)`
|
sqlExistsStatement := `SELECT balance, accountNonce from accounts WHERE addr = ($1)`
|
||||||
err := sqldb.QueryRow(sqlExistsStatement, addr).Scan(&addressBalance, &accountNonce)
|
err := sqldb.QueryRow(sqlExistsStatement, strings.ToLower(addr)).Scan(&addressBalance, &accountNonce)
|
||||||
|
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
return addressBalance, accountNonce, err
|
return addressBalance, accountNonce, err
|
||||||
|
|
@ -463,27 +444,39 @@ func AccountExists (sqldb *sql.DB, addr string) (string, string, error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BlockExists (sqldb *sql.DB, hash string) (error) {
|
||||||
|
var res string
|
||||||
|
sqlExistsStatement := `SELECT hash from blocks WHERE hash= ($1)`
|
||||||
|
err := sqldb.QueryRow(sqlExistsStatement, strings.ToLower(hash)).Scan(&res)
|
||||||
|
switch {
|
||||||
|
case err == sql.ErrNoRows:
|
||||||
|
return err
|
||||||
|
panic(err)
|
||||||
|
default:
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateAccount(sqldb *sql.DB, addr string, balance string, accountNonce string) {
|
func UpdateAccount(sqldb *sql.DB, addr string, balance string, accountNonce string) {
|
||||||
updateSQLStatement := `UPDATE accounts SET balance = ($2), accountNonce = ($3) WHERE addr = ($1)`
|
updateSQLStatement := `UPDATE accounts SET balance = ($2), accountNonce = ($3) WHERE addr = ($1)`
|
||||||
_, updateErr := sqldb.Exec(updateSQLStatement, addr, balance, accountNonce)
|
_, updateErr := sqldb.Exec(updateSQLStatement, strings.ToLower(addr), balance, accountNonce)
|
||||||
if updateErr != nil {
|
if updateErr != nil {
|
||||||
panic(updateErr)
|
panic(updateErr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertBlock(sqldb *sql.DB, blockData SBlock, blockAge SBlock) {
|
func InsertBlock(sqldb *sql.DB, blockData SBlock) {
|
||||||
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`
|
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, blockData.Hash, blockData.Coinbase, blockData.Number, blockData.GasUsed, blockData.GasLimit, blockData.TxCount, blockData.UncleCount, blockAge.Age, blockData.ParentHash, blockData.UncleHash, blockData.Difficulty, blockData.Size, blockData.Rewards, blockData.Nonce).Scan(&blockData.Number)
|
qerr := sqldb.QueryRow(sqlStatement, strings.ToLower(blockData.Hash), blockData.Coinbase, blockData.Number, blockData.GasUsed, blockData.GasLimit, blockData.TxCount, blockData.UncleCount, blockData.Age, blockData.ParentHash, blockData.UncleHash, blockData.Difficulty, blockData.Size, blockData.Rewards, blockData.Nonce).Scan(&blockData.Number)
|
||||||
if qerr != nil {
|
if qerr != nil {
|
||||||
panic(qerr)
|
panic(qerr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InsertTx (sqldb *sql.DB, txData ShyftTxEntryPretty) {
|
||||||
func InsertTx (sqldb *sql.DB, txData ShyftTxEntryPretty, data ShyftTxEntryPretty) {
|
|
||||||
var retNonce string
|
var retNonce string
|
||||||
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit, txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
|
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit, txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
|
||||||
err := sqldb.QueryRow(sqlStatement, txData.TxHash, txData.From, data.To.String(), txData.BlockHash, txData.BlockNumber, txData.Amount, txData.GasPrice, txData.Gas, txData.GasLimit, txData.Cost, txData.Nonce, data.IsContract, data.Status, txData.Age, txData.Data).Scan(&retNonce)
|
err := sqldb.QueryRow(sqlStatement, strings.ToLower(txData.TxHash), txData.From, txData.To.String(), strings.ToLower(txData.BlockHash), txData.BlockNumber, txData.Amount, txData.GasPrice, txData.Gas, txData.GasLimit, txData.Cost, txData.Nonce, txData.IsContract, txData.Status, txData.Age, txData.Data).Scan(&retNonce)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue