core, core/vm, cmd/evm: remove redundant balance check

This commit is contained in:
Gustav Simonsson 2015-10-06 12:35:05 +02:00
parent 44fd395141
commit e1616f77c7
6 changed files with 10 additions and 19 deletions

View File

@ -217,8 +217,8 @@ func (self *VMEnv) AddLog(log *vm.Log) {
func (self *VMEnv) CanTransfer(from common.Address, balance *big.Int) bool { func (self *VMEnv) CanTransfer(from common.Address, balance *big.Int) bool {
return self.state.GetBalance(from).Cmp(balance) >= 0 return self.state.GetBalance(from).Cmp(balance) >= 0
} }
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) {
return core.Transfer(from, to, amount) core.Transfer(from, to, amount)
} }
func (self *VMEnv) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { func (self *VMEnv) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {

View File

@ -17,7 +17,6 @@
package core package core
import ( import (
"errors"
"math/big" "math/big"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
@ -108,13 +107,7 @@ func exec(env vm.Environment, caller vm.ContractRef, address, codeAddr *common.A
} }
// generic transfer method // generic transfer method
func Transfer(from, to vm.Account, amount *big.Int) error { func Transfer(from, to vm.Account, amount *big.Int) {
if from.Balance().Cmp(amount) < 0 {
return errors.New("Insufficient balance in account")
}
from.SubBalance(amount) from.SubBalance(amount)
to.AddBalance(amount) to.AddBalance(amount)
return nil
} }

View File

@ -51,7 +51,7 @@ type Environment interface {
// Determines whether it's possible to transact // Determines whether it's possible to transact
CanTransfer(from common.Address, balance *big.Int) bool CanTransfer(from common.Address, balance *big.Int) bool
// Transfers amount from one account to the other // Transfers amount from one account to the other
Transfer(from, to Account, amount *big.Int) error Transfer(from, to Account, amount *big.Int)
// Adds a LOG to the state // Adds a LOG to the state
AddLog(*Log) AddLog(*Log)
// Adds a structured log to the env // Adds a structured log to the env

View File

@ -152,9 +152,7 @@ func (self *Env) SetDepth(i int) { self.depth = i }
func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool { func (self *Env) CanTransfer(from common.Address, balance *big.Int) bool {
return true return true
} }
func (self *Env) Transfer(from, to Account, amount *big.Int) error { func (self *Env) Transfer(from, to Account, amount *big.Int) {}
return nil
}
func (self *Env) Call(caller ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { func (self *Env) Call(caller ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {
return nil, nil return nil, nil
} }

View File

@ -81,8 +81,8 @@ func (self *VMEnv) SetSnapshot(copy vm.Database) {
self.state.Set(copy.(*state.StateDB)) self.state.Set(copy.(*state.StateDB))
} }
func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) error { func (self *VMEnv) Transfer(from, to vm.Account, amount *big.Int) {
return Transfer(from, to, amount) Transfer(from, to, amount)
} }
func (self *VMEnv) Call(me vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { func (self *VMEnv) Call(me vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {

View File

@ -209,11 +209,11 @@ func (self *Env) SetSnapshot(copy vm.Database) {
self.state.Set(copy.(*state.StateDB)) self.state.Set(copy.(*state.StateDB))
} }
func (self *Env) Transfer(from, to vm.Account, amount *big.Int) error { func (self *Env) Transfer(from, to vm.Account, amount *big.Int) {
if self.skipTransfer { if self.skipTransfer {
return nil return
} }
return core.Transfer(from, to, amount) core.Transfer(from, to, amount)
} }
func (self *Env) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) { func (self *Env) Call(caller vm.ContractRef, addr common.Address, data []byte, gas, price, value *big.Int) ([]byte, error) {