diff --git a/core/database_util.go b/core/database_util.go index af88b7733c..54572ac71b 100644 --- a/core/database_util.go +++ b/core/database_util.go @@ -265,15 +265,11 @@ func GetBlockReceipts(db DatabaseReader, hash common.Hash, number uint64) types. // GetTxLookupEntry retrieves the positional metadata associated with a transaction // hash to allow retrieving the transaction or receipt by hash. func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, uint64) { - fmt.Println("[GetTxLookupEntry FUNCTION RAN]") // Load the positional metadata from disk and bail if it fails //fmt.Println("INSIDE GetTxLookupEntry ") //fmt.Println("the db is ") //fmt.Println(db) - fmt.Println("the hash is", hash.String()) data, _ := db.Get(append(lookupPrefix, hash.Bytes()...)) - fmt.Println("the data is ") - fmt.Println(data) if len(data) == 0 { return common.Hash{}, 0, 0 } diff --git a/core/shyft_database_util.go b/core/shyft_database_util.go index 2fc57804cb..3478312288 100644 --- a/core/shyft_database_util.go +++ b/core/shyft_database_util.go @@ -14,7 +14,6 @@ _ "github.com/lib/pq" "github.com/ethereum/go-ethereum/core/types" Rewards "github.com/ethereum/go-ethereum/consensus/ethash" "github.com/ethereum/go-ethereum/shyfttracerinterface" - "reflect" ) var IShyftTracer shyfttracerinterface.IShyftTracer @@ -174,11 +173,9 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H } hash := txData.TxHash - fmt.Println(reflect.TypeOf(hash)) txHash := txData.TxHash.Hex() - //prayer, _ := IShyftTracer.GetTracerToRun(hash) - //fmt.Printf("%+v\n", prayer) + IShyftTracer.GetTracerToRun(hash) //var stack *node.Node //var cfg *eth.Config @@ -292,6 +289,25 @@ func writeContractBalance(sqldb *sql.DB, tx *types.Transaction) error { return nil } +func writeContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string) { + sendAndReceiveData := SendAndReceive{ + From: tx.From().Hex(), + Amount: tx.Value().String(), + } + + fromAddr := sendAndReceiveData.From + getAccountBalanceSender:= SGetAccount(sqldb, fromAddr) + + var senderBalance SendAndReceive + if err := json.Unmarshal([]byte(getAccountBalanceSender), &senderBalance); err != nil { + log.Fatal(err) + } + balanceSender := senderBalance.Balance + accountNonceSender := senderBalance.TxCountAccount + + return sendAndReceiveData, balanceSender, accountNonceSender +} + //writeFromBalance writes senders balance to accounts db func writeFromBalance(sqldb *sql.DB, tx *types.Transaction) error { sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := writeBalanceHelper(sqldb, tx) @@ -375,8 +391,9 @@ func writeBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s toAddr := sendAndReceiveData.To fromAddr := sendAndReceiveData.From - getAccountBalanceReceiver := GetAccount(sqldb, toAddr) - getAccountBalanceSender:= GetAccount(sqldb, fromAddr) + + getAccountBalanceReceiver := SGetAccount(sqldb, toAddr) + getAccountBalanceSender:= SGetAccount(sqldb, fromAddr) var receiverBalance SendAndReceive if err := json.Unmarshal([]byte(getAccountBalanceReceiver), &receiverBalance); err != nil { @@ -495,7 +512,7 @@ func storeReward(sqldb *sql.DB, address string, reward *big.Int) { //Look into postgres functions array_to_json(array_agg(lap)) //Example select array_to_json(array_agg(lap)) //from ( select * from blocks)lap; -func GetAllBlocks(sqldb *sql.DB) string { +func SGetAllBlocks(sqldb *sql.DB) string { var arr blockRes var blockArr string rows, err := sqldb.Query(` @@ -616,7 +633,7 @@ func SGetBlock(sqldb *sql.DB, blockNumber string) string { return string(json) } -func GetRecentBlock(sqldb *sql.DB) string { +func SGetRecentBlock(sqldb *sql.DB) string { sqlStatement := `SELECT * FROM blocks WHERE number=(SELECT MAX(number) FROM blocks);` row := sqldb.QueryRow(sqlStatement) var hash string @@ -669,7 +686,7 @@ func GetRecentBlock(sqldb *sql.DB) string { return string(json) } -func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string { +func SGetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string { var arr txRes var txx string sqlStatement := `SELECT * FROM txs WHERE blocknumber=$1` @@ -737,7 +754,7 @@ func GetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string { return txx } -func GetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string { +func SGetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string { var arr blockRes var blockArr string sqlStatement := `SELECT * FROM blocks WHERE coinbase=$1` @@ -804,7 +821,7 @@ func GetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string { } //GetAllTransactions getter fn for API -func GetAllTransactions(sqldb *sql.DB) string { +func SGetAllTransactions(sqldb *sql.DB) string { var arr txRes var txx string rows, err := sqldb.Query(` @@ -931,7 +948,7 @@ func SGetTransaction(sqldb *sql.DB, txHash string) string { } //GetAccount returns account balances -func GetAccount(sqldb *sql.DB, address string) string { +func SGetAccount(sqldb *sql.DB, address string) string { sqlStatement := `SELECT * FROM accounts WHERE addr=$1;` row := sqldb.QueryRow(sqlStatement, address) var addr string @@ -952,7 +969,7 @@ func GetAccount(sqldb *sql.DB, address string) string { } //GetAllAccounts returns all accounts and balances -func GetAllAccounts(sqldb *sql.DB) string { +func SGetAllAccounts(sqldb *sql.DB) string { var array accountRes var accountsArr string var txCountAccount string @@ -991,7 +1008,7 @@ func GetAllAccounts(sqldb *sql.DB) string { } //GetAccount returns account balances -func GetAccountTxs(sqldb *sql.DB, address string) string { +func SGetAccountTxs(sqldb *sql.DB, address string) string { var arr txRes var txx string sqlStatement := `SELECT * FROM txs WHERE to_addr=$1 OR from_addr=$1;` diff --git a/eth/api_tracer.go b/eth/api_tracer.go index 39c5779d9b..fa4c0d0f95 100644 --- a/eth/api_tracer.go +++ b/eth/api_tracer.go @@ -532,189 +532,6 @@ func (api *PrivateDebugAPI) computeStateDB(block *types.Block, reexec uint64) (* // 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) { - fmt.Println("TRACE TRANSACTION ++++++!+!+!+!+!+!+!+!+!+!+!+!++!") - _, file, no, ok := runtime.Caller(1) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(2) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(3) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(4) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(5) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(6) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(7) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(8) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(9) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(10) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(11) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(12) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(13) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(14) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(15) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(16) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(17) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(18) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(19) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(20) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(21) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(22) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(23) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(24) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(25) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(26) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(27) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(28) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(29) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(30) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(31) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(32) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(33) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(34) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(35) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(36) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(37) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(38) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(39) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(40) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - fmt.Println("////////////// ++++++++++++++++ /////////////////// Phantom *(!*!*!*!*!*!**!*!*") - _, file, no, ok = runtime.Caller(41) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(42) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(43) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - _, file, no, ok = runtime.Caller(44) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } - fmt.Println("////////////// ++++++++++++++++ /////////////////// TraceTransaction *(!*!*!*!*!*!**!*!*") - _, file, no, ok = runtime.Caller(45) - if ok { - fmt.Printf("called from %s#%d\n", file, no) - } // NOTE:SHYFT //fmt.Printf("\n\t[API_TRACER.GO api.config] %+v", api.config) //fmt.Printf("\n\t[API_TRACER.GO api.eth] %+v\n", api.eth) @@ -729,7 +546,6 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha return nil, fmt.Errorf("transaction %x not found", hash) } - fmt.Println("TX IN TRACETRANSACTION", tx) reexec := defaultTraceReexec if config != nil && config.Reexec != nil { reexec = *config.Reexec @@ -746,8 +562,6 @@ func (api *PrivateDebugAPI) TraceTransaction(ctx context.Context, hash common.Ha // be tracer dependent. func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, vmctx vm.Context, statedb *state.StateDB, config *TraceConfig) (interface{}, error) { // Assemble the structured logger or the JavaScript tracer - fmt.Println("\n [API_TRACER.GO traceTX func]") - // fmt.Printf("%+v", config, "THIS IS CONFIG") var ( tracer vm.Tracer err error @@ -756,23 +570,23 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v case config != nil && config.Tracer != nil: // Define a meaningful timeout of a single transaction trace timeout := defaultTraceTimeout + fmt.Println(timeout) if config.Timeout != nil { if timeout, err = time.ParseDuration(*config.Timeout); err != nil { return nil, err } } // Constuct the JavaScript tracer to execute with - fmt.Printf("%+v \n", *config.Tracer) if tracer, err = tracers.New(*config.Tracer); err != nil { return nil, err } // Handle timeouts and RPC cancellations - deadlineCtx, cancel := context.WithTimeout(ctx, timeout) - go func() { - <-deadlineCtx.Done() - tracer.(*tracers.Tracer).Stop(errors.New("execution timeout")) - }() - defer cancel() + //deadlineCtx, cancel := context.WithTimeout(ctx, timeout) + //go func() { + // <-deadlineCtx.Done() + // tracer.(*tracers.Tracer).Stop(errors.New("execution timeout")) + //}() + //defer cancel() case config == nil: tracer = vm.NewStructLogger(nil) @@ -798,7 +612,6 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v }, nil case *tracers.Tracer: - fmt.Println("THIS RAN MF") return tracer.GetResult() default: diff --git a/eth/shyft_tracer.go b/eth/shyft_tracer.go index d0c984d961..fb39dd5e19 100644 --- a/eth/shyft_tracer.go +++ b/eth/shyft_tracer.go @@ -5,7 +5,6 @@ import ( "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/params" "context" - "fmt" ) var EthereumObject interface{} @@ -26,7 +25,6 @@ func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { Timeout: nil, Reexec: nil, } - fmt.Printf("%+v", config, "THIS IS CONFIG IN SHYFT_TRACER") //var fullNode *Ethereum fullNode, _ := SNew(Global_config) privateAPI := NewPrivateDebugAPI(config2, fullNode) diff --git a/eth/tracers/tracer.go b/eth/tracers/tracer.go index 8c42b157b3..328549e27b 100644 --- a/eth/tracers/tracer.go +++ b/eth/tracers/tracer.go @@ -30,7 +30,7 @@ import ( "github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/log" - duktape "gopkg.in/olebedev/go-duktape.v3" + "gopkg.in/olebedev/go-duktape.v3" ) // bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js. @@ -307,13 +307,10 @@ type Tracer struct { // which must evaluate to an expression returning an object with 'step', 'fault' // and 'result' functions. func New(code string) (*Tracer, error) { - fmt.Println("\n [TRACER.GO New func]", code) // Resolve any tracers by name and assemble the tracer object if tracer, ok := tracer(code); ok { code = tracer - fmt.Println("\n [ok]", ok) } - fmt.Println("\n [tracer]", tracer) tracer := &Tracer{ vm: duktape.New(), @@ -328,6 +325,7 @@ func New(code string) (*Tracer, error) { costValue: new(uint), depthValue: new(uint), } + // Set up builtins for this environment tracer.vm.PushGlobalGoFunction("toHex", func(ctx *duktape.Context) int { ctx.PushString(hexutil.Encode(popSlice(ctx))) @@ -460,7 +458,6 @@ func New(code string) (*Tracer, error) { tracer.dbWrapper.pushObject(tracer.vm) tracer.vm.PutPropString(tracer.stateObject, "db") - return tracer, nil } @@ -500,11 +497,6 @@ func wrapError(context string, err error) error { // CaptureStart implements the Tracer interface to initialize the tracing operation. func (jst *Tracer) CaptureStart(from common.Address, to common.Address, create bool, input []byte, gas uint64, value *big.Int) error { - //fmt.Println("\n\n\t\t type: ", reflect.TypeOf(input)) - fmt.Println("\t\t [TRACER TO]:", to.String()) - fmt.Println("\t\t [TRACER FROM]:", from.String()) - fmt.Println("\t\t [TRACER VALUE]:", value.String()) - fmt.Println("\t\t [TRACER INPUT STRING]:", string(input[:len(input)]), "\n\n") jst.ctx["type"] = "CALL" if create { jst.ctx["type"] = "CREATE" @@ -573,9 +565,6 @@ func (jst *Tracer) CaptureFault(env *vm.EVM, pc uint64, op vm.OpCode, gas, cost // CaptureEnd is called after the call finishes to finalize the tracing. func (jst *Tracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, err error) error { - //fmt.Println("\n\n\t\t", reflect.TypeOf(output)) - //fmt.Println("\t\t [TRACER OUTPUT]:", output[:len(output)]) - //fmt.Println("\t\t [TRACER OUTPUT STRING]:", string(output[:len(output)]), "\n\n") jst.ctx["output"] = output jst.ctx["gasUsed"] = gasUsed jst.ctx["time"] = t.String() @@ -586,6 +575,13 @@ func (jst *Tracer) CaptureEnd(output []byte, gasUsed uint64, t time.Duration, er return nil } +type Internals struct { + From string + To string + Value string + Calls []*Internals +} + // GetResult calls the Javascript 'result' function and returns its value, or any accumulated error func (jst *Tracer) GetResult() (json.RawMessage, error) { // Transform the context into a JavaScript object and inject into the state @@ -626,5 +622,33 @@ func (jst *Tracer) GetResult() (json.RawMessage, error) { jst.vm.DestroyHeap() jst.vm.Destroy() + //var dat map[string]interface{} + var dat Internals + + if err := json.Unmarshal(result, &dat); err != nil { + panic(err) + } + + //fmt.Println("[FULL DATA]", string(result)) + //fmt.Println("\n +++++++++++++++++++") + //fmt.Println(dat["calls"]) + //fmt.Println(dat["calls"]["gasUsed"]) + //j, _ := json.Marshal(result) + //internals := string(j) + //fmt.Println("[RESULT]", dat) + //fmt.Println("[RESULT]", dat.To) + //fmt.Println("[Internal Call]", len(dat.Calls)) + + for key, val := range dat.Calls { + fmt.Println(key) + fmt.Println("[INTERNAL TO]", val.To) + fmt.Println("[INTERNAL From]", val.From) + fmt.Println("[INTERNAL Calls length]", len(val.Calls)) + for newKey, newVal := range val.Calls { + fmt.Println(newKey) + fmt.Println("[INSIDE INTERNAL TO]", newVal.To) + } + } + return result, jst.err } diff --git a/shyftBlockExplorerApi/handler.go b/shyftBlockExplorerApi/handler.go index 496941db7b..9f368d6748 100644 --- a/shyftBlockExplorerApi/handler.go +++ b/shyftBlockExplorerApi/handler.go @@ -2,13 +2,12 @@ package main ///@NOTE Shyft handler functions when endpoints are hit import ( - "database/sql" "fmt" "net/http" _ "github.com/lib/pq" - "github.com/ethereum/go-ethereum/shyftdb" + "github.com/ethereum/go-ethereum/core" "github.com/gorilla/mux" "bytes" "io/ioutil" @@ -19,13 +18,13 @@ import ( func GetTransaction(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) txHash := vars["txHash"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } - - getTxResponse := shyftdb.GetTransaction(blockExplorerDb, txHash) + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} + sqldb, err := core.DBConnection() + getTxResponse := core.SGetTransaction(sqldb, txHash) if err != nil { http.Error(w, err.Error(), 500) @@ -40,13 +39,15 @@ func GetTransaction(w http.ResponseWriter, r *http.Request) { // GetAllTransactions gets txs func GetAllTransactions(w http.ResponseWriter, r *http.Request) { - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} - txs := shyftdb.GetAllTransactions(blockExplorerDb) + sqldb, err := core.DBConnection() + + txs := core.SGetAllTransactions(sqldb) if err != nil { http.Error(w, err.Error(), 500) @@ -64,13 +65,15 @@ func GetAllTransactions(w http.ResponseWriter, r *http.Request) { func GetAllTransactionsFromBlock(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) blockNumber := vars["blockNumber"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} - txsFromBlock := shyftdb.GetAllTransactionsFromBlock(blockExplorerDb, blockNumber) + sqldb, err := core.DBConnection() + + txsFromBlock := core.SGetAllTransactionsFromBlock(sqldb, blockNumber) if err != nil { http.Error(w, err.Error(), 500) @@ -86,13 +89,15 @@ func GetAllTransactionsFromBlock(w http.ResponseWriter, r *http.Request) { func GetAllBlocksMinedByAddress(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) coinbase := vars["coinbase"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} - blocksMined := shyftdb.GetAllBlocksMinedByAddress(blockExplorerDb, coinbase) + sqldb, err := core.DBConnection() + + blocksMined := core.SGetAllBlocksMinedByAddress(sqldb, coinbase) if err != nil { http.Error(w, err.Error(), 500) @@ -109,13 +114,15 @@ func GetAllBlocksMinedByAddress(w http.ResponseWriter, r *http.Request) { func GetAccount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) address := vars["address"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} - getAccountBalance := shyftdb.GetAccount(blockExplorerDb, address) + sqldb, err := core.DBConnection() + + getAccountBalance := core.SGetAccount(sqldb, address) if err != nil { http.Error(w, err.Error(), 500) @@ -132,13 +139,15 @@ func GetAccount(w http.ResponseWriter, r *http.Request) { func GetAccountTxs(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) address := vars["address"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} - getAccountTxs := shyftdb.GetAccountTxs(blockExplorerDb, address) + sqldb, err := core.DBConnection() + + getAccountTxs := core.SGetAccountTxs(sqldb, address) if err != nil { http.Error(w, err.Error(), 500) @@ -153,12 +162,15 @@ func GetAccountTxs(w http.ResponseWriter, r *http.Request) { // GetAllAccounts gets balances func GetAllAccounts(w http.ResponseWriter, r *http.Request) { - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } - allAccounts := shyftdb.GetAllAccounts(blockExplorerDb) + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} + + sqldb, err := core.DBConnection() + + allAccounts := core.SGetAllAccounts(sqldb) if err != nil { http.Error(w, err.Error(), 500) return @@ -173,13 +185,13 @@ func GetAllAccounts(w http.ResponseWriter, r *http.Request) { func GetBlock(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) blockNumber := vars["blockNumber"] - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } - - getBlockResponse := shyftdb.GetBlock(blockExplorerDb, blockNumber) + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} + sqldb, err := core.DBConnection() + getBlockResponse := core.SGetBlock(sqldb, blockNumber) if err != nil { http.Error(w, err.Error(), 500) @@ -194,12 +206,13 @@ func GetBlock(w http.ResponseWriter, r *http.Request) { // GetAllBlocks response func GetAllBlocks(w http.ResponseWriter, r *http.Request) { - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } - block3 := shyftdb.GetAllBlocks(blockExplorerDb) + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} + sqldb, err := core.DBConnection() + block3 := core.SGetAllBlocks(sqldb) if err != nil { http.Error(w, err.Error(), 500) return @@ -210,12 +223,14 @@ func GetAllBlocks(w http.ResponseWriter, r *http.Request) { } func GetRecentBlock(w http.ResponseWriter, r *http.Request) { - connStr := "user=postgres dbname=shyftdb sslmode=disable" - blockExplorerDb, err := sql.Open("postgres", connStr) - if err != nil { - return - } - mostRecentBlock := shyftdb.GetRecentBlock(blockExplorerDb) + //connStr := "user=postgres dbname=shyftdb sslmode=disable" + //blockExplorerDb, err := sql.Open("postgres", connStr) + //if err != nil { + // return + //} + sqldb, err := core.DBConnection() + + mostRecentBlock := core.SGetRecentBlock(sqldb) if err != nil { http.Error(w, err.Error(), 500) return