diff options
author | obscuren <obscuren@obscura.com> | 2014-01-03 07:43:49 +0800 |
---|---|---|
committer | obscuren <obscuren@obscura.com> | 2014-01-03 07:43:49 +0800 |
commit | 7cd41ac45aed7ee22ef02f8abedf83a2914c4807 (patch) | |
tree | 7a4c3daee8a04dc9604098407f019bb5db9ea3d4 /contract.go | |
parent | 9df4c745119b3ed10a7ad17887e8dd9cac249af7 (diff) | |
download | go-tangerine-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.gz go-tangerine-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.tar.zst go-tangerine-7cd41ac45aed7ee22ef02f8abedf83a2914c4807.zip |
Wip VM. Created contracts
Diffstat (limited to 'contract.go')
-rw-r--r-- | contract.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/contract.go b/contract.go new file mode 100644 index 000000000..e95e50b74 --- /dev/null +++ b/contract.go @@ -0,0 +1,40 @@ +package main + +import ( +) + +type Contract struct { + active int + amount uint32 // ??? + state *Trie +} +func NewContract(amount uint32, root []byte) *Contract { + contract := &Contract{active: 1, amount: amount} + contract.state = NewTrie(Db, string(root)) + + return contract +} +func (c *Contract) MarshalRlp() []byte { + // Prepare the transaction for serialization + preEnc := []interface{}{uint32(c.active), c.amount, c.state.root} + + return Encode(preEnc) +} + +func (c *Contract) UnmarshalRlp(data []byte) { + t, _ := Decode(data, 0) + + if slice, ok := t.([]interface{}); ok { + if active, ok := slice[0].(uint8); ok { + c.active = int(active) + } + + if amount, ok := slice[1].(uint8); ok { + c.amount = uint32(amount) + } + + if root, ok := slice[2].([]uint8); ok { + c.state = NewTrie(Db, string(root)) + } + } +} |