removed fmt prints, created types file and fixed UI

This commit is contained in:
Dustin Brickwood 2018-08-08 17:43:56 -04:00
parent ba48ad13e9
commit a37f60d6a3
15 changed files with 370 additions and 260 deletions

View file

@ -18,16 +18,20 @@ package core
import (
"bytes"
"database/sql"
"encoding/hex"
"encoding/json"
"errors"
"fmt"
"math/big"
"strconv"
"strings"
"database/sql"
"time"
"github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
"github.com/ShyftNetwork/go-empyrean/common/math"
stypes "github.com/ShyftNetwork/go-empyrean/core/sTypes"
"github.com/ShyftNetwork/go-empyrean/core/state"
"github.com/ShyftNetwork/go-empyrean/core/types"
"github.com/ShyftNetwork/go-empyrean/ethdb"
@ -35,8 +39,6 @@ import (
"github.com/ShyftNetwork/go-empyrean/params"
"github.com/ShyftNetwork/go-empyrean/rlp"
_ "github.com/lib/pq"
"strconv"
"time"
)
//go:generate gencodec -type Genesis -field-override genesisSpecMarshaling -out gen_genesis.go
@ -157,7 +159,7 @@ func WriteShyftGen(gen *Genesis, block *types.Block) {
//Appending GENESIS to address stored as txHash and From Addr
Genesis := []string{"GENESIS_", k.String()}
GENESIS := "GENESIS"
txHash := strings.Join(Genesis, k.String())
txHash := strings.Join(Genesis, k.String())
//Create the accountNonce, set to 1 (1 incoming tx), format type
accountNonce := v.Nonce + 1
accountNoncee := strconv.FormatUint(accountNonce, 10)
@ -168,22 +170,22 @@ func WriteShyftGen(gen *Genesis, block *types.Block) {
}
age := time.Unix(i, 0)
txData := ShyftTxEntryPretty {
TxHash: txHash,
From: GENESIS,
To: toAddr,
BlockHash: block.Header().Hash().Hex(),
BlockNumber:block.Header().Number.String(),
Amount: v.Balance.String(),
Cost: cost,
GasPrice: gasPrice,
GasLimit: block.GasLimit(),
Gas: block.GasUsed(),
Nonce: accountNonce,
Age: age,
Data: data,
Status: "SUCCESS",
IsContract: false,
txData := stypes.ShyftTxEntryPretty{
TxHash: txHash,
From: GENESIS,
To: toAddr,
BlockHash: block.Header().Hash().Hex(),
BlockNumber: block.Header().Number.String(),
Amount: v.Balance.String(),
Cost: cost,
GasPrice: gasPrice,
GasLimit: block.GasLimit(),
Gas: block.GasUsed(),
Nonce: accountNonce,
Age: age,
Data: data,
Status: "SUCCESS",
IsContract: false,
}
//Create account and store tx
CreateAccount(sqldb, k.String(), v.Balance.String(), accountNoncee)
@ -191,9 +193,11 @@ func WriteShyftGen(gen *Genesis, block *types.Block) {
default:
log.Info("Found Genesis Block")
}}
}
}
}
//WriteShyftBlockZero writes block 0 to postgres db
func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
sqldb, _ := DBConnection()
@ -203,21 +207,21 @@ func WriteShyftBlockZero(block *types.Block, gen *Genesis) error {
}
age := time.Unix(i, 0)
blockData := SBlock{
Hash: block.Header().Hash().Hex(),
Coinbase: block.Header().Coinbase.String(),
Number: block.Header().Number.String(),
GasUsed: block.Header().GasUsed,
GasLimit: block.Header().GasLimit,
TxCount: len(gen.Alloc),
UncleCount: len(block.Uncles()),
Age: age,
ParentHash: block.ParentHash().String(),
UncleHash: block.UncleHash().String(),
Difficulty: block.Difficulty().String(),
Size: block.Size().String(),
Nonce: block.Nonce(),
Rewards: "0",
blockData := stypes.SBlock{
Hash: block.Header().Hash().Hex(),
Coinbase: block.Header().Coinbase.String(),
Number: block.Header().Number.String(),
GasUsed: block.Header().GasUsed,
GasLimit: block.Header().GasLimit,
TxCount: len(gen.Alloc),
UncleCount: len(block.Uncles()),
Age: age,
ParentHash: block.ParentHash().String(),
UncleHash: block.UncleHash().String(),
Difficulty: block.Difficulty().String(),
Size: block.Size().String(),
Nonce: block.Nonce(),
Rewards: "0",
}
err := BlockExists(sqldb, blockData.Hash)

92
core/sTypes/stypes.go Normal file
View file

@ -0,0 +1,92 @@
package stypes
import (
"time"
"github.com/ShyftNetwork/go-empyrean/common"
)
//SBlock type
type SBlock struct {
Hash string
Coinbase string
AgeGet string
Age time.Time
ParentHash string
UncleHash string
Difficulty string
Size string
Rewards string
Number string
GasUsed uint64
GasLimit uint64
Nonce uint64
TxCount int
UncleCount int
Blocks []SBlock
}
type InteralWrite struct {
Hash string
Type string
From string
To string
Value string
Gas uint64
GasUsed uint64
Input string
Output string
Time string
}
//blockRes struct
type BlockRes struct {
hash string
coinbase string
number string
Blocks []SBlock
}
type SAccounts struct {
Addr string
Balance string
AccountNonce string
}
type AccountRes struct {
addr string
balance string
AllAccounts []SAccounts
}
type TxRes struct {
TxEntry []ShyftTxEntryPretty
}
type ShyftTxEntryPretty struct {
TxHash string
To *common.Address
ToGet string
From string
BlockHash string
BlockNumber string
Amount string
GasPrice uint64
Gas uint64
GasLimit uint64
Cost uint64
Nonce uint64
Status string
IsContract bool
Age time.Time
Data []byte
}
type SendAndReceive struct {
To string
From string
Amount string
Address string
Balance string
AccountNonce uint64 `json:",string"`
}

View file

@ -11,103 +11,106 @@ import (
"github.com/ShyftNetwork/go-empyrean/common"
Rewards "github.com/ShyftNetwork/go-empyrean/consensus/ethash"
stypes "github.com/ShyftNetwork/go-empyrean/core/sTypes"
"github.com/ShyftNetwork/go-empyrean/core/types"
"github.com/ShyftNetwork/go-empyrean/shyfttracerinterface"
_ "github.com/lib/pq"
)
//IShyftTracer Used to initialize ShyftTracer
var IShyftTracer shyfttracerinterface.IShyftTracer
//SetIShyftTracer sets tracer type
func SetIShyftTracer(st shyfttracerinterface.IShyftTracer) {
IShyftTracer = st
}
//SBlock type
type SBlock struct {
Hash string
Coinbase string
AgeGet string
Age time.Time
ParentHash string
UncleHash string
Difficulty string
Size string
Rewards string
Number string
GasUsed uint64
GasLimit uint64
Nonce uint64
TxCount int
UncleCount int
Blocks []SBlock
}
// //SBlock type
// type SBlock struct {
// Hash string
// Coinbase string
// AgeGet string
// Age time.Time
// ParentHash string
// UncleHash string
// Difficulty string
// Size string
// Rewards string
// Number string
// GasUsed uint64
// GasLimit uint64
// Nonce uint64
// TxCount int
// UncleCount int
// Blocks []SBlock
// }
type InteralWrite struct {
Hash string
Type string
From string
To string
Value string
Gas uint64
GasUsed uint64
Input string
Output string
Time string
}
// type InteralWrite struct {
// Hash string
// Type string
// From string
// To string
// Value string
// Gas uint64
// GasUsed uint64
// Input string
// Output string
// Time string
// }
//blockRes struct
type blockRes struct {
hash string
coinbase string
number string
Blocks []SBlock
}
// //blockRes struct
// // type blockRes struct {
// // hash string
// // coinbase string
// // number string
// // Blocks []SBlock
// // }
type SAccounts struct {
Addr string
Balance string
AccountNonce string
}
// type SAccounts struct {
// Addr string
// Balance string
// AccountNonce string
// }
type accountRes struct {
addr string
balance string
AllAccounts []SAccounts
}
// type accountRes struct {
// addr string
// balance string
// AllAccounts []SAccounts
// }
type txRes struct {
TxEntry []ShyftTxEntryPretty
}
// type txRes struct {
// TxEntry []ShyftTxEntryPretty
// }
type ShyftTxEntryPretty struct {
TxHash string
To *common.Address
ToGet string
From string
BlockHash string
BlockNumber string
Amount string
GasPrice uint64
Gas uint64
GasLimit uint64
Cost uint64
Nonce uint64
Status string
IsContract bool
Age time.Time
Data []byte
}
// type ShyftTxEntryPretty struct {
// TxHash string
// To *common.Address
// ToGet string
// From string
// BlockHash string
// BlockNumber string
// Amount string
// GasPrice uint64
// Gas uint64
// GasLimit uint64
// Cost uint64
// Nonce uint64
// Status string
// IsContract bool
// Age time.Time
// Data []byte
// }
type SendAndReceive struct {
To string
From string
Amount string
Address string
Balance string
AccountNonce uint64 `json:",string"`
}
// type SendAndReceive struct {
// To string
// From string
// Amount string
// Address string
// Balance string
// AccountNonce uint64 `json:",string"`
// }
//WriteBlock writes to block info to sql db
//SWriteBlock writes to block info to sql db
func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
sqldb, err := DBConnection()
if err != nil {
@ -123,7 +126,7 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
}
age := time.Unix(i, 0)
blockData := SBlock{
blockData := stypes.SBlock{
Hash: block.Header().Hash().Hex(),
Coinbase: block.Header().Coinbase.String(),
Number: block.Header().Number.String(),
@ -185,7 +188,7 @@ func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
toAddr = tx.To()
}
txData := ShyftTxEntryPretty{
txData := stypes.ShyftTxEntryPretty{
TxHash: tx.Hash().Hex(),
From: tx.From().Hex(),
To: toAddr,
@ -212,7 +215,7 @@ func swriteTransactions(sqldb *sql.DB, tx *types.Transaction, blockHash common.H
//SWriteInternalTxBalances Writes internal txs and updates balances
func SWriteInternalTxBalances(sqldb *sql.DB, toAddr string, fromAddr string, amount string) error {
sendAndReceiveData := SendAndReceive{
sendAndReceiveData := stypes.SendAndReceive{
To: toAddr,
From: fromAddr,
Amount: amount,
@ -233,11 +236,12 @@ func SWriteInternalTxBalances(sqldb *sql.DB, toAddr string, fromAddr string, amo
return nil
}
func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
func adjustBalanceFromAddr(sqldb *sql.DB, s stypes.SendAndReceive, value *big.Int) {
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From)
switch {
case err == sql.ErrNoRows:
fmt.Println("Need to write From", s.From)
CreateAccount(sqldb, s.From, "0", "1")
fmt.Println("New From account created")
}
if err != nil {
log.Fatal(err)
@ -257,7 +261,7 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
UpdateAccount(sqldb, s.From, newBalanceSender.String(), newAccountNonceSender.String())
}
func balanceHelper(sqldb *sql.DB, s SendAndReceive, amount string) {
func balanceHelper(sqldb *sql.DB, s stypes.SendAndReceive, amount string) {
fromAddressBalance, fromAccountNonce, err := AccountExists(sqldb, s.From)
toAddressBalance, toAccountNonce, err := AccountExists(sqldb, s.To)
if err != nil {
@ -383,6 +387,8 @@ func sstoreReward(sqldb *sql.DB, address string, reward *big.Int) {
///////////////////////
//DB Utility functions
//////////////////////
//CreateAccount writes new account to Postgres Db
func CreateAccount(sqldb *sql.DB, addr string, balance string, accountNonce string) {
sqlStatement := `INSERT INTO accounts(addr, balance, accountNonce) VALUES(($1), ($2), ($3)) RETURNING addr`
insertErr := sqldb.QueryRow(sqlStatement, strings.ToLower(addr), balance, accountNonce).Scan(&addr)
@ -391,6 +397,7 @@ func CreateAccount(sqldb *sql.DB, addr string, balance string, accountNonce stri
}
}
//AccountExists checks if account exists in Postgres Db
func AccountExists(sqldb *sql.DB, addr string) (string, string, error) {
var addressBalance, accountNonce string
sqlExistsStatement := `SELECT balance, accountNonce from accounts WHERE addr = ($1)`
@ -405,6 +412,7 @@ func AccountExists(sqldb *sql.DB, addr string) (string, string, error) {
}
}
//BlockExists checks if block exists in Postgres Db
func BlockExists(sqldb *sql.DB, hash string) error {
var res string
sqlExistsStatement := `SELECT hash from blocks WHERE hash= ($1)`
@ -418,6 +426,7 @@ func BlockExists(sqldb *sql.DB, hash string) error {
}
}
//UpdateAccount updates account in Postgres Db
func UpdateAccount(sqldb *sql.DB, addr string, balance string, accountNonce string) {
updateSQLStatement := `UPDATE accounts SET balance = ($2), accountNonce = ($3) WHERE addr = ($1)`
_, updateErr := sqldb.Exec(updateSQLStatement, strings.ToLower(addr), balance, accountNonce)
@ -426,7 +435,8 @@ func UpdateAccount(sqldb *sql.DB, addr string, balance string, accountNonce stri
}
}
func InsertBlock(sqldb *sql.DB, blockData SBlock) {
//InsertBlock writes block to Postgres Db
func InsertBlock(sqldb *sql.DB, blockData stypes.SBlock) {
sqlStatement := `INSERT INTO blocks(hash, coinbase, number, gasUsed, gasLimit, txCount, uncleCount, age, parentHash, uncleHash, difficulty, size, rewards, nonce) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12),($13), ($14)) RETURNING number`
qerr := sqldb.QueryRow(sqlStatement, strings.ToLower(blockData.Hash), blockData.Coinbase, blockData.Number, blockData.GasUsed, blockData.GasLimit, blockData.TxCount, blockData.UncleCount, blockData.Age, blockData.ParentHash, blockData.UncleHash, blockData.Difficulty, blockData.Size, blockData.Rewards, blockData.Nonce).Scan(&blockData.Number)
if qerr != nil {
@ -434,7 +444,8 @@ func InsertBlock(sqldb *sql.DB, blockData SBlock) {
}
}
func InsertTx(sqldb *sql.DB, txData ShyftTxEntryPretty) {
//InsertTx writes tx to Postgres Db
func InsertTx(sqldb *sql.DB, txData stypes.ShyftTxEntryPretty) {
var retNonce string
sqlStatement := `INSERT INTO txs(txhash, from_addr, to_addr, blockhash, blockNumber, amount, gasprice, gas, gasLimit, txfee, nonce, isContract, txStatus, age, data) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10), ($11), ($12), ($13), ($14), ($15)) RETURNING nonce`
err := sqldb.QueryRow(sqlStatement, strings.ToLower(txData.TxHash), strings.ToLower(txData.From), strings.ToLower(txData.To.String()), strings.ToLower(txData.BlockHash), txData.BlockNumber, txData.Amount, txData.GasPrice, txData.Gas, txData.GasLimit, txData.Cost, txData.Nonce, txData.IsContract, txData.Status, txData.Age, txData.Data).Scan(&retNonce)
@ -443,7 +454,8 @@ func InsertTx(sqldb *sql.DB, txData ShyftTxEntryPretty) {
}
}
func InsertInternalTx(sqldb *sql.DB, i InteralWrite) {
//InsertInternalTx writes internal tx to Postgres Db
func InsertInternalTx(sqldb *sql.DB, i stypes.InteralWrite) {
var returnValue string
sqlStatement := `INSERT INTO internaltxs(type, txhash, from_addr, to_addr, amount, gas, gasUsed, time, input, output) VALUES(($1), ($2), ($3), ($4), ($5), ($6), ($7), ($8), ($9), ($10)) RETURNING txHash`
qerr := sqldb.QueryRow(sqlStatement, i.Type, strings.ToLower(i.Hash), strings.ToLower(i.From), strings.ToLower(i.To), i.Value, i.Gas, i.GasUsed, i.Time, i.Input, i.Output).Scan(&returnValue)

View file

@ -1,17 +1,19 @@
package core
import (
"encoding/json"
"database/sql"
"encoding/json"
"fmt"
"time"
stypes "github.com/ShyftNetwork/go-empyrean/core/sTypes"
)
///////////
// Getters
//////////
func SGetAllBlocks(sqldb *sql.DB) string {
var arr blockRes
var arr stypes.BlockRes
var blockArr string
rows, err := sqldb.Query(`SELECT * FROM blocks`)
if err != nil {
@ -25,23 +27,23 @@ func SGetAllBlocks(sqldb *sql.DB) string {
var txCount, uncleCount int
err = rows.Scan(
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num,)
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num)
arr.Blocks = append(arr.Blocks, SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
UncleCount: uncleCount,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
arr.Blocks = append(arr.Blocks, stypes.SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
UncleCount: uncleCount,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
})
blocks, _ := json.Marshal(arr.Blocks)
@ -61,23 +63,23 @@ func SGetBlock(sqldb *sql.DB, blockNumber string) string {
var txCount, uncleCount int
row.Scan(
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num,)
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num)
block := SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
block := stypes.SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
UncleCount: uncleCount,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
}
json, _ := json.Marshal(block)
return string(json)
@ -91,30 +93,30 @@ func SGetRecentBlock(sqldb *sql.DB) string {
var txCount, uncleCount int
row.Scan(
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num,)
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num)
block := SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
block := stypes.SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
UncleCount: uncleCount,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
}
json, _ := json.Marshal(block)
return string(json)
}
func SGetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
var arr txRes
var arr stypes.TxRes
var txx string
sqlStatement := `SELECT * FROM txs WHERE blocknumber=$1`
rows, err := sqldb.Query(sqlStatement, blockNumber)
@ -133,22 +135,22 @@ func SGetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
&txhash, &to_addr, &from_addr, &blockhash, &blocknumber, &amount, &gasprice, &gas, &gasLimit, &txfee, &nonce, &status, &isContract, &age, &data,
)
arr.TxEntry = append(arr.TxEntry, ShyftTxEntryPretty{
TxHash: txhash,
arr.TxEntry = append(arr.TxEntry, stypes.ShyftTxEntryPretty{
TxHash: txhash,
ToGet: to_addr,
From: from_addr,
BlockHash: blockhash,
From: from_addr,
BlockHash: blockhash,
BlockNumber: blocknumber,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
IsContract: isContract,
Age: age,
Data: data,
Age: age,
Data: data,
})
tx, _ := json.Marshal(arr.TxEntry)
@ -159,7 +161,7 @@ func SGetAllTransactionsFromBlock(sqldb *sql.DB, blockNumber string) string {
}
func SGetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string {
var arr blockRes
var arr stypes.BlockRes
var blockArr string
sqlStatement := `SELECT * FROM blocks WHERE coinbase=$1`
rows, err := sqldb.Query(sqlStatement, coinbase)
@ -174,23 +176,23 @@ func SGetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string {
var txCount, uncleCount int
err = rows.Scan(
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num,)
&hash, &coinbase, &gasUsed, &gasLimit, &txCount, &uncleCount, &age, &parentHash, &uncleHash, &difficulty, &size, &nonce, &rewards, &num)
arr.Blocks = append(arr.Blocks, SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
arr.Blocks = append(arr.Blocks, stypes.SBlock{
Hash: hash,
Coinbase: coinbase,
GasUsed: gasUsed,
GasLimit: gasLimit,
TxCount: txCount,
UncleCount: uncleCount,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
AgeGet: age,
ParentHash: parentHash,
UncleHash: uncleHash,
Difficulty: difficulty,
Size: size,
Nonce: nonce,
Rewards: rewards,
Number: num,
})
blocks, _ := json.Marshal(arr.Blocks)
@ -202,7 +204,7 @@ func SGetAllBlocksMinedByAddress(sqldb *sql.DB, coinbase string) string {
//GetAllTransactions getter fn for API
func SGetAllTransactions(sqldb *sql.DB) string {
var arr txRes
var arr stypes.TxRes
var txx string
rows, err := sqldb.Query(`SELECT * FROM txs`)
if err != nil {
@ -220,22 +222,22 @@ func SGetAllTransactions(sqldb *sql.DB) string {
&txhash, &to_addr, &from_addr, &blockhash, &blocknumber, &amount, &gasprice, &gas, &gasLimit, &txfee, &nonce, &status, &isContract, &age, &data,
)
arr.TxEntry = append(arr.TxEntry, ShyftTxEntryPretty{
TxHash: txhash,
arr.TxEntry = append(arr.TxEntry, stypes.ShyftTxEntryPretty{
TxHash: txhash,
ToGet: to_addr,
From: from_addr,
BlockHash: blockhash,
From: from_addr,
BlockHash: blockhash,
BlockNumber: blocknumber,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
IsContract: isContract,
Age: age,
Data: data,
Age: age,
Data: data,
})
tx, _ := json.Marshal(arr.TxEntry)
@ -258,39 +260,39 @@ func SGetTransaction(sqldb *sql.DB, txHash string) string {
row.Scan(
&txhash, &to_addr, &from_addr, &blockhash, &blocknumber, &amount, &gasprice, &gas, &gasLimit, &txfee, &nonce, &status, &isContract, &age, &data)
tx := ShyftTxEntryPretty{
tx := stypes.ShyftTxEntryPretty{
TxHash: txhash,
ToGet: to_addr,
From: from_addr,
BlockHash: blockhash,
From: from_addr,
BlockHash: blockhash,
BlockNumber: blocknumber,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
IsContract: isContract,
Age: age,
Data: data,
Age: age,
Data: data,
}
json, _ := json.Marshal(tx)
return string(json)
}
func InnerSGetAccount(sqldb *sql.DB, address string) (SAccounts, bool) {
func InnerSGetAccount(sqldb *sql.DB, address string) (stypes.SAccounts, bool) {
sqlStatement := `SELECT * FROM accounts WHERE addr=$1;`
var addr, balance, accountNonce string
err := sqldb.QueryRow(sqlStatement, address).Scan(&addr, &balance, &accountNonce)
if err == sql.ErrNoRows {
return SAccounts{}, false
return stypes.SAccounts{}, false
} else {
account := SAccounts{
Addr: addr,
Balance: balance,
AccountNonce: accountNonce,
account := stypes.SAccounts{
Addr: addr,
Balance: balance,
AccountNonce: accountNonce,
}
return account, true
}
@ -305,7 +307,7 @@ func SGetAccount(sqldb *sql.DB, address string) string {
//GetAllAccounts returns all accounts and balances
func SGetAllAccounts(sqldb *sql.DB) string {
var array accountRes
var array stypes.AccountRes
var accountsArr, accountNonce string
accs, err := sqldb.Query(`
@ -326,10 +328,10 @@ func SGetAllAccounts(sqldb *sql.DB) string {
&addr, &balance, &accountNonce,
)
array.AllAccounts = append(array.AllAccounts, SAccounts{
Addr: addr,
Balance: balance,
AccountNonce: accountNonce,
array.AllAccounts = append(array.AllAccounts, stypes.SAccounts{
Addr: addr,
Balance: balance,
AccountNonce: accountNonce,
})
accounts, _ := json.Marshal(array.AllAccounts)
@ -341,7 +343,7 @@ func SGetAllAccounts(sqldb *sql.DB) string {
//GetAccount returns account balances
func SGetAccountTxs(sqldb *sql.DB, address string) string {
var arr txRes
var arr stypes.TxRes
var txx string
sqlStatement := `SELECT * FROM txs WHERE to_addr=$1 OR from_addr=$1;`
rows, err := sqldb.Query(sqlStatement, address)
@ -360,22 +362,22 @@ func SGetAccountTxs(sqldb *sql.DB, address string) string {
&txhash, &to_addr, &from_addr, &blockhash, &blocknumber, &amount, &gasprice, &gas, &gasLimit, &txfee, &nonce, &status, &isContract, &age, &data,
)
arr.TxEntry = append(arr.TxEntry, ShyftTxEntryPretty{
TxHash: txhash,
arr.TxEntry = append(arr.TxEntry, stypes.ShyftTxEntryPretty{
TxHash: txhash,
ToGet: to_addr,
From: from_addr,
From: from_addr,
BlockHash: blockhash,
BlockNumber: blocknumber,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
Amount: amount,
GasPrice: gasprice,
Gas: gas,
GasLimit: gasLimit,
Cost: txfee,
Nonce: nonce,
Status: status,
IsContract: isContract,
Age: age,
Data: data,
Age: age,
Data: data,
})
tx, _ := json.Marshal(arr.TxEntry)

View file

@ -30,6 +30,7 @@ import (
"github.com/ShyftNetwork/go-empyrean/common"
"github.com/ShyftNetwork/go-empyrean/common/hexutil"
"github.com/ShyftNetwork/go-empyrean/core"
stypes "github.com/ShyftNetwork/go-empyrean/core/sTypes"
"github.com/ShyftNetwork/go-empyrean/core/vm"
"github.com/ShyftNetwork/go-empyrean/crypto"
"github.com/ShyftNetwork/go-empyrean/log"
@ -604,7 +605,7 @@ func (i *Internals) SWriteInteralTxs(hash common.Hash) {
value, _ := hexutil.DecodeUint64(i.Value)
amount := strconv.FormatUint(value, 10)
iTx := core.InteralWrite{
iTx := stypes.InteralWrite{
Hash: hash.Hex(),
Type: i.Type,
From: i.From,

View file

@ -21,7 +21,6 @@ class AccountTable extends Component {
}
render() {
let startNum = 1;
const sorted = [...this.state.data];
sorted.sort((a, b) => Number(a.Balance) > Number(b.Balance));
@ -38,7 +37,7 @@ class AccountTable extends Component {
Percentage={percentage.toFixed(2)}
Addr={data.Addr}
Balance={conversion}
TxCountAccount={data.TxCountAccount}
AccountNonce={data.AccountNonce}
detailAccountHandler={this.props.detailAccountHandler}
/>
});

View file

@ -12,7 +12,7 @@ const AccountsTable = (props) => {
</Link></td>
<td>{props.Balance}</td>
<td>{props.Percentage}%</td>
<td>{props.TxCountAccount}</td>
<td>{props.AccountNonce}</td>
</tr>
</tbody>
)

View file

@ -17,7 +17,7 @@ class AccountTransactionTable extends Component {
age={data.Age}
txHash={data.TxHash}
blockNumber={data.BlockNumber}
to={data.To}
to={data.ToGet}
from={data.From}
value={amountConversion}
cost={costConversion}

View file

@ -30,7 +30,7 @@ class BlocksTable extends Component {
Hash={data.Hash}
Number={data.Number}
Coinbase={data.Coinbase}
Age={data.Age}
AgeGet={data.AgeGet}
GasUsed={data.GasUsed}
GasLimit={data.GasLimit}
UncleCount={data.UncleCount}

View file

@ -10,7 +10,7 @@ const BlockTable = (props) => {
{props.Number}
</Link></td>
<td className={classes.addressTag}>{props.Hash}</td>
<td>{props.Age}</td>
<td>{props.AgeGet}</td>
<td>{props.TxCount}</td>
<td>{props.UncleCount}</td>
<td className={classes.addressTag}><Link to="/mined/blocks" onClick={() => props.getBlocksMined(props.Coinbase)}>{props.Coinbase}</Link></td>

View file

@ -16,7 +16,7 @@ class DetailBlockTable extends Component {
</tr>
<tr>
<th scope="col">Age:</th>
<td>{data.Age}</td>
<td>{data.AgeGet}</td>
</tr>
<tr>
<th scope="col">Txn:</th>

View file

@ -19,7 +19,7 @@ class BlocksMinedTable extends Component {
Hash={data.Hash}
Number={data.Number}
Coinbase={data.Coinbase}
Age={data.Age}
AgeGet={data.AgeGet}
GasUsed={data.GasUsed}
GasLimit={data.GasLimit}
UncleCount={data.UncleCount}

View file

@ -10,7 +10,7 @@ const MinedBlockTable = (props) => {
{props.Number}
</Link></td>
<td className={classes.addressTag}>{props.Hash}</td>
<td>{props.Age}</td>
<td>{props.AgeGet}</td>
<td>{props.TxCount}</td>
<td>{props.UncleCount}</td>
<td className={classes.addressTag}>{props.Coinbase}</td>

View file

@ -32,7 +32,7 @@ class DetailTransactionTable extends Component {
</tr>
<tr>
<th scope="col">To:</th>
<td>{ `${data.IsContract}` ? `${data.To} (Contract)` : `${data.To}` }</td>
<td>{ `${data.IsContract}` ? `${data.ToGet} (Contract)` : `${data.ToGet}` }</td>
</tr>
<tr>
<th scope="col">Value:</th>

View file

@ -31,7 +31,7 @@ class TransactionTable extends Component {
age={data.Age}
txHash={data.TxHash}
blockNumber={data.BlockNumber}
to={data.To}
to={data.ToGet}
from={data.From}
value={data.Amount}
cost={conversion}