aboutsummaryrefslogtreecommitdiffstats
path: root/block.go
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-03 07:43:49 +0800
committerobscuren <obscuren@obscura.com>2014-01-03 07:43:49 +0800
commit7cd41ac45aed7ee22ef02f8abedf83a2914c4807 (patch)
tree7a4c3daee8a04dc9604098407f019bb5db9ea3d4 /block.go
parent9df4c745119b3ed10a7ad17887e8dd9cac249af7 (diff)
downloaddexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.gz
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.bz2
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.lz
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.xz
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.zst
dexon-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.zip
Wip VM. Created contracts
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() {
}