mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
need to clean up updating account balances functions
This commit is contained in:
parent
2abd54c29e
commit
3acdd3f5c5
3 changed files with 12 additions and 15 deletions
|
|
@ -147,7 +147,7 @@ func SWriteBlock(block *types.Block, receipts []*types.Receipt) error {
|
||||||
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 {
|
if block.Transactions()[0].To() != nil {
|
||||||
swriteFromBalance(sqldb, tx)
|
swriteBalance(sqldb, tx)
|
||||||
}
|
}
|
||||||
if block.Transactions()[0].To() == nil {
|
if block.Transactions()[0].To() == nil {
|
||||||
swriteContractBalance(sqldb, tx)
|
swriteContractBalance(sqldb, tx)
|
||||||
|
|
@ -247,8 +247,8 @@ func swriteContractBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//writeFromBalance writes senders balance to accounts db
|
//writeBalance writes senders balance to accounts db
|
||||||
func swriteFromBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
func swriteBalance(sqldb *sql.DB, tx *types.Transaction) error {
|
||||||
sendAndReceiveData := SendAndReceive{
|
sendAndReceiveData := SendAndReceive{
|
||||||
To: tx.To().Hex(),
|
To: tx.To().Hex(),
|
||||||
From: tx.From().Hex(),
|
From: tx.From().Hex(),
|
||||||
|
|
@ -278,7 +278,6 @@ func adjustBalanceFromAddr(sqldb *sql.DB, s SendAndReceive, value *big.Int) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
var newBalanceSender, newAccountNonceSender big.Int
|
var newBalanceSender, newAccountNonceSender big.Int
|
||||||
var nonceIncrement = big.NewInt(1)
|
var nonceIncrement = big.NewInt(1)
|
||||||
|
|
||||||
|
|
@ -335,13 +334,14 @@ func SWriteInternalTxBalances(sqldb *sql.DB, toAddr string, fromAddr string, amo
|
||||||
From: fromAddr,
|
From: fromAddr,
|
||||||
Amount: amount,
|
Amount: amount,
|
||||||
}
|
}
|
||||||
|
|
||||||
toAddressBalance, toAccountNonce, err := AccountExists(sqldb, sendAndReceiveData.To)
|
toAddressBalance, toAccountNonce, err := AccountExists(sqldb, sendAndReceiveData.To)
|
||||||
|
value := new(big.Int)
|
||||||
|
value, _ = value.SetString(amount, 10)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
accountNonce := "1"
|
accountNonce := "1"
|
||||||
CreateAccount(sqldb, sendAndReceiveData.To, sendAndReceiveData.Amount, accountNonce)
|
CreateAccount(sqldb, sendAndReceiveData.To, sendAndReceiveData.Amount, accountNonce)
|
||||||
|
adjustBalanceFromAddr(sqldb, sendAndReceiveData, value)
|
||||||
case err != nil:
|
case err != nil:
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,12 @@ import (
|
||||||
|
|
||||||
_ "github.com/lib/pq"
|
_ "github.com/lib/pq"
|
||||||
|
|
||||||
|
"bytes"
|
||||||
|
"encoding/json"
|
||||||
|
"io/ioutil"
|
||||||
|
|
||||||
"github.com/ShyftNetwork/go-empyrean/core"
|
"github.com/ShyftNetwork/go-empyrean/core"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"bytes"
|
|
||||||
"io/ioutil"
|
|
||||||
"encoding/json"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetTransaction gets txs
|
// GetTransaction gets txs
|
||||||
|
|
@ -239,7 +240,7 @@ func BroadcastTx(w http.ResponseWriter, r *http.Request) {
|
||||||
fmt.Fprintln(w, "ERROR parsing json")
|
fmt.Fprintln(w, "ERROR parsing json")
|
||||||
}
|
}
|
||||||
tx_hash := dat["result"]
|
tx_hash := dat["result"]
|
||||||
if(tx_hash == nil) {
|
if tx_hash == nil {
|
||||||
errMap := dat["error"].(map[string]interface{})
|
errMap := dat["error"].(map[string]interface{})
|
||||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
|
|
@ -249,4 +250,4 @@ func BroadcastTx(w http.ResponseWriter, r *http.Request) {
|
||||||
w.WriteHeader(http.StatusOK)
|
w.WriteHeader(http.StatusOK)
|
||||||
fmt.Fprintln(w, "Transaction Hash:", tx_hash)
|
fmt.Fprintln(w, "Transaction Hash:", tx_hash)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -362,7 +362,3 @@ func TestBlock(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
//Genesis.go functions
|
|
||||||
// WriteBlockZero
|
|
||||||
// WriteShyftGen
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue