Modified according to poc 9 changes
* Refund of value
This commit is contained in:
		@@ -39,20 +39,22 @@ func (self *Execution) exec(contextAddr *common.Address, code []byte, caller vm.
 | 
				
			|||||||
		return nil, vm.DepthError{}
 | 
							return nil, vm.DepthError{}
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	snapshot := env.State().Copy()
 | 
						vsnapshot := env.State().Copy()
 | 
				
			||||||
	if self.address == nil {
 | 
						if self.address == nil {
 | 
				
			||||||
		// Generate a new address
 | 
							// Generate a new address
 | 
				
			||||||
		nonce := env.State().GetNonce(caller.Address())
 | 
							nonce := env.State().GetNonce(caller.Address())
 | 
				
			||||||
		addr := crypto.CreateAddress(caller.Address(), nonce)
 | 
							addr := crypto.CreateAddress(caller.Address(), nonce)
 | 
				
			||||||
		self.address = &addr
 | 
					 | 
				
			||||||
		env.State().SetNonce(caller.Address(), nonce+1)
 | 
							env.State().SetNonce(caller.Address(), nonce+1)
 | 
				
			||||||
 | 
							self.address = &addr
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
						snapshot := env.State().Copy()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(*self.address)
 | 
						from, to := env.State().GetStateObject(caller.Address()), env.State().GetOrNewStateObject(*self.address)
 | 
				
			||||||
	err = env.Transfer(from, to, self.value)
 | 
						err = env.Transfer(from, to, self.value)
 | 
				
			||||||
	if err != nil {
 | 
						if err != nil {
 | 
				
			||||||
		env.State().Set(snapshot)
 | 
							env.State().Set(vsnapshot)
 | 
				
			||||||
		//caller.ReturnGas(self.Gas, self.price)
 | 
					
 | 
				
			||||||
 | 
							caller.ReturnGas(self.Gas, self.price)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
 | 
							return nil, ValueTransferErr("insufficient funds to transfer value. Req %v, has %v", self.value, from.Balance())
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -196,7 +196,6 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
 | 
				
			|||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	// Increment the nonce for the next transaction
 | 
						// Increment the nonce for the next transaction
 | 
				
			||||||
	self.state.SetNonce(sender.Address(), sender.Nonce()+1)
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
	vmenv := self.env
 | 
						vmenv := self.env
 | 
				
			||||||
	var ref vm.ContextRef
 | 
						var ref vm.ContextRef
 | 
				
			||||||
@@ -214,6 +213,7 @@ func (self *StateTransition) transitionState() (ret []byte, usedGas *big.Int, er
 | 
				
			|||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
	} else {
 | 
						} else {
 | 
				
			||||||
 | 
							self.state.SetNonce(sender.Address(), sender.Nonce()+1)
 | 
				
			||||||
		ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
 | 
							ret, err = vmenv.Call(self.From(), self.To().Address(), self.msg.Data(), self.gas, self.gasPrice, self.value)
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,8 +7,8 @@ import (
 | 
				
			|||||||
	"math/big"
 | 
						"math/big"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/common"
 | 
						"github.com/ethereum/go-ethereum/common"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/rlp"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core/state"
 | 
						"github.com/ethereum/go-ethereum/core/state"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/rlp"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Environment interface {
 | 
					type Environment interface {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -6,9 +6,9 @@ import (
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/common"
 | 
						"github.com/ethereum/go-ethereum/common"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core"
 | 
						"github.com/ethereum/go-ethereum/core"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/crypto"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core/state"
 | 
						"github.com/ethereum/go-ethereum/core/state"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core/vm"
 | 
						"github.com/ethereum/go-ethereum/core/vm"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/crypto"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
type Env struct {
 | 
					type Env struct {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,10 +7,10 @@ import (
 | 
				
			|||||||
	"testing"
 | 
						"testing"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/common"
 | 
						"github.com/ethereum/go-ethereum/common"
 | 
				
			||||||
 | 
						"github.com/ethereum/go-ethereum/core/state"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core/types"
 | 
						"github.com/ethereum/go-ethereum/core/types"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/ethdb"
 | 
						"github.com/ethereum/go-ethereum/ethdb"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/logger"
 | 
						"github.com/ethereum/go-ethereum/logger"
 | 
				
			||||||
	"github.com/ethereum/go-ethereum/core/state"
 | 
					 | 
				
			||||||
	"github.com/ethereum/go-ethereum/tests/helper"
 | 
						"github.com/ethereum/go-ethereum/tests/helper"
 | 
				
			||||||
)
 | 
					)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -144,6 +144,11 @@ func RunVmTest(p string, t *testing.T) {
 | 
				
			|||||||
				if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
 | 
									if obj.Balance().Cmp(common.Big(account.Balance)) != 0 {
 | 
				
			||||||
					t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address().Bytes()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
 | 
										t.Errorf("%s's : (%x) balance failed. Expected %v, got %v => %v\n", name, obj.Address().Bytes()[:4], account.Balance, obj.Balance(), new(big.Int).Sub(common.Big(account.Balance), obj.Balance()))
 | 
				
			||||||
				}
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
									if obj.Nonce() != common.String2Big(account.Nonce).Uint64() {
 | 
				
			||||||
 | 
										t.Errorf("%s's : (%x) nonce failed. Expected %v, got %v\n", name, obj.Address().Bytes()[:4], account.Nonce, obj.Nonce())
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
			for addr, value := range account.Storage {
 | 
								for addr, value := range account.Storage {
 | 
				
			||||||
@@ -194,7 +199,7 @@ func RunVmTest(p string, t *testing.T) {
 | 
				
			|||||||
				}
 | 
									}
 | 
				
			||||||
			}
 | 
								}
 | 
				
			||||||
		}
 | 
							}
 | 
				
			||||||
		//statedb.Trie().PrintRoot()
 | 
							//fmt.Println(string(statedb.Dump()))
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	logger.Flush()
 | 
						logger.Flush()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user