aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/transaction_pool.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-28 18:05:46 +0800
committerobscuren <geffobscura@gmail.com>2014-05-28 18:05:46 +0800
commit73761f7af64432b6946934c3b1db646d8e99ef07 (patch)
tree80ec8827bcbca50b65e1ca8f155b6d348e87fc72 /ethchain/transaction_pool.go
parent1c01e9c0958d2706c522602663da7cfc40a88600 (diff)
downloadgo-tangerine-73761f7af64432b6946934c3b1db646d8e99ef07.tar.gz
go-tangerine-73761f7af64432b6946934c3b1db646d8e99ef07.tar.zst
go-tangerine-73761f7af64432b6946934c3b1db646d8e99ef07.zip
Closure call now returns the total usage as well
* Return the used gas value based on the UseGas and ReturnGas
Diffstat (limited to 'ethchain/transaction_pool.go')
-rw-r--r--ethchain/transaction_pool.go18
1 files changed, 14 insertions, 4 deletions
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index ee026ffdd..7198026a8 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -91,28 +91,37 @@ func (pool *TxPool) addTransaction(tx *Transaction) {
// Process transaction validates the Tx and processes funds from the
// sender to the recipient.
-func (pool *TxPool) ProcessTransaction(tx *Transaction, state *State, toContract bool) (err error) {
+func (pool *TxPool) ProcessTransaction(tx *Transaction, state *State, toContract bool) (gas *big.Int, err error) {
defer func() {
if r := recover(); r != nil {
ethutil.Config.Log.Infoln(r)
err = fmt.Errorf("%v", r)
}
}()
+
+ gas = new(big.Int)
+ addGas := func(g *big.Int) { gas.Add(gas, g) }
+
// Get the sender
sender := state.GetAccount(tx.Sender())
if sender.Nonce != tx.Nonce {
- return fmt.Errorf("[TXPL] Invalid account nonce, state nonce is %d transaction nonce is %d instead", sender.Nonce, tx.Nonce)
+ err = fmt.Errorf("[TXPL] Invalid account nonce, state nonce is %d transaction nonce is %d instead", sender.Nonce, tx.Nonce)
+ return
}
+ txTotalBytes := big.NewInt(int64(len(tx.Data)))
+ txTotalBytes.Div(txTotalBytes, ethutil.Big32)
+ addGas(new(big.Int).Mul(txTotalBytes, GasSStore))
+
// Make sure there's enough in the sender's account. Having insufficient
// funds won't invalidate this transaction but simple ignores it.
//totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(TxFee, TxFeeRat))
totAmount := new(big.Int).Add(tx.Value, new(big.Int).Mul(tx.Gas, tx.GasPrice))
if sender.Amount.Cmp(totAmount) < 0 {
- return fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender())
+ err = fmt.Errorf("[TXPL] Insufficient amount in sender's (%x) account", tx.Sender())
+ return
}
- //fmt.Println(tx)
// Get the receiver
receiver := state.GetAccount(tx.Recipient)
@@ -120,6 +129,7 @@ func (pool *TxPool) ProcessTransaction(tx *Transaction, state *State, toContract
// Send Tx to self
if bytes.Compare(tx.Recipient, tx.Sender()) == 0 {
+ addGas(GasTx)
// Subtract the fee
sender.SubAmount(new(big.Int).Mul(GasTx, tx.GasPrice))
} else {