updating accounts from internal txs

This commit is contained in:
Dustin Brickwood 2018-07-26 17:03:50 -04:00
parent 3f6bdfc0e4
commit ab8d98ad91
3 changed files with 54 additions and 17 deletions

View file

@ -190,7 +190,7 @@ func WriteShyftGen(gen *Genesis, block *types.Block) {
InsertTx(sqldb, txData)
default:
log.Info("Found Genesis Block")
log.Info("Found Genesis Block")
}}
}
@ -259,11 +259,20 @@ func SetupGenesisBlock(db ethdb.Database, genesis *Genesis) (*params.ChainConfig
log.Info("Writing custom genesis block")
}
block, err := genesis.Commit(db)
//@NOTE:SHYFT WRITE TO BLOCK ZERO DB
WriteShyftBlockZero(block, genesis)
//@NOTE:SHYFT WRITE TO DB
WriteShyftGen(genesis, block)
//@NOTE:SHYFT SWITCH CASE ENSURES SHYFT GENESIS FUNCTIONS ARE ONLY CALLED ONCE
sqldb, _ := DBConnection()
serror := BlockExists(sqldb, block.Hash().String())
switch {
case serror == sql.ErrNoRows:
//@NOTE:SHYFT WRITE TO BLOCK ZERO DB
WriteShyftBlockZero(block, genesis)
//@NOTE:SHYFT WRITE TO DB
WriteShyftGen(genesis, block)
case serror != nil:
panic(serror)
default:
log.Info("Genesis Block Written")
}
return genesis.Config, block.Hash(), err
}

View file

@ -12,6 +12,7 @@ import (
Rewards "github.com/ShyftNetwork/go-empyrean/consensus/ethash"
"github.com/ShyftNetwork/go-empyrean/shyfttracerinterface"
"strings"
"fmt"
)
var IShyftTracer shyfttracerinterface.IShyftTracer
@ -40,6 +41,19 @@ type SBlock struct {
Blocks []SBlock
}
type InteralWrite struct {
Hash string
Type string
From string
To string
Value string
Gas uint64
GasUsed uint64
Input string
Output string
Time string
}
//blockRes struct
type blockRes struct {
hash string
@ -482,4 +496,14 @@ func InsertTx (sqldb *sql.DB, txData ShyftTxEntryPretty) {
}
}
func InsertInternalTx(sqldb *sql.DB, i InteralWrite) {
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`
qerr := sqldb.QueryRow(sqlStatement, i.Type, i.Hash, i.From, i.To, i.Value, i.Gas, i.GasUsed, i.Time, i.Input, i.Output).Scan(&returnValue)
if qerr != nil {
fmt.Println(qerr)
panic(qerr)
}
}

View file

@ -603,18 +603,22 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) {
value, _ := hexutil.DecodeUint64(i.Value)
amount := strconv.FormatUint(value, 10)
//@TODO WRITE OVER TRANSACTION STRUCT
core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount)
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`
qerr := sqldb.QueryRow(sqlStatement, i.Type, hash.Hex(), i.From, i.To, amount, gas, gasUsed, i.Time, i.Input, i.Output).Scan(&returnValue)
if qerr != nil {
fmt.Println(qerr)
panic(qerr)
iTx := core.InteralWrite{
Hash: hash.Hex(),
Type: i.Type,
From: i.From,
To: i.To,
Value: amount,
Gas: gas,
GasUsed: gasUsed,
Input: i.Input,
Output: i.Output,
Time: i.Time,
}
//@TODO WRITE OVER TRANSACTION STRUCT
core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount)
core.InsertInternalTx(sqldb, iTx)
}
//@NOTE:SHYFT