aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/vm.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-05-08 20:20:45 +0800
committerobscuren <geffobscura@gmail.com>2014-05-08 20:20:45 +0800
commitf0440e85dc306f270666e3aee1fe419b684a2ae8 (patch)
tree48bdfe63832723d5007536c73452a98859941ed9 /ethchain/vm.go
parent554f4f6f7d8b8bc5332d42631ec9de0d7015eccf (diff)
downloadgo-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar.gz
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar.bz2
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar.lz
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar.xz
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.tar.zst
go-tangerine-f0440e85dc306f270666e3aee1fe419b684a2ae8.zip
Removed value from closure.
Diffstat (limited to 'ethchain/vm.go')
-rw-r--r--ethchain/vm.go26
1 files changed, 17 insertions, 9 deletions
diff --git a/ethchain/vm.go b/ethchain/vm.go
index b4c77c849..ee470c269 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -5,7 +5,6 @@ import (
"fmt"
"github.com/ethereum/eth-go/ethutil"
_ "github.com/obscuren/secp256k1-go"
- "log"
_ "math"
"math/big"
)
@@ -96,7 +95,6 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
if ethutil.Config.Debug {
ethutil.Config.Log.Debugf("# op\n")
}
-
fmt.Println(closure.Script)
for {
@@ -320,13 +318,12 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case oADDRESS:
stack.Push(ethutil.BigD(closure.Object().Address()))
case oBALANCE:
- stack.Push(closure.Value)
+ stack.Push(closure.object.Amount)
case oORIGIN:
stack.Push(ethutil.BigD(vm.vars.Origin))
case oCALLER:
stack.Push(ethutil.BigD(closure.Callee().Address()))
case oCALLVALUE:
- log.Println("Value:", vm.vars.Value)
stack.Push(vm.vars.Value)
case oCALLDATALOAD:
require(1)
@@ -406,13 +403,15 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
require(1)
pc = stack.Pop()
// Reduce pc by one because of the increment that's at the end of this for loop
- pc.Sub(pc, ethutil.Big1)
+ //pc.Sub(pc, ethutil.Big1)
+ continue
case oJUMPI:
require(2)
cond, pos := stack.Popn()
if cond.Cmp(ethutil.BigTrue) == 0 {
pc = pos
- pc.Sub(pc, ethutil.Big1)
+ //pc.Sub(pc, ethutil.Big1)
+ continue
}
case oPC:
stack.Push(pc)
@@ -441,8 +440,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
contract.initScript,
vm.state,
gas,
- closure.Price,
- value)
+ closure.Price)
// Call the closure and set the return value as
// main script.
closure.Script, err = closure.Call(vm, nil, hook)
@@ -469,10 +467,13 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
break
}
+
// Get the arguments from the memory
args := mem.Get(inOffset.Int64(), inSize.Int64())
+
// Fetch the contract which will serve as the closure body
contract := vm.state.GetContract(addr.Bytes())
+ fmt.Println("before", contract.Amount)
if contract != nil {
// Prepay for the gas
@@ -482,8 +483,12 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
gas = new(big.Int).Set(closure.Gas)
}
closure.Gas.Sub(closure.Gas, gas)
+
+ // Add the value to the state object
+ contract.AddAmount(value)
+
// Create a new callable closure
- closure := NewClosure(closure.Object(), contract, contract.script, vm.state, gas, closure.Price, value)
+ closure := NewClosure(closure.Object(), contract, contract.script, vm.state, gas, closure.Price)
// Executer the closure and get the return value (if any)
ret, err := closure.Call(vm, args, hook)
if err != nil {
@@ -496,6 +501,9 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
vm.stateManager.manifest.AddObjectChange(contract)
}
+ vm.state.SetStateObject(contract)
+ fmt.Println("after", contract.Amount)
+
mem.Set(retOffset.Int64(), retSize.Int64(), ret)
} else {
ethutil.Config.Log.Debugf("Contract %x not found\n", addr.Bytes())