From a3fb7008b2df860b01df71ef7da42b394570d1e2 Mon Sep 17 00:00:00 2001
From: obscuren <geffobscura@gmail.com>
Date: Mon, 24 Feb 2014 12:12:24 +0100
Subject: Added make contract

---
 ethchain/contract.go | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

(limited to 'ethchain/contract.go')

diff --git a/ethchain/contract.go b/ethchain/contract.go
index 68ec39f0b..dbcbb3697 100644
--- a/ethchain/contract.go
+++ b/ethchain/contract.go
@@ -41,3 +41,31 @@ func (c *Contract) SetAddr(addr []byte, value interface{}) {
 func (c *Contract) State() *ethutil.Trie {
 	return c.state
 }
+
+func (c *Contract) GetMem(num int) *ethutil.Value {
+	nb := ethutil.BigToBytes(big.NewInt(int64(num)), 256)
+
+	return c.Addr(nb)
+}
+
+func MakeContract(tx *Transaction, state *State) *Contract {
+	// Create contract if there's no recipient
+	if tx.IsContract() {
+		addr := tx.Hash()[12:]
+
+		value := tx.Value
+		contract := NewContract(value, []byte(""))
+		state.trie.Update(string(addr), string(contract.RlpEncode()))
+		for i, val := range tx.Data {
+			if len(val) > 0 {
+				bytNum := ethutil.BigToBytes(big.NewInt(int64(i)), 256)
+				contract.state.Update(string(bytNum), string(ethutil.Encode(val)))
+			}
+		}
+		state.trie.Update(string(addr), string(contract.RlpEncode()))
+
+		return contract
+	}
+
+	return nil
+}
-- 
cgit v1.2.3