aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-24 19:12:24 +0800
committerobscuren <geffobscura@gmail.com>2014-02-24 19:12:24 +0800
commita3fb7008b2df860b01df71ef7da42b394570d1e2 (patch)
tree3edf97ea3e8061f69c28bb605d7f79e4d5e15925 /ethchain
parent55c1c220d07c37610c9aa61c583eccb3c8e3829e (diff)
downloaddexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar.gz
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar.bz2
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar.lz
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar.xz
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.tar.zst
dexon-a3fb7008b2df860b01df71ef7da42b394570d1e2.zip
Added make contract
Diffstat (limited to 'ethchain')
-rw-r--r--ethchain/contract.go28
1 files changed, 28 insertions, 0 deletions
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
+}