updating balances working correctly, test suite incomplete for accounts

This commit is contained in:
Dustin Brickwood 2018-08-07 16:48:08 -04:00
parent d760a7caa7
commit ba48ad13e9
7 changed files with 31 additions and 44 deletions

View file

@ -29,7 +29,6 @@ import (
"sync/atomic" "sync/atomic"
"time" "time"
"github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/mclock" "github.com/ShyftNetwork/go-empyrean/common/mclock"
"github.com/ShyftNetwork/go-empyrean/consensus" "github.com/ShyftNetwork/go-empyrean/consensus"
@ -92,10 +91,10 @@ type BlockChain struct {
chainConfig *params.ChainConfig // Chain & network configuration chainConfig *params.ChainConfig // Chain & network configuration
cacheConfig *CacheConfig // Cache configuration for pruning cacheConfig *CacheConfig // Cache configuration for pruning
db ethdb.Database // Low level persistent database to store final content in db ethdb.Database // Low level persistent database to store final content in
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping gcproc time.Duration // Accumulates canonical block processing for trie dumping
hc *HeaderChain hc *HeaderChain
rmLogsFeed event.Feed rmLogsFeed event.Feed

View file

@ -21,8 +21,8 @@ import (
"encoding/binary" "encoding/binary"
"encoding/json" "encoding/json"
"errors" "errors"
"math/big"
"fmt" "fmt"
"math/big"
"github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/core/types" "github.com/ShyftNetwork/go-empyrean/core/types"
@ -283,14 +283,7 @@ func GetTxLookupEntry(db DatabaseReader, hash common.Hash) (common.Hash, uint64,
// its added positional metadata. // its added positional metadata.
func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) { func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) {
// Retrieve the lookup metadata and resolve the transaction from the body // Retrieve the lookup metadata and resolve the transaction from the body
//fmt.Println("INSIDE GET TRANSACTION ++++++++")
//fmt.Println("The hash and db reader are")
//fmt.Println(hash)
//fmt.Println(db)
blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash) blockHash, blockNumber, txIndex := GetTxLookupEntry(db, hash)
//fmt.Println(blockHash)
//fmt.Println(blockNumber)
if blockHash != (common.Hash{}) { if blockHash != (common.Hash{}) {
body := GetBody(db, blockHash, blockNumber) body := GetBody(db, blockHash, blockNumber)
if body == nil || len(body.Transactions) <= int(txIndex) { if body == nil || len(body.Transactions) <= int(txIndex) {

View file

@ -146,12 +146,6 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
if block.Transactions().Len() > 0 { if block.Transactions().Len() > 0 {
for _, tx := range block.Transactions() { for _, tx := range block.Transactions() {
swriteTransactions(sqldb, tx, block.Header().Hash(), blockData.Number, receipts, age, blockData.GasLimit) swriteTransactions(sqldb, tx, block.Header().Hash(), blockData.Number, receipts, age, blockData.GasLimit)
// if block.Transactions()[0].To() != nil {
// swriteBalance(sqldb, tx)
// }
// if block.Transactions()[0].To() == nil {
// swriteContractBalance(sqldb, tx)
// }
} }
} }
return nil return nil
@ -243,7 +237,7 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From) fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From)
switch { switch {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
fmt.Println("wtf", s.From) fmt.Println("Need to write From", s.From)
} }
if err != nil { if err != nil {
log.Fatal(err) log.Fatal(err)

View file

@ -631,8 +631,6 @@ func (api *PrivateDebugAPI) StraceTx(ctx context.Context, message core.Message,
} }
} }
// traceTx configures a new tracer according to the provided configuration, and // traceTx configures a new tracer according to the provided configuration, and
// executes the given message in the provided environment. The return value will // executes the given message in the provided environment. The return value will
// be tracer dependent. // be tracer dependent.
@ -646,7 +644,7 @@ func (api *PrivateDebugAPI) traceTx(ctx context.Context, message core.Message, v
case config != nil && config.Tracer != nil: case config != nil && config.Tracer != nil:
// Define a meaningful timeout of a single transaction trace // Define a meaningful timeout of a single transaction trace
timeout := defaultTraceTimeout timeout := defaultTraceTimeout
if config.Timeout != nil { if config.Timeout != nil {
if timeout, err = time.ParseDuration(*config.Timeout); err != nil { if timeout, err = time.ParseDuration(*config.Timeout); err != nil {

View file

@ -1,15 +1,16 @@
package eth package eth
import ( import (
"context"
"fmt"
"github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/params" "github.com/ShyftNetwork/go-empyrean/params"
"context"
) )
var EthereumObject interface{} var EthereumObject interface{}
type ShyftTracer struct {} type ShyftTracer struct{}
var PrivateAPI *PrivateDebugAPI var PrivateAPI *PrivateDebugAPI
var Context context.Context var Context context.Context
@ -23,21 +24,22 @@ func InitTracerEnv() {
Context = ctx2 Context = ctx2
config := &TraceConfig{ config := &TraceConfig{
LogConfig: nil, LogConfig: nil,
Tracer: &jsTracer, // needs to be non-nil Tracer: &jsTracer, // needs to be non-nil
Timeout: nil, Timeout: nil,
Reexec: nil, Reexec: nil,
} }
TracerConfig = config TracerConfig = config
fullNode, _ := SNew(Global_config) fullNode, _ := SNew(Global_config)
fmt.Println("FULL NODE", fullNode)
privateAPI := NewPrivateDebugAPI(config2, fullNode) privateAPI := NewPrivateDebugAPI(config2, fullNode)
PrivateAPI = privateAPI PrivateAPI = privateAPI
} }
func (st ShyftTracer) GetTracerToRun (hash common.Hash) (interface{}, error) { func (st ShyftTracer) GetTracerToRun(hash common.Hash) (interface{}, error) {
return PrivateAPI.STraceTransaction(Context, hash, TracerConfig) return PrivateAPI.STraceTransaction(Context, hash, TracerConfig)
} }
func setEthObject(ethobj interface{}){ func setEthObject(ethobj interface{}) {
EthereumObject = ethobj EthereumObject = ethobj
} }
@ -45,4 +47,4 @@ var Global_config *Config
func SetGlobalConfig(c *Config) { func SetGlobalConfig(c *Config) {
Global_config = c Global_config = c
} }

View file

@ -25,6 +25,8 @@ import (
"time" "time"
"unsafe" "unsafe"
"strconv"
"github.com/ShyftNetwork/go-empyrean/common" "github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/hexutil" "github.com/ShyftNetwork/go-empyrean/common/hexutil"
"github.com/ShyftNetwork/go-empyrean/core" "github.com/ShyftNetwork/go-empyrean/core"
@ -32,7 +34,6 @@ import (
"github.com/ShyftNetwork/go-empyrean/crypto" "github.com/ShyftNetwork/go-empyrean/crypto"
"github.com/ShyftNetwork/go-empyrean/log" "github.com/ShyftNetwork/go-empyrean/log"
"gopkg.in/olebedev/go-duktape.v3" "gopkg.in/olebedev/go-duktape.v3"
"strconv"
) )
// bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js. // bigIntegerJS is the minified version of https://github.com/peterolson/BigInteger.js.
@ -604,18 +605,17 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) {
amount := strconv.FormatUint(value, 10) amount := strconv.FormatUint(value, 10)
iTx := core.InteralWrite{ iTx := core.InteralWrite{
Hash: hash.Hex(), Hash: hash.Hex(),
Type: i.Type, Type: i.Type,
From: i.From, From: i.From,
To: i.To, To: i.To,
Value: amount, Value: amount,
Gas: gas, Gas: gas,
GasUsed: gasUsed, GasUsed: gasUsed,
Input: i.Input, Input: i.Input,
Output: i.Output, Output: i.Output,
Time: i.Time, Time: i.Time,
} }
//@TODO WRITE OVER TRANSACTION STRUCT //@TODO WRITE OVER TRANSACTION STRUCT
core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount) core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount)
core.InsertInternalTx(sqldb, iTx) core.InsertInternalTx(sqldb, iTx)

View file

@ -2,6 +2,7 @@ package shyftdb
import ( import (
"encoding/json" "encoding/json"
"fmt"
"math/big" "math/big"
"strconv" "strconv"
"strings" "strings"
@ -318,13 +319,13 @@ func TestBlock(t *testing.T) {
t.Fatalf("isContract [%v]: isContract bool is incorrect", isContract) t.Fatalf("isContract [%v]: isContract bool is incorrect", isContract)
} }
} }
if getAllTx := core.SGetAllTransactions(sqldb); len(getAllTx) == 0 { if getAllTx := core.SGetAllTransactions(sqldb); len(getAllTx) == 0 {
t.Fatalf("GetAllTransactions [%v]: GetAllTransactions did not return correctly", getAllTx) t.Fatalf("GetAllTransactions [%v]: GetAllTransactions did not return correctly", getAllTx)
} }
}) })
t.Run("TestAccountsToReturnAccounts", func(t *testing.T) { t.Run("TestAccountsToReturnAccounts", func(t *testing.T) {
for _, tx := range txs { for _, tx := range txs {
fmt.Println("test account", tx.To().String())
accountAddrTo := core.SGetAccount(sqldb, tx.To().String()) accountAddrTo := core.SGetAccount(sqldb, tx.To().String())
byts := []byte(accountAddrTo) byts := []byte(accountAddrTo)
var accountDataTo core.SAccounts var accountDataTo core.SAccounts