From bf5b37902508dae761d459a9deceb6ca2e93683c Mon Sep 17 00:00:00 2001 From: Dustin Brickwood Date: Wed, 4 Jul 2018 20:31:29 -0400 Subject: [PATCH] need to resolve dereference issue in node.go --- core/blockchain.go | 3 +- core/shyft_database_util.go | 25 ++++++++-- eth/api_tracer.go | 21 +++++++++ eth/backend.go | 1 - eth/shyft_tracer.go | 60 ++++++------------------ miner/worker.go | 1 - rpc/http.go | 4 -- shyfttracerinterface/tracer_interface.go | 7 ++- 8 files changed, 63 insertions(+), 59 deletions(-) diff --git a/core/blockchain.go b/core/blockchain.go index f40f6019e7..47a3c65913 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -1002,7 +1002,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) + //fmt.Printf("\n\t[BLOCKCHAIN.GO bc.chainConfig] %+v", bc.chainConfig) if err := SWriteBlock(block, receipts); err != nil { return NonStatTy, err } @@ -1026,7 +1026,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { // only reason this method exists as a separate one is to make locking cleaner // with deferred statements. func (bc *BlockChain) insertChain(chain types.Blocks) (int, []interface{}, []*types.Log, error) { - fmt.Println("++++++++++ insertChain +++++++++") _, file, no, ok := runtime.Caller(1) if ok { fmt.Printf("called from %s#%d\n", file, no) diff --git a/core/shyft_database_util.go b/core/shyft_database_util.go index 2b8fe64b05..5186c8c5a2 100644 --- a/core/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -4,16 +4,19 @@ import ( "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/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/types" + Rewards "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/shyfttracerinterface" + "github.com/ethereum/go-ethereum/node" + "reflect" + ) var IShyftTracer shyfttracerinterface.IShyftTracer @@ -171,8 +174,20 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H Nonce: tx.Nonce(), Data: tx.Data(), } + + hash := txData.TxHash + fmt.Println(reflect.TypeOf(hash)) txHash := txData.TxHash.Hex() - IShyftTracer.MyTraceTransaction(txHash) //.chaindb_global + //IShyftTracer.MyTraceTransaction(txHash) + + // + var stack *node.Node + fmt.Println(reflect.TypeOf(stack)) + + prayer, err := IShyftTracer.GetTracerToRun(hash, stack) + fmt.Println("THIS IS A PRAYER", prayer) + fmt.Println(err) + from := txData.From.Hex() blockHasher := txData.BlockHash amount := txData.Amount.String() diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 81622f208e..47c4fd599c 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -38,6 +38,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" "github.com/ethereum/go-ethereum/rpc" "github.com/ethereum/go-ethereum/trie" + ) const ( @@ -529,6 +530,26 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (* return statedb, nil } + +//func GetTracerToRun(hash common.Hash) (interface{}, error) { +// config2 := params.ShyftNetworkChainConfig +// var cfg *Config +// fmt.Println(reflect.TypeOf(cfg)) +// var ctx context.Context +// var config *TraceConfig +// var fullNode *Ethereum +// var stack *node.Node +// fmt.Println(reflect.TypeOf(stack)) +// err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { +// fullNode, err := New(ctx, cfg) +// return fullNode, err +// }) +// fmt.Println(err) +// privateAPI := NewPrivateDebugAPI(config2, fullNode) +// return privateAPI.TraceTransaction(ctx, hash, config) +//} + + // TraceTransaction returns the structured logs created during the execution of EVM // and returns them as a JSON object. func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Hash, config *TraceConfig) (interface{}, error) { diff --git a/eth/backend.go b/eth/backend.go index 34d847bf2c..5737865057 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -109,7 +109,6 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { shyft_tracer := new(ShyftTracer) core.SetIShyftTracer(shyft_tracer) - fmt.Println("++++++++++") _, file, no, ok := runtime.Caller(1) if ok { fmt.Printf("called from %s#%d\n", file, no) diff --git a/eth/shyft_tracer.go b/eth/shyft_tracer.go index 78fc206d32..24f31019ca 100644 --- a/eth/shyft_tracer.go +++ b/eth/shyft_tracer.go @@ -3,59 +3,29 @@ package eth import ( "github.com/ethereum/go-ethereum/common" "fmt" - "github.com/ethereum/go-ethereum/core" + "github.com/ethereum/go-ethereum/node" + "github.com/ethereum/go-ethereum/params" + "context" ) -//const ( -// // defaultTraceReexec is the number of blocks the tracer is willing to go back -// // and reexecute to produce missing historical state necessary to run a specific -// // trace. -// defaultTraceReexec = uint64(128) -//) - -//var api *eth.PrivateDebugAPI - var EthereumObject interface{} type ShyftTracer struct {} -func (st ShyftTracer) MyTraceTransaction(hash string) (interface{}) { - //fmt.Println("THE stringed hash is in MYTRACETRANSACTION") - //fmt.Println(hash) - //fmt.Println(ethObjectInterface.GetEthObject()) - common_hash := common.HexToHash(hash) +func (st ShyftTracer) GetTracerToRun(hash common.Hash, stack *node.Node) (interface{}, error) { + config2 := params.ShyftNetworkChainConfig + var cfg *Config + var ctx context.Context + var config *TraceConfig + var fullNode *Ethereum - - //fmt.Println("the chain db is in MyTraceTransaction") - //fmt.Println(Chaindb_global) - if Chaindb_global == nil { - return nil - } - - tx, blockHash, _, index := core.GetTransaction(Chaindb_global, common_hash) - - if tx == nil { - fmt.Println("TRANSACTION NOT FOUND IN MyTraceTransaction +++++++++") - } - - reexec := defaultTraceReexec - //if config != nil && config.Reexec != nil { - // reexec = *config.Reexec - //} - msg, vmctx, statedb, err := DebugApi.computeTxEnv(blockHash, int(index), reexec) - - fmt.Println("stuff and nonsense") - fmt.Println(msg) - fmt.Println(vmctx) - fmt.Println(statedb) + err := stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { + fullNode, err := New(ctx, cfg) + return fullNode, err + }) fmt.Println(err) - - //fmt.Println("the tx is ") - //fmt.Println(tx) - //fmt.Println(blockHash) - //fmt.Println(index) - //DebugApi.traceTx(ctx, msg, vmctx, statedb, config) - return 42 + privateAPI := NewPrivateDebugAPI(config2, fullNode) + return privateAPI.TraceTransaction(ctx, hash, config) } func setEthObject(ethobj interface{}){ diff --git a/miner/worker.go b/miner/worker.go index d1880456fc..fa331b53eb 100644 --- a/miner/worker.go +++ b/miner/worker.go @@ -309,7 +309,6 @@ func (self *worker) wait() { for _, log := range work.state.Logs() { log.BlockHash = block.Hash() } - fmt.Printf("\n\t[WORKER.GO self.eth] %+v\n", self.eth) // NOTE:SHYFT Added eth to writeBlockWithState stat, err := self.chain.WriteBlockWithState(block, work.receipts, work.state) if err != nil { diff --git a/rpc/http.go b/rpc/http.go index 3011222483..9805d69b63 100644 --- a/rpc/http.go +++ b/rpc/http.go @@ -231,10 +231,6 @@ func (h *virtualHostHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { } if ipAddr := net.ParseIP(host); ipAddr != nil { // It's an IP address, we can serve that - fmt.Println("THE write is ") - fmt.Println(w) - fmt.Println("The read is ") - fmt.Println(r) h.next.ServeHTTP(w, r) return diff --git a/shyfttracerinterface/tracer_interface.go b/shyfttracerinterface/tracer_interface.go index a2f775e570..40d341b028 100644 --- a/shyfttracerinterface/tracer_interface.go +++ b/shyfttracerinterface/tracer_interface.go @@ -1,5 +1,10 @@ package shyfttracerinterface +import ( + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/node" +) + type IShyftTracer interface { - MyTraceTransaction(hash string) (interface{}) + GetTracerToRun(hash common.Hash, stack *node.Node) (interface{}, error) }