mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
fixed suggested changes
This commit is contained in:
parent
274ae75ad3
commit
1e38e2f577
8 changed files with 29 additions and 79 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -51,3 +51,4 @@ $HOME
|
|||
shyftData/*
|
||||
shyft-cli/web3/token_test/node_modules
|
||||
shyft-cli/web3/transfer-through-master/node_modules
|
||||
shyft-cli/web3/transfer-through-master/build
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ import (
|
|||
"github.com/ethereum/go-ethereum/node"
|
||||
)
|
||||
|
||||
const (
|
||||
testInstance = "console-tester"
|
||||
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
const (
|
||||
testInstance = "console-tester"
|
||||
testAddress = "0x8605cdbbdb6d264aa742e77020dcbc58fcdce182"
|
||||
)
|
||||
|
||||
// hookedPrompter implements UserPrompter to simulate use input via channels.
|
||||
|
|
|
|||
|
|
@ -266,9 +266,6 @@ func GetBlockReceipts(db DatabaseReader, hash common.Hash, number uint64) types.
|
|||
// hash to allow retrieving the transaction or receipt by hash.
|
||||
func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64, uint64) {
|
||||
// Load the positional metadata from disk and bail if it fails
|
||||
//fmt.Println("INSIDE GetTxLookupEntry ")
|
||||
//fmt.Println("the db is ")
|
||||
//fmt.Println(db)
|
||||
data, _ := db.Get(append(lookupPrefix, hash.Bytes()...))
|
||||
if len(data) == 0 {
|
||||
return common.Hash{}, 0, 0
|
||||
|
|
|
|||
13
core/db.go
13
core/db.go
|
|
@ -7,12 +7,16 @@ import (
|
|||
|
||||
var blockExplorerDb *sql.DB
|
||||
|
||||
const (
|
||||
connStr = "user=postgres dbname=shyftdb sslmode=disable"
|
||||
connStrTest = "user=postgres dbname=shyftdbtest sslmode=disable"
|
||||
)
|
||||
|
||||
func InitDB() (*sql.DB, error){
|
||||
var connStr = "user=postgres dbname=shyftdb sslmode=disable"
|
||||
db, err := sql.Open("postgres", connStr)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR OPENING DB, NOT INITIALIZING")
|
||||
fmt.Println(err)
|
||||
panic(err)
|
||||
return nil, err
|
||||
} else {
|
||||
blockExplorerDb = db
|
||||
|
|
@ -21,11 +25,10 @@ func InitDB() (*sql.DB, error){
|
|||
}
|
||||
|
||||
func InitDBTest() (*sql.DB, error){
|
||||
var connStr = "user=postgres dbname=shyftdbtest sslmode=disable"
|
||||
db, err := sql.Open("postgres", connStr)
|
||||
db, err := sql.Open("postgres", connStrTest)
|
||||
if err != nil {
|
||||
fmt.Println("ERROR OPENING DB, NOT INITIALIZING")
|
||||
fmt.Println(err)
|
||||
panic(err)
|
||||
return nil, err
|
||||
} else {
|
||||
blockExplorerDb = db
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
|||
panic(err)
|
||||
}
|
||||
|
||||
rewards := writeMinerRewards(sqldb,block)
|
||||
rewards := swriteMinerRewards(sqldb,block)
|
||||
coinbase := block.Header().Coinbase.String()
|
||||
number := block.Header().Number.String()
|
||||
gasUsed := block.Header().GasUsed
|
||||
|
|
@ -147,10 +147,10 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
|||
for _, tx := range block.Transactions() {
|
||||
SwriteTransactions(sqldb, tx, block.Header().Hash(), block.Header().Number.String(), receipts, age, gasLimit)
|
||||
if block.Transactions()[0].To() != nil {
|
||||
writeFromBalance(sqldb, tx)
|
||||
swriteFromBalance(sqldb, tx)
|
||||
}
|
||||
if block.Transactions()[0].To() == nil {
|
||||
writeContractBalance(sqldb, tx)
|
||||
swriteContractBalance(sqldb, tx)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -232,7 +232,7 @@ func SwriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
|
|||
return nil
|
||||
}
|
||||
|
||||
func writeContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||
func swriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||
sendAndReceiveData := SendAndReceive{
|
||||
From: tx.From().Hex(),
|
||||
Amount: tx.Value().String(),
|
||||
|
|
@ -284,7 +284,7 @@ func writeContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func writeContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string) {
|
||||
func swriteContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string) {
|
||||
sendAndReceiveData := SendAndReceive{
|
||||
From: tx.From().Hex(),
|
||||
Amount: tx.Value().String(),
|
||||
|
|
@ -304,8 +304,8 @@ func writeContractBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndRe
|
|||
}
|
||||
|
||||
//writeFromBalance writes senders balance to accounts db
|
||||
func writeFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||
sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := writeBalanceHelper(sqldb, tx)
|
||||
func swriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||
sendAndReceiveData, balanceRec, balanceSen, accountNonceRec, accountNonceSen := swriteBalanceHelper(sqldb, tx)
|
||||
toAddr := sendAndReceiveData.To
|
||||
fromAddr := sendAndReceiveData.From
|
||||
amount := sendAndReceiveData.Amount
|
||||
|
|
@ -377,7 +377,7 @@ func writeFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func writeBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string, string, string) {
|
||||
func swriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, string, string, string, string) {
|
||||
sendAndReceiveData := SendAndReceive{
|
||||
To: tx.To().Hex(),
|
||||
From: tx.From().Hex(),
|
||||
|
|
@ -412,7 +412,7 @@ func writeBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s
|
|||
// uncle blocks, account balance updates based on reorgs, diverges that get dropped.
|
||||
// Reason for this is because the accounts are not deterministic like the block and tx hashes.
|
||||
// @TODO: Calculate reorg
|
||||
func writeMinerRewards(sqldb *sql.DB, block *types.Block) string {
|
||||
func swriteMinerRewards(sqldb *sql.DB, block *types.Block) string {
|
||||
minerAddr := block.Coinbase().String()
|
||||
shyftConduitAddress := Rewards.ShyftNetworkConduitAddress.String()
|
||||
// Calculate the total gas used in the block
|
||||
|
|
@ -442,13 +442,13 @@ func writeMinerRewards(sqldb *sql.DB, block *types.Block) string {
|
|||
uncleAddrs = append(uncleAddrs, uncle.Coinbase.String())
|
||||
}
|
||||
|
||||
storeReward(sqldb, minerAddr, totalMinerReward)
|
||||
storeReward(sqldb, shyftConduitAddress, Rewards.ShyftNetworkBlockReward)
|
||||
sstoreReward(sqldb, minerAddr, totalMinerReward)
|
||||
sstoreReward(sqldb, shyftConduitAddress, Rewards.ShyftNetworkBlockReward)
|
||||
var uncRewards = new(big.Int)
|
||||
for i := 0; i < len(uncleAddrs); i++ {
|
||||
uncRewards := uncleRewards[i]
|
||||
fmt.Println(uncRewards)
|
||||
storeReward(sqldb, uncleAddrs[i], uncleRewards[i])
|
||||
sstoreReward(sqldb, uncleAddrs[i], uncleRewards[i])
|
||||
}
|
||||
|
||||
fullRewardValue := new(big.Int)
|
||||
|
|
@ -458,7 +458,7 @@ func writeMinerRewards(sqldb *sql.DB, block *types.Block) string {
|
|||
return fullRewardValue.String()
|
||||
}
|
||||
|
||||
func storeReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||
func sstoreReward(sqldb *sql.DB, address string, reward *big.Int) {
|
||||
// Check if address exists
|
||||
var addressBalance string
|
||||
addressExistsStatement := `SELECT balance from accounts WHERE addr = ($1)`
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@ func (api *PrivateDebugAPI) TraceChain(ctx context.Context, start, end rpc.Block
|
|||
// traceChain configures a new tracer according to the provided configuration, and
|
||||
// executes all the transactions contained within. The return value will be one item
|
||||
// per transaction, dependent on the requestd tracer.
|
||||
func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Block, config *TraceConfig) (*rpc.Subscription, error) {
|
||||
func (api *PrivateDebugAPI) traceChain(ctx context.Context, start, end *types.Block, config *TraceConfig) (*rpc.Subscription, error) {
|
||||
// Tracing a chain is a **long** operation, only do with subscriptions
|
||||
notifier, supported := rpc.NotifierFromContext(ctx)
|
||||
if !supported {
|
||||
|
|
@ -532,7 +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) {
|
||||
// NOTE:SHYFT
|
||||
tx, blockHash, _, index := core.GetTransaction(api.eth.ChainDb(), hash)
|
||||
if tx == nil {
|
||||
return nil, fmt.Errorf("transaction %x not found", hash)
|
||||
|
|
|
|||
|
|
@ -188,8 +188,6 @@ loop:
|
|||
arguments = make([]interface{}, 1)
|
||||
}
|
||||
arguments[0] = timer.call.ArgumentList[0]
|
||||
fmt.Println("The arguments are")
|
||||
fmt.Println(arguments)
|
||||
_, err := vm.Call(`Function.call.call`, nil, arguments...)
|
||||
if err != nil {
|
||||
fmt.Println("js error:", err, arguments)
|
||||
|
|
|
|||
|
|
@ -18,11 +18,6 @@ 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
|
||||
//}
|
||||
sqldb, err := core.DBConnection()
|
||||
getTxResponse := core.SGetTransaction(sqldb, txHash)
|
||||
|
||||
|
|
@ -39,11 +34,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -54,7 +44,6 @@ func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
|
|
@ -65,11 +54,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -89,11 +73,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -114,11 +93,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -139,11 +113,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -162,11 +131,6 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
|
|
@ -185,11 +149,7 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
getBlockResponse := core.SGetBlock(sqldb, blockNumber)
|
||||
|
||||
|
|
@ -206,11 +166,7 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
block3 := core.SGetAllBlocks(sqldb)
|
||||
if err != nil {
|
||||
|
|
@ -223,11 +179,7 @@ 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
|
||||
//}
|
||||
|
||||
sqldb, err := core.DBConnection()
|
||||
|
||||
mostRecentBlock := core.SGetRecentBlock(sqldb)
|
||||
|
|
|
|||
Loading…
Reference in a new issue