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"
"time"
"github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/mclock"
"github.com/ShyftNetwork/go-empyrean/consensus"
@ -92,10 +91,10 @@ type BlockChain struct {
chainConfig *params.ChainConfig // Chain & network configuration
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
gcproc time.Duration // Accumulates canonical block processing for trie dumping
triegc *prque.Prque // Priority queue mapping block numbers to tries to gc
gcproc time.Duration // Accumulates canonical block processing for trie dumping
hc *HeaderChain
rmLogsFeed event.Feed

View file

@ -21,8 +21,8 @@ import (
"encoding/binary"
"encoding/json"
"errors"
"math/big"
"fmt"
"math/big"
"github.com/ShyftNetwork/go-empyrean/common"
"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.
func GetTransaction(db DatabaseReader, hash common.Hash) (*types.Transaction, common.Hash, uint64, uint64) {
// 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)
//fmt.Println(blockHash)
//fmt.Println(blockNumber)
if blockHash != (common.Hash{}) {
body := GetBody(db, blockHash, blockNumber)
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 {
for _, tx := range block.Transactions() {
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
@ -243,7 +237,7 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From)
switch {
case err == sql.ErrNoRows:
fmt.Println("wtf", s.From)
fmt.Println("Need to write From", s.From)
}
if err != nil {
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
// executes the given message in the provided environment. The return value will
// be tracer dependent.
@ -646,7 +644,7 @@ 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
timeout := defaultTraceTimeout
if config.Timeout != nil {
if timeout, err = time.ParseDuration(*config.Timeout); err != nil {

View file

@ -1,15 +1,16 @@
package eth
import (
"context"
"fmt"
"github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/params"
"context"
)
var EthereumObject interface{}
type ShyftTracer struct {}
type ShyftTracer struct{}
var PrivateAPI *PrivateDebugAPI
var Context context.Context
@ -23,21 +24,22 @@ func InitTracerEnv() {
Context = ctx2
config := &TraceConfig{
LogConfig: nil,
Tracer: &jsTracer, // needs to be non-nil
Timeout: nil,
Reexec: nil,
Tracer: &jsTracer, // needs to be non-nil
Timeout: nil,
Reexec: nil,
}
TracerConfig = config
fullNode, _ := SNew(Global_config)
fmt.Println("FULL NODE", fullNode)
privateAPI := NewPrivateDebugAPI(config2, fullNode)
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)
}
func setEthObject(ethobj interface{}){
func setEthObject(ethobj interface{}) {
EthereumObject = ethobj
}

View file

@ -25,6 +25,8 @@ import (
"time"
"unsafe"
"strconv"
"github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
"github.com/ShyftNetwork/go-empyrean/core"
@ -32,7 +34,6 @@ import (
"github.com/ShyftNetwork/go-empyrean/crypto"
"github.com/ShyftNetwork/go-empyrean/log"
"gopkg.in/olebedev/go-duktape.v3"
"strconv"
)
// 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)
iTx := core.InteralWrite{
Hash: hash.Hex(),
Type: i.Type,
From: i.From,
To: i.To,
Value: amount,
Gas: gas,
GasUsed: gasUsed,
Input: i.Input,
Output: i.Output,
Time: i.Time,
Hash: hash.Hex(),
Type: i.Type,
From: i.From,
To: i.To,
Value: amount,
Gas: gas,
GasUsed: gasUsed,
Input: i.Input,
Output: i.Output,
Time: i.Time,
}
//@TODO WRITE OVER TRANSACTION STRUCT
core.SWriteInternalTxBalances(sqldb, i.To, i.From, amount)
core.InsertInternalTx(sqldb, iTx)

View file

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