aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-21 19:37:16 +0800
committerobscuren <geffobscura@gmail.com>2014-02-21 19:37:16 +0800
commit18cc35338afc8a3843716af0d96bd03d36e735ea (patch)
treef6dead08baf0c53a3dbce91c1a614d5e09eb6551 /ethchain
parent681eacaa7fdda41fe168baba03095ee74708444f (diff)
downloadgo-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar.gz
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar.bz2
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar.lz
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar.xz
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.tar.zst
go-tangerine-18cc35338afc8a3843716af0d96bd03d36e735ea.zip
Fixed contract running
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/block_manager.go18
-rw-r--r--ethchain/block_manager_test.go1
2 files changed, 10 insertions, 9 deletions
diff --git a/ethchain/block_manager.go b/ethchain/block_manager.go
index 1847ba2d4..91bcaa468 100644
--- a/ethchain/block_manager.go
+++ b/ethchain/block_manager.go
@@ -321,19 +321,20 @@ func (bm *BlockManager) ProcContract(tx *Transaction, block *Block, cb TxCallbac
stepcount := 0
totalFee := new(big.Int)
+
+ // helper function for getting a contract's memory address
+ getMem := func(num int) *ethutil.Value {
+ nb := ethutil.BigToBytes(big.NewInt(int64(num)), 256)
+ return contract.Addr(nb)
+ }
out:
for {
stepcount++
// The base big int for all calculations. Use this for any results.
base := new(big.Int)
- // XXX Should Instr return big int slice instead of string slice?
- // Get the next instruction from the contract
- nb := ethutil.BigToBytes(big.NewInt(int64(pc)), 256)
- r := contract.State().Get(string(nb))
- v := ethutil.NewValueFromBytes([]byte(r))
+ val := getMem(pc)
//fmt.Printf("%x = %d, %v %x\n", r, len(r), v, nb)
- o := v.Uint()
- op := OpCode(o)
+ op := OpCode(val.Uint())
var fee *big.Int = new(big.Int)
var fee2 *big.Int = new(big.Int)
@@ -378,6 +379,7 @@ out:
switch op {
case oSTOP:
+ fmt.Println("")
break out
case oADD:
x, y := bm.stack.Popn()
@@ -580,7 +582,7 @@ out:
case oECVALID:
case oPUSH:
pc++
- bm.stack.Push(bm.mem[strconv.Itoa(pc)])
+ bm.stack.Push(getMem(pc).BigInt())
case oPOP:
// Pop current value of the stack
bm.stack.Pop()
diff --git a/ethchain/block_manager_test.go b/ethchain/block_manager_test.go
index ae29e2e25..853d459d8 100644
--- a/ethchain/block_manager_test.go
+++ b/ethchain/block_manager_test.go
@@ -22,7 +22,6 @@ func TestVm(t *testing.T) {
"1",
"PUSH",
"2",
-
"STOP",
})
bm.ApplyTransactions(block, []*Transaction{ctrct})