aboutsummaryrefslogtreecommitdiffstats
path: root/block.go
diff options
context:
space:
mode:
Diffstat (limited to 'block.go')
-rw-r--r--block.go26
1 files changed, 25 insertions, 1 deletions
diff --git a/block.go b/block.go
index 146328471..dd329f8ac 100644
--- a/block.go
+++ b/block.go
@@ -4,6 +4,7 @@ import (
_"fmt"
"time"
_"bytes"
+ _"encoding/hex"
)
type Block struct {
@@ -63,13 +64,36 @@ func CreateBlock(root string, num int, prevHash string, base string, difficulty
extra: extra,
}
block.state = NewTrie(Db, root)
+
for _, tx := range txes {
- block.state.Update(tx.recipient, string(tx.MarshalRlp()))
+ // Create contract if there's no recipient
+ if tx.recipient == "" {
+ addr := tx.Hash()
+
+ contract := NewContract(tx.value, []byte(""))
+ block.state.Update(string(addr), string(contract.MarshalRlp()))
+ for i, val := range tx.data {
+ contract.state.Update(string(Encode(i)), val)
+ }
+ block.UpdateContract(addr, contract)
+ }
}
return block
}
+func (block *Block) GetContract(addr []byte) *Contract {
+ data := block.state.Get(string(addr))
+ contract := &Contract{}
+ contract.UnmarshalRlp([]byte(data))
+
+ return contract
+}
+
+func (block *Block) UpdateContract(addr []byte, contract *Contract) {
+ block.state.Update(string(addr), string(contract.MarshalRlp()))
+}
+
func (block *Block) Update() {
}