diff --git a/eth/backend.go b/eth/backend.go index 94b94f157e..3f9a813567 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -232,6 +232,8 @@ func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { DebugApi.eth = eth DebugApi.config = chainConfig + // Shyft Tracer + InitTracerEnv() return eth, nil } diff --git a/eth/chaindb.go b/eth/chaindb.go index 4ff89683fb..19f999d023 100644 --- a/eth/chaindb.go +++ b/eth/chaindb.go @@ -4,6 +4,8 @@ import ( "github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/node" "fmt" + "io/ioutil" + "os" ) var Chaindb_global ethdb.Database @@ -24,4 +26,22 @@ func chaindb(ctx *node.ServiceContext, config *Config) (ethdb.Database, error) { return Chaindb_global, nil } return nil, err +} + +//(*ethdb.LDBDatabase, func()) +func NewShyftTestLDB() { + dirname, err := ioutil.TempDir(os.TempDir(), "shyftdb_test_") + if err != nil { + panic("failed to create test file: " + err.Error()) + } + db, err := ethdb.NewLDBDatabase(dirname, 0, 0) + if err != nil { + panic("failed to create test database: " + err.Error()) + } + Chaindb_global = db + + //return db, func() { + // db.Close() + // os.RemoveAll(dirname) + //} } \ No newline at end of file diff --git a/eth/shyft_tracer.go b/eth/shyft_tracer.go index 5fa2eb392f..0e1bcd6734 100644 --- a/eth/shyft_tracer.go +++ b/eth/shyft_tracer.go @@ -12,23 +12,35 @@ var EthereumObject interface{} type ShyftTracer struct {} -func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { +var PrivateAPI *PrivateDebugAPI +var Context context.Context +var TracerConfig *TraceConfig + +func InitTracerEnv() { + fmt.Println("INIT tracer Env") config2 := params.ShyftNetworkChainConfig jsTracer := "callTracer" var ctx2 context.Context + Context = ctx2 config := &TraceConfig{ LogConfig: nil, Tracer: &jsTracer, // needs to be non-nil Timeout: nil, Reexec: nil, } + TracerConfig = config fmt.Println("+++++++++++++++++++++++++++ before FULLNODE", Global_config) + // called here fullNode, _ := SNew(Global_config) fmt.Println("+++++++++++++++++++++++++++ after FULLNODE") privateAPI := NewPrivateDebugAPI(config2, fullNode) + PrivateAPI = privateAPI fmt.Println("+++++++++++++++++++++++++++ after privateAPI") - return privateAPI.STraceTransaction(ctx2, hash, config) +} + +func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { + return PrivateAPI.STraceTransaction(Context, hash, TracerConfig) } func setEthObject(ethobj interface{}){ diff --git a/shyftDb/shyft_database_util_test.go b/shyftDb/shyft_database_util_test.go index 4875f656d9..9ce11ea3b8 100644 --- a/shyftDb/shyft_database_util_test.go +++ b/shyftDb/shyft_database_util_test.go @@ -29,6 +29,7 @@ const ( ) func TestBlock(t *testing.T) { + eth.NewShyftTestLDB() core.InitDBTest() shyft_tracer := new(eth.ShyftTracer) core.SetIShyftTracer(shyft_tracer) @@ -55,6 +56,8 @@ func TestBlock(t *testing.T) { eth.SetGlobalConfig(ethConf) + eth.InitTracerEnv() + t.Run("TestBlockToReturnBlock", func(t *testing.T) { key, _ := crypto.HexToECDSA("b71c71a67e1177ad4e901695e1b4b9ee17ae16c6668d313eac2f96dbcda3f291") signer := types.NewEIP155Signer(big.NewInt(2147483647))