diff --git a/blockExplorerApi/handler.go b/blockExplorerApi/handler.go index a030a6b07a..b84d5d3537 100644 --- a/blockExplorerApi/handler.go +++ b/blockExplorerApi/handler.go @@ -74,13 +74,34 @@ func GetAllTransactionsFromBlock(w http.ResponseWriter, r *http.Request) { return } - w.Header().Set("Content-Type", "application/json; charset=UTF-8") w.WriteHeader(http.StatusOK) fmt.Fprintln(w, txsFromBlock) } +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 + } + + blocksMined := shyftdb.GetAllBlocksMinedByAddress(blockExplorerDb, coinbase) + + if err != nil { + http.Error(w, err.Error(), 500) + return + } + + w.Header().Set("Content-Type", "application/json; charset=UTF-8") + w.WriteHeader(http.StatusOK) + + fmt.Fprintln(w, blocksMined) +} + // GetAccount gets balance func GetAccount(w http.ResponseWriter, r *http.Request) { vars := mux.Vars(r) diff --git a/blockExplorerApi/routes.go b/blockExplorerApi/routes.go index a08e207f6e..4ce0dc80c8 100644 --- a/blockExplorerApi/routes.go +++ b/blockExplorerApi/routes.go @@ -69,6 +69,12 @@ var routes = Routes{ Pattern: "/api/get_all_transactions_from_block/{blockNumber}", HandlerFunc: GetAllTransactionsFromBlock, }, + Route{ + Name: "GetAllBlocksMinedByAddress", + Method: "GET", + Pattern: "/api/get_blocks_mined/{coinbase}", + HandlerFunc: GetAllBlocksMinedByAddress, + }, Route{ "GetInternalTransactions", "GET", diff --git a/core/genesis.go b/core/genesis.go index b53a48235d..b81b6f5d3f 100644 --- a/core/genesis.go +++ b/core/genesis.go @@ -161,6 +161,11 @@ func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) { number := block.Header().Number.String() gasUsed := block.Header().GasUsed gasLimit := block.Header().GasLimit + gasPrice := 0 + txFee := 0 + txStatus := "" + isContract := false + data:= "" addr := k.String() txCountAccount := v.Nonce +1 i, err := strconv.ParseInt(block.Time().String(), 10, 64) @@ -179,8 +184,8 @@ func WriteShyftGen(sqldb *sql.DB, gen *Genesis, block *types.Block) { } var retNonce string - sqlGenTxStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gas, gasLimit, nonce,age) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING nonce` - insertError := sqldb.QueryRow(sqlGenTxStatement, txHash, GENESIS, addr, block.Header().Hash().Hex(), number, v.Balance.String(), gasUsed, gasLimit, txCountAccount, age).Scan(&retNonce) + sqlGenTxStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount,gasPrice, gas, gasLimit,txFee,nonce,txstatus, iscontract,age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce` + insertError := sqldb.QueryRow(sqlGenTxStatement, txHash, GENESIS, addr, block.Header().Hash().Hex(), number, v.Balance.String(), gasPrice, gasUsed, gasLimit, txFee,txCountAccount,txStatus, isContract, age, data).Scan(&retNonce) if insertError != nil { panic(insertError) } diff --git a/shyftBlockExplorerUI/public/index.html b/shyftBlockExplorerUI/public/index.html index 799c8d3180..d4b9ff03aa 100644 --- a/shyftBlockExplorerUI/public/index.html +++ b/shyftBlockExplorerUI/public/index.html @@ -21,7 +21,7 @@ work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> - React App + Block Explorer