From 5f46c2d4a872a9da4a2068e18c8652d056515a3e Mon Sep 17 00:00:00 2001 From: greg Date: Mon, 16 Apr 2018 16:08:08 -0400 Subject: [PATCH] Tx getters return values --- cmd/geth/chaincmd.go | 1 - cmd/geth/config.go | 1 - cmd/geth/main.go | 1 - cmd/utils/flags.go | 2 - core/blockchain.go | 1 - eth/backend.go | 2 - shyftdb/shyft_database_util.go | 87 ++++++++++++++++++++++++---------- 7 files changed, 63 insertions(+), 32 deletions(-) diff --git a/cmd/geth/chaincmd.go b/cmd/geth/chaincmd.go index 8c8d7e70bc..9b7914190c 100644 --- a/cmd/geth/chaincmd.go +++ b/cmd/geth/chaincmd.go @@ -146,7 +146,6 @@ Use "ethereum dump 0" to dump the genesis block.`, // initGenesis will initialise the given JSON format genesis file and writes it as // the zero'd block (i.e. genesis) or will fail hard if it can't succeed. func initGenesis(ctx *cli.Context) error { - fmt.Println("GENESIS+++++++++++++++++++++++") // Make sure we have a valid genesis JSON genesisPath := ctx.Args().First() if len(genesisPath) == 0 { diff --git a/cmd/geth/config.go b/cmd/geth/config.go index f3c3591bbe..fd86949f7c 100644 --- a/cmd/geth/config.go +++ b/cmd/geth/config.go @@ -152,7 +152,6 @@ func enableWhisper(ctx *cli.Context) bool { } func makeFullNode(ctx *cli.Context) *node.Node { - fmt.Println("+++++++++++++++++cmd/geth/config.GO+++++++++++++++++++++++++MakeFullNode()") stack, cfg := makeConfigNode(ctx) utils.RegisterEthService(stack, &cfg.Eth) diff --git a/cmd/geth/main.go b/cmd/geth/main.go index 00afce3308..f5a3fa941a 100644 --- a/cmd/geth/main.go +++ b/cmd/geth/main.go @@ -214,7 +214,6 @@ func main() { // It creates a default node based on the command line arguments and runs it in // blocking mode, waiting for it to be shut down. func geth(ctx *cli.Context) error { - fmt.Println("+++++++++++++++++cmd/main/geth.GO+++++++++++++++++++++++++Geth()") node := makeFullNode(ctx) startNode(ctx, node) node.Wait() diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go index 64599ff0c7..9f5b2bc033 100644 --- a/cmd/utils/flags.go +++ b/cmd/utils/flags.go @@ -1124,7 +1124,6 @@ func SetDashboardConfig(ctx *cli.Context, cfg *dashboard.Config) { // RegisterEthService adds an Ethereum client to the stack. func RegisterEthService(stack *node.Node, cfg *eth.Config) { - fmt.Println("+++++++++++++++++cmd/utils/Flags.GO+++++++++++++++++++++++++RegisterEthService()") var err error if cfg.SyncMode == downloader.LightSync { err = stack.Register(func(ctx *node.ServiceContext) (node.Service, error) { @@ -1216,7 +1215,6 @@ func MakeGenesis(ctx *cli.Context) *core.Genesis { // MakeChain creates a chain manager from set command line flags. func MakeChain(ctx *cli.Context, stack *node.Node) (chain *core.BlockChain, chainDb ethdb.Database) { - fmt.Println("+++++++++++++++++cmd/flags.GO+++++++++++++++++++++++++MakeChain()") var err error chainDb = MakeChainDatabase(ctx, stack) diff --git a/core/blockchain.go b/core/blockchain.go index 2f94166fec..411b4a7438 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -141,7 +141,6 @@ type BlockChain struct { // available in the database. It initialises the default Ethereum Validator and // Processor. func NewBlockChain(db ethdb.Database, blockExplorerDb *leveldb.DB, cacheConfig *CacheConfig, chainConfig *params.ChainConfig, engine consensus.Engine, vmConfig vm.Config) (*BlockChain, error) { - fmt.Printf("+++++++++++++++++core/blockchain.GO+++++++++++++++++++++++++NewBlockChain()") if cacheConfig == nil { cacheConfig = &CacheConfig{ TrieNodeLimit: 256 * 1024 * 1024, diff --git a/eth/backend.go b/eth/backend.go index f0f77dcb7c..b5c99965c7 100644 --- a/eth/backend.go +++ b/eth/backend.go @@ -104,7 +104,6 @@ func (s *Ethereum) AddLesServer(ls LesServer) { // initialisation of the common Ethereum object) func New(ctx *node.ServiceContext, config *Config) (*Ethereum, error) { // @NOTE:shyft Where we instantiate BlockExplorerDB - fmt.Println("+++++++++++++++++eth/backend.GO+++++++++++++++++++++++++New()") if config.SyncMode == downloader.LightSync { return nil, errors.New("can't run eth.Ethereum in light sync mode, use les.LightEthereum") } @@ -210,7 +209,6 @@ func makeExtraData(extra []byte) []byte { // CreateDB creates the chain database. func CreateDB(ctx *node.ServiceContext, config *Config, name string) (ethdb.Database, error) { - fmt.Println("+++++++++++++++++eth/backend.GO+++++++++++++++++++++++++CreateDB()") db, err := ctx.OpenDatabase(name, config.DatabaseCache, config.DatabaseHandles) if err != nil { return nil, err diff --git a/shyftdb/shyft_database_util.go b/shyftdb/shyft_database_util.go index dfbf5c7e84..78bd44bd1f 100644 --- a/shyftdb/shyft_database_util.go +++ b/shyftdb/shyft_database_util.go @@ -31,6 +31,18 @@ type ShyftTxEntry struct { Data []byte } +type ShyftTxEntryPretty struct { + TxHash string + To string + From string + BlockHash string + Amount *big.Int + GasPrice *big.Int + Gas uint64 + Nonce uint64 + Data []byte +} + func WriteBlock(db *leveldb.DB, block *types.Block) error { leng := block.Transactions().Len() var tx_strs = make([]string, leng) @@ -80,8 +92,6 @@ func WriteTransactions(db *leveldb.DB, tx *types.Transaction, blockHash common.H if err := db.Put(key, encodedData.Bytes(), nil); err != nil { log.Crit("Failed to store TX", "err", err) } - GetTransaction(db, tx) - GetAllTransactions(db) return tx.Hash().String() } @@ -119,7 +129,8 @@ func GetBlock(db *leveldb.DB, block *types.Block) []byte { return data } -func GetAllTransactions(db *leveldb.DB) { +func GetAllTransactions(db *leveldb.DB) []ShyftTxEntryPretty { + var txs []ShyftTxEntryPretty iter := db.NewIterator(util.BytesPrefix([]byte("tx-")), nil) for iter.Next() { var txData ShyftTxEntry @@ -127,21 +138,36 @@ func GetAllTransactions(db *leveldb.DB) { if err := d.Decode(&txData); err != nil { log.Crit("Failed to decode tx:", "err", err) } - fmt.Println("DECODED TX") - fmt.Println("Tx Hash: ", txData.TxHash.Hex()) - fmt.Println("From: ", txData.From.Hex()) - fmt.Println("To: ", txData.To.Hex()) - fmt.Println("BlockHash: ", txData.BlockHash.Hex()) - fmt.Println("Amount: ", txData.Amount) - fmt.Println("Gas: ", txData.Gas) - fmt.Println("GasPrice: ", txData.GasPrice) - fmt.Println("Nonce: ", txData.Nonce) - fmt.Println("Data: ", txData.Data) + prettyFormat := ShyftTxEntryPretty{ + TxHash: txData.TxHash.Hex(), + From: txData.From.Hex(), + To: txData.To.Hex(), + BlockHash: txData.BlockHash.Hex(), + Amount: txData.Amount, + Gas: txData.Gas, + GasPrice: txData.GasPrice, + Nonce: txData.Nonce, + Data: txData.Data, + } + txs = append(txs, prettyFormat) + // Uncomment to view "pretty" version of data + //fmt.Println("DECODED TX") + //fmt.Println("Tx Hash: ", txData.TxHash.Hex()) + //fmt.Println("From: ", txData.From.Hex()) + //fmt.Println("To: ", txData.To.Hex()) + //fmt.Println("BlockHash: ", txData.BlockHash.Hex()) + //fmt.Println("Amount: ", txData.Amount) + //fmt.Println("Gas: ", txData.Gas) + //fmt.Println("GasPrice: ", txData.GasPrice) + //fmt.Println("Nonce: ", txData.Nonce) + //fmt.Println("Data: ", txData.Data) } iter.Release() + return txs } -func GetTransaction (db *leveldb.DB, tx *types.Transaction) { +func GetTransaction (db *leveldb.DB, tx *types.Transaction) ShyftTxEntryPretty { + var prettyFormat ShyftTxEntryPretty key := append([]byte("tx-")[:], tx.Hash().Bytes()[:]...) data, err := db.Get(key, nil) if err != nil { @@ -153,15 +179,28 @@ func GetTransaction (db *leveldb.DB, tx *types.Transaction) { if err := d.Decode(&txData); err != nil { log.Crit("Failed to decode tx:", "err", err) } - fmt.Println("DECODED TX") - fmt.Println("Tx Hash: ", txData.TxHash.Hex()) - fmt.Println("From: ", txData.From.Hex()) - fmt.Println("To: ", txData.To.Hex()) - fmt.Println("BlockHash: ", txData.BlockHash.Hex()) - fmt.Println("Amount: ", txData.Amount) - fmt.Println("Gas: ", txData.Gas) - fmt.Println("GasPrice: ", txData.GasPrice) - fmt.Println("Nonce: ", txData.Nonce) - fmt.Println("Data: ", txData.Data) + prettyFormat = ShyftTxEntryPretty{ + TxHash: txData.TxHash.Hex(), + From: txData.From.Hex(), + To: txData.To.Hex(), + BlockHash: txData.BlockHash.Hex(), + Amount: txData.Amount, + Gas: txData.Gas, + GasPrice: txData.GasPrice, + Nonce: txData.Nonce, + Data: txData.Data, + } + // Uncomment to view "pretty" version of data + //fmt.Println("DECODED TX") + //fmt.Println("Tx Hash: ", txData.TxHash.Hex()) + //fmt.Println("From: ", txData.From.Hex()) + //fmt.Println("To: ", txData.To.Hex()) + //fmt.Println("BlockHash: ", txData.BlockHash.Hex()) + //fmt.Println("Amount: ", txData.Amount) + //fmt.Println("Gas: ", txData.Gas) + //fmt.Println("GasPrice: ", txData.GasPrice) + //fmt.Println("Nonce: ", txData.Nonce) + //fmt.Println("Data: ", txData.Data) } + return prettyFormat } \ No newline at end of file