This commit is contained in:
Tim Williams 2018-06-18 11:36:01 -04:00 committed by Dustin Brickwood
parent 6b4eb6abef
commit 802c1b061e
7 changed files with 85 additions and 25 deletions

View file

@ -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
}

View file

@ -1,4 +1,4 @@
package shyftdb
package core
import (
"fmt"

View file

@ -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()

View file

@ -1,4 +1,4 @@
package shyftdb
package core
import (
"encoding/json"
@ -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

35
core/shyft_tracer.go Normal file
View file

@ -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
}

View file

@ -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

25
eth/chaindb.go Normal file
View file

@ -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
}