diff --git a/core/blockchain.go b/core/blockchain.go index d81f262abc..4216999069 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -33,7 +33,6 @@ import ( "github.com/ethereum/go-ethereum/common/mclock" "github.com/ethereum/go-ethereum/consensus" "github.com/ethereum/go-ethereum/core/state" - "github.com/ethereum/go-ethereum/shyftdb" "github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" @@ -903,7 +902,7 @@ func (bc *BlockChain) WriteBlockWithState(block *types.Block, receipts []*types. } // NOTE:SHYFT - Write block data for block explorer fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig) - if err := shyftdb.WriteBlock(block, receipts); err != nil { + if err := SWriteBlock(block, receipts); err != nil { return NonStatTy, err } diff --git a/shyftDb/db.go b/core/db.go similarity index 97% rename from shyftDb/db.go rename to core/db.go index f95871fd28..3fedb09b18 100644 --- a/shyftDb/db.go +++ b/core/db.go @@ -1,4 +1,4 @@ -package shyftdb +package core import ( "fmt" @@ -34,4 +34,4 @@ func DBConnection() (*sql.DB, error) { } } return blockExplorerDb, nil -} \ No newline at end of file +} diff --git a/core/genesis.go b/core/genesis.go index 26f7a771f1..ade6d3f0de 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -35,7 +35,6 @@ import ( "github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/rlp" - "github.com/ethereum/go-ethereum/shyftdb" "database/sql" "strconv" "time" @@ -145,7 +144,7 @@ func (e *GenesisMismatchError) Error() string { //@NOTE:SHYFT func WriteShyftGen(gen *Genesis, block *types.Block) { - sqldb, _ := shyftdb.DBConnection() + sqldb, _ := DBConnection() for k := range gen.Alloc { addr := k.String() @@ -195,7 +194,7 @@ func WriteShyftGen(gen *Genesis, block *types.Block) { func WriteShyftBlockZero(block *types.Block, gen *Genesis) error { - sqldb, _ := shyftdb.DBConnection() + sqldb, _ := DBConnection() coinbase := block.Header().Coinbase.String() number := block.Header().Number.String() diff --git a/shyftDb/shyft_database_util.go b/core/shyft_database_util.go similarity index 96% rename from shyftDb/shyft_database_util.go rename to core/shyft_database_util.go index 658abe6e07..4e464d211b 100644 --- a/shyftDb/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -1,18 +1,18 @@ -package shyftdb +package core import ( - "encoding/json" - "fmt" - "math/big" - "github.com/ethereum/go-ethereum/common" - "github.com/ethereum/go-ethereum/core/types" - "time" - "strconv" - "database/sql" - "log" +"encoding/json" +"fmt" +"math/big" +"github.com/ethereum/go-ethereum/common" +"github.com/ethereum/go-ethereum/core/types" +"time" +"strconv" +"database/sql" +"log" - _ "github.com/lib/pq" - Rewards "github.com/ethereum/go-ethereum/consensus/ethash" +_ "github.com/lib/pq" +Rewards "github.com/ethereum/go-ethereum/consensus/ethash" ) //SBlock type @@ -104,7 +104,7 @@ type SendAndReceive struct { } //WriteBlock writes to block info to sql db -func WriteBlock(block *types.Block, receipts []*types.Receipt) error { +func SWriteBlock(block *types.Block, receipts []*types.Receipt) error { sqldb, err := DBConnection() if (err != nil) { @@ -138,7 +138,7 @@ func WriteBlock(block *types.Block, receipts []*types.Receipt) error { if block.Transactions().Len() > 0 { for _, tx := range block.Transactions() { - writeTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit) + SwriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit) if block.Transactions()[0].To() != nil { writeFromBalance(sqldb, tx) } @@ -151,7 +151,7 @@ func WriteBlock(block *types.Block, receipts []*types.Receipt) error { } //writeTransactions writes to sqldb -func writeTransactions(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 { txData := ShyftTxEntry{ TxHash: tx.Hash(), From: tx.From(), @@ -165,6 +165,7 @@ func writeTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.Ha Data: tx.Data(), } txHash := txData.TxHash.Hex() + MyTraceTransaction(txHash) //.chaindb_global from := txData.From.Hex() blockHasher := txData.BlockHash amount := txData.Amount.String() @@ -545,7 +546,7 @@ func GetAllBlocks(sqldb *sql.DB) string { //GetBlock queries to send single block info //TODO provide blockHash arg passed from handler.go -func GetBlock(sqldb *sql.DB, blockNumber string) string { +func SGetBlock(sqldb *sql.DB, blockNumber string) string { sqlStatement := `SELECT * FROM blocks WHERE number=$1;` row := sqldb.QueryRow(sqlStatement, blockNumber) var hash string @@ -855,7 +856,7 @@ func GetAllTransactions(sqldb *sql.DB) string { } //GetTransaction fn returns single tx -func GetTransaction(sqldb *sql.DB, txHash string) string { +func SGetTransaction(sqldb *sql.DB, txHash string) string { sqlStatement := `SELECT * FROM txs WHERE txhash=$1;` row := sqldb.QueryRow(sqlStatement, txHash) var txhash string diff --git a/core/shyft_tracer.go b/core/shyft_tracer.go new file mode 100644 index 0000000000..aac6bf5db6 --- /dev/null +++ b/core/shyft_tracer.go @@ -0,0 +1,35 @@ +package core + +import ( + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/common" + "fmt" +) + +var Chaindb_global ethdb.Database + +func SetChainDB(db ethdb.Database){ + Chaindb_global = db +} + + + +func MyTraceTransaction(hash string) (interface{}) { + common_hash := common.StringToHash(hash) + fmt.Println("the hash is") + fmt.Println(common_hash) + + fmt.Println("the chain db is") + fmt.Println(Chaindb_global) + if Chaindb_global == nil { + return nil + } + + tx, blockHash, _, index := GetTransaction(Chaindb_global, common_hash) + + fmt.Println("the tx is ") + fmt.Println(tx) + fmt.Println(blockHash) + fmt.Println(index) + return 42 +} \ No newline at end of file diff --git a/eth/backend.go b/eth/backend.go index 44425ece9a..c78cfa3164 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -107,7 +107,7 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { if !config.SyncMode.IsValid() { return nil, fmt.Errorf("invalid sync mode %d", config.SyncMode) } - chainDb, err := CreateDB(ctx, config, "chaindata") + chainDb, err := chaindb(ctx, config) if err != nil { return nil, err } @@ -202,6 +202,7 @@ func makeExtraData(extra []byte) []byte { // CreateDB creates the chain database. func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) { + fmt.Println("in create db") db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles) if err != nil { return nil, err diff --git a/eth/chaindb.go b/eth/chaindb.go new file mode 100644 index 0000000000..e17cd37771 --- /dev/null +++ b/eth/chaindb.go @@ -0,0 +1,25 @@ +package eth + +import ( + "github.com/ethereum/go-ethereum/ethdb" + "github.com/ethereum/go-ethereum/node" + "fmt" + "github.com/ethereum/go-ethereum/core" +) + +func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { + fmt.Println("DO WE GET HERE ++++++++++++++++++++++++++++++++") + fmt.Printf("%+v", ctx) + if core.Chaindb_global != nil { + return core.Chaindb_global, nil + } + fmt.Println("FAR OUT ++++++++++++++++++++++++++++++++") + + chainDb, err := CreateDB(ctx, config, "chaindata") + fmt.Println("CHECK CHECK ++++++++++++++++") + if err == nil { + core.SetChainDB(chainDb) + return core.Chaindb_global, nil + } + return nil, err +} \ No newline at end of file