mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 18:02:24 +00:00
changed start script for web socket access, modified writeBlock
This commit is contained in:
parent
bd6acd8059
commit
1d93088980
4 changed files with 91 additions and 75 deletions
|
|
@ -8,7 +8,7 @@ import (
|
|||
|
||||
_ "github.com/lib/pq"
|
||||
|
||||
shyftdb "github.com/ethereum/go-ethereum/shyftdb"
|
||||
"github.com/ethereum/go-ethereum/shyftdb"
|
||||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
|
|
@ -48,6 +48,7 @@ func GetAllTransactions(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
||||
|
|
|
|||
|
|
@ -94,8 +94,9 @@ func WriteBlock(sqldb *sql.DB, block *types.Block) error {
|
|||
panic(qerr)
|
||||
}
|
||||
|
||||
if block.Transactions().Len() > 0 {
|
||||
if block.Transactions().Len() > 0 && block.Transactions()[0].To() != nil {
|
||||
for _, tx := range block.Transactions() {
|
||||
//WriteMinerRewards(sqldb, block)
|
||||
WriteTransactions(sqldb, tx, block.Header().Hash())
|
||||
WriteFromBalance(sqldb, tx)
|
||||
}
|
||||
|
|
@ -233,63 +234,77 @@ func WriteBalanceHelper(sqldb *sql.DB, tx *types.Transaction) (SendAndReceive, s
|
|||
return sendAndReceiveData, balanceReceiver, balanceSender
|
||||
}
|
||||
|
||||
//func WriteMinerRewards(sqldb *sql.DB, block *types.Block) {
|
||||
// var totalGas big.Int
|
||||
// //var txs []string
|
||||
//
|
||||
// fmt.Println("this is BLOCK.UNCLE", block.Uncles())
|
||||
// fmt.Println("this is BLOCK UNCLE HASH", block.UncleHash().String())
|
||||
// fmt.Println("this is BLOCK.TRANSACTIONS", block.Transactions())
|
||||
// fmt.Println("this is BLOCK TOTAL GAS", block.GasUsed())
|
||||
//
|
||||
// for _, tx := range block.Transactions() {
|
||||
// totalGas.Add(&totalGas, new(big.Int).Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.Gas())))
|
||||
// }
|
||||
//}
|
||||
|
||||
// @NOTE: This function is extremely complex and requires heavy testing and knowdlege of edge cases:
|
||||
// uncle blocks, account balance updates based on reorgs, diverges that get dropped.
|
||||
// Reason for this is because the accounts are not deterministic like the block and tx hashes.
|
||||
// @TODO: Calculate reward if there are uncles
|
||||
// @TODO: Calculate mining reward (most likely retrieve higher up in the operations)
|
||||
// @TODO: Calculate reorg
|
||||
// func WriteMinerReward(db *leveldb.DB, block *types.Block) {
|
||||
// var totalGas *big.Int
|
||||
// var txs []string
|
||||
// key := append([]byte("acc-")[:], block.Coinbase().Hash().Bytes()[:]...)
|
||||
// for _, tx := range block.Transactions() {
|
||||
// totalGas.Add(totalGas, new(big.Int).Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.Gas())))
|
||||
// }
|
||||
// retrievedData, err := db.Get(key, nil)
|
||||
// if err != nil {
|
||||
// // Assume time this account has had a tx
|
||||
// // Balacne is exclusively minerreward + total gas from the block b/c no prior evm activity
|
||||
// // Txs would be empty because they have not had any transactions on the EVM
|
||||
// // @TODO: Calc mining reward
|
||||
// //balance := totalGas.Add(totalGas, MINING_REWARD)
|
||||
// balance := totalGas
|
||||
// accData := ShyftAccountEntry{
|
||||
// Balance: balance,
|
||||
// Txs: txs,
|
||||
// }
|
||||
// var encodedData bytes.Buffer
|
||||
// encoder := gob.NewEncoder(&encodedData)
|
||||
// if err := encoder.Encode(accData); err != nil {
|
||||
// log.Crit("Faild to encode Miner Account data", "err", err)
|
||||
// }
|
||||
// if err := db.Put(key, encodedData.Bytes(), nil); err != nil {
|
||||
// log.Crit("Could not write the miner's first tx", "err", err)
|
||||
// }
|
||||
// } else {
|
||||
// // The account has already have previous data stored due to activity in the EVM
|
||||
// // Decode the data to update balance
|
||||
// var decodedData ShyftAccountEntry
|
||||
// d := gob.NewDecoder(bytes.NewBuffer(retrievedData))
|
||||
// if err := d.Decode(&decodedData); err != nil {
|
||||
// log.Crit("Failed to decode miner data:", "err", err)
|
||||
// }
|
||||
// // Write new balance
|
||||
// // @TODO: Calc mining reward
|
||||
// // decodedData.Balance.Add(decodedData.Balance, totalGas.Add(totalGas, MINING_REWARD)))
|
||||
// decodedData.Balance.Add(decodedData.Balance, totalGas)
|
||||
// // Encode the data to be written back to the db
|
||||
// var encodedData bytes.Buffer
|
||||
// encoder := gob.NewEncoder(&encodedData)
|
||||
// if err := encoder.Encode(decodedData); err != nil {
|
||||
// log.Crit("Faild to encode Miner Account data", "err", err)
|
||||
// }
|
||||
// // Write newly encoded data back to the db
|
||||
// if err := db.Put(key, encodedData.Bytes(), nil); err != nil {
|
||||
// log.Crit("Could not update miner account data", "err", err)
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//func WriteMinerReward(db *leveldb.DB, block *types.Block) {
|
||||
// var totalGas *big.Int
|
||||
// var txs []string
|
||||
// key := append([]byte("acc-")[:], block.Coinbase().Hash().Bytes()[:]...)
|
||||
// for _, tx := range block.Transactions() {
|
||||
// totalGas.Add(totalGas, new(big.Int).Mul(tx.GasPrice(), new(big.Int).SetUint64(tx.Gas())))
|
||||
// }
|
||||
//// retrievedData, err := db.Get(key, nil)
|
||||
// if err != nil {
|
||||
// // Assume time this account has had a tx
|
||||
// // Balacne is exclusively minerreward + total gas from the block b/c no prior evm activity
|
||||
// // Txs would be empty because they have not had any transactions on the EVM
|
||||
// // @TODO: Calc mining reward
|
||||
// //balance := totalGas.Add(totalGas, MINING_REWARD)
|
||||
// balance := totalGas
|
||||
// accData := ShyftAccountEntry{
|
||||
// Balance: balance,
|
||||
// Txs: txs,
|
||||
// }
|
||||
// var encodedData bytes.Buffer
|
||||
// encoder := gob.NewEncoder(&encodedData)
|
||||
// if err := encoder.Encode(accData); err != nil {
|
||||
// log.Crit("Faild to encode Miner Account data", "err", err)
|
||||
// }
|
||||
// if err := db.Put(key, encodedData.Bytes(), nil); err != nil {
|
||||
// log.Crit("Could not write the miner's first tx", "err", err)
|
||||
// }
|
||||
// } else {
|
||||
// // The account has already have previous data stored due to activity in the EVM
|
||||
// // Decode the data to update balance
|
||||
// var decodedData ShyftAccountEntry
|
||||
// d := gob.NewDecoder(bytes.NewBuffer(retrievedData))
|
||||
// if err := d.Decode(&decodedData); err != nil {
|
||||
// log.Crit("Failed to decode miner data:", "err", err)
|
||||
// }
|
||||
// // Write new balance
|
||||
// // @TODO: Calc mining reward
|
||||
// // decodedData.Balance.Add(decodedData.Balance, totalGas.Add(totalGas, MINING_REWARD)))
|
||||
// decodedData.Balance.Add(decodedData.Balance, totalGas)
|
||||
// // Encode the data to be written back to the db
|
||||
// var encodedData bytes.Buffer
|
||||
// encoder := gob.NewEncoder(&encodedData)
|
||||
// if err := encoder.Encode(decodedData); err != nil {
|
||||
// log.Crit("Faild to encode Miner Account data", "err", err)
|
||||
// }
|
||||
// // Write newly encoded data back to the db
|
||||
// if err := db.Put(key, encodedData.Bytes(), nil); err != nil {
|
||||
// log.Crit("Could not update miner account data", "err", err)
|
||||
// }
|
||||
// }
|
||||
//}
|
||||
|
||||
///////////
|
||||
// Getters
|
||||
|
|
@ -477,7 +492,7 @@ func GetAllAccounts(sqldb *sql.DB) string {
|
|||
}
|
||||
|
||||
defer accs.Close()
|
||||
////
|
||||
|
||||
for accs.Next() {
|
||||
var addr string
|
||||
var balance string
|
||||
|
|
|
|||
|
|
@ -2,28 +2,28 @@ var firstAccount = web3.eth.accounts[0]
|
|||
var secondAccount = web3.eth.accounts[1]
|
||||
var thirdAccount = web3.eth.accounts[2]
|
||||
|
||||
for (var i = 0; i < 10; i++) {
|
||||
for (var i = 0; i < 1; i++) {
|
||||
console.log('\t\t' + (i + 1) + ' - Transactions')
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[2],
|
||||
to: web3.eth.accounts[0],
|
||||
from: web3.eth.accounts[1],
|
||||
to: web3.eth.accounts[2],
|
||||
value: 5,
|
||||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[1],
|
||||
to: web3.eth.accounts[2],
|
||||
value: 291,
|
||||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
|
||||
web3.eth.sendTransaction({
|
||||
from: web3.eth.accounts[0],
|
||||
to: web3.eth.accounts[1],
|
||||
value: 53039,
|
||||
gas: 50000,
|
||||
gasPrice: 20
|
||||
});
|
||||
// web3.eth.sendTransaction({
|
||||
// from: web3.eth.accounts[1],
|
||||
// to: web3.eth.accounts[2],
|
||||
// value: 291,
|
||||
// gas: 50000,
|
||||
// gasPrice: 20
|
||||
// });
|
||||
//
|
||||
// web3.eth.sendTransaction({
|
||||
// from: web3.eth.accounts[0],
|
||||
// to: web3.eth.accounts[1],
|
||||
// value: 53039,
|
||||
// gas: 50000,
|
||||
// gasPrice: 20
|
||||
// });
|
||||
}
|
||||
|
|
@ -1,2 +1,2 @@
|
|||
#!/bin/sh
|
||||
./build/bin/geth --config config.toml --nat=none --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt
|
||||
./build/bin/geth --config config.toml --ws --wsaddr="0.0.0.0" --wsorigins "*" --nat=none --mine --minerthreads 4 --targetgaslimit 80000000 --unlock "0x43EC6d0942f7fAeF069F7F63D0384a27f529B062,0x9e602164C5826ebb5A6B68E4AFD9Cd466043dc4A,0x5Bd738164C61FB50eb12E227846CbaeF2dE965Aa,0xC04eE4131895F1d0C294D508AF65D94060AA42BB,0x07D899C4aC0c1725C35C5f816e60273B33a964F7" --password ./unlockPasswords.txt
|
||||
|
|
|
|||
Loading…
Reference in a new issue