aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/keypair.go10
-rw-r--r--ethchain/state_object.go1
-rw-r--r--ethchain/transaction_pool.go14
-rw-r--r--ethchain/vm.go44
4 files changed, 34 insertions, 35 deletions
diff --git a/ethchain/keypair.go b/ethchain/keypair.go
index a5af791d0..0f23bacdf 100644
--- a/ethchain/keypair.go
+++ b/ethchain/keypair.go
@@ -2,6 +2,7 @@ package ethchain
import (
"github.com/ethereum/eth-go/ethutil"
+ "github.com/obscuren/secp256k1-go"
"math/big"
)
@@ -14,6 +15,15 @@ type KeyPair struct {
state *State
}
+func NewKeyPairFromSec(seckey []byte) (*KeyPair, error) {
+ pubkey, err := secp256k1.GeneratePubKey(seckey)
+ if err != nil {
+ return nil, err
+ }
+
+ return &KeyPair{PrivateKey: seckey, PublicKey: pubkey}, nil
+}
+
func NewKeyPairFromValue(val *ethutil.Value) *KeyPair {
keyPair := &KeyPair{PrivateKey: val.Get(0).Bytes(), PublicKey: val.Get(1).Bytes()}
diff --git a/ethchain/state_object.go b/ethchain/state_object.go
index 8e921795d..4ec91d2e0 100644
--- a/ethchain/state_object.go
+++ b/ethchain/state_object.go
@@ -80,7 +80,6 @@ func (c *StateObject) SetAddr(addr []byte, value interface{}) {
func (c *StateObject) SetMem(num *big.Int, val *ethutil.Value) {
addr := ethutil.BigToBytes(num, 256)
c.SetAddr(addr, val)
- //c.state.trie.Update(string(addr), string(val.Encode()))
}
func (c *StateObject) GetMem(num *big.Int) *ethutil.Value {
diff --git a/ethchain/transaction_pool.go b/ethchain/transaction_pool.go
index 8fbe676f5..72836d6cb 100644
--- a/ethchain/transaction_pool.go
+++ b/ethchain/transaction_pool.go
@@ -91,14 +91,12 @@ 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, block *Block, toContract bool) (err error) {
- /*
- defer func() {
- if r := recover(); r != nil {
- log.Println(r)
- err = fmt.Errorf("%v", r)
- }
- }()
- */
+ defer func() {
+ if r := recover(); r != nil {
+ log.Println(r)
+ err = fmt.Errorf("%v", r)
+ }
+ }()
// Get the sender
sender := block.state.GetAccount(tx.Sender())
diff --git a/ethchain/vm.go b/ethchain/vm.go
index 0a3690c41..3a3b3447a 100644
--- a/ethchain/vm.go
+++ b/ethchain/vm.go
@@ -73,10 +73,7 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
}
}()
- // If the amount of gas supplied is less equal to 0
- if closure.Gas.Cmp(big.NewInt(0)) <= 0 {
- // TODO Do something
- }
+ ethutil.Config.Log.Debugf("[VM] Running closure %x\n", closure.object.Address())
// Memory for the current closure
mem := &Memory{}
@@ -107,9 +104,11 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
val := closure.Get(pc)
// Get the opcode (it must be an opcode!)
op := OpCode(val.Uint())
- if ethutil.Config.Debug {
- ethutil.Config.Log.Debugf("%-3d %-4s", pc, op.String())
- }
+ /*
+ if ethutil.Config.Debug {
+ ethutil.Config.Log.Debugf("%-3d %-4s", pc, op.String())
+ }
+ */
gas := new(big.Int)
useGas := func(amount *big.Int) {
@@ -163,9 +162,6 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
case oLOG:
stack.Print()
mem.Print()
- case oSTOP: // Stop the closure
- return closure.Return(nil), nil
-
// 0x20 range
case oADD:
require(2)
@@ -520,22 +516,18 @@ func (vm *Vm) RunClosure(closure *Closure, hook DebugHook) (ret []byte, err erro
return closure.Return(ret), nil
case oSUICIDE:
- /*
- recAddr := stack.Pop().Bytes()
- // Purge all memory
- deletedMemory := contract.state.Purge()
- // Add refunds to the pop'ed address
- refund := new(big.Int).Mul(StoreFee, big.NewInt(int64(deletedMemory)))
- account := state.GetAccount(recAddr)
- account.Amount.Add(account.Amount, refund)
- // Update the refunding address
- state.UpdateAccount(recAddr, account)
- // Delete the contract
- state.trie.Update(string(addr), "")
-
- ethutil.Config.Log.Debugf("(%d) => %x\n", deletedMemory, recAddr)
- break out
- */
+ require(1)
+
+ receiver := vm.state.GetAccount(stack.Pop().Bytes())
+ receiver.AddAmount(closure.object.Amount)
+
+ vm.stateManager.manifest.AddObjectChange(receiver)
+
+ closure.object.state.Purge()
+
+ fallthrough
+ case oSTOP: // Stop the closure
+ return closure.Return(nil), nil
default:
ethutil.Config.Log.Debugf("Invalid opcode %x\n", op)