aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorobscuren <obscuren@obscura.com>2014-01-04 07:32:01 +0800
committerobscuren <obscuren@obscura.com>2014-01-04 07:32:01 +0800
commitebef4e103b4601e477a787ace068dbf181acc39c (patch)
treee0386f1dcff7dbce9810c9d28127b66e7c798151
parenta42ebd9ed62ffe5ba30e29001a380a4bd185be6d (diff)
downloadgo-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar.gz
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar.bz2
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar.lz
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar.xz
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.tar.zst
go-tangerine-ebef4e103b4601e477a787ace068dbf181acc39c.zip
Ether
-rw-r--r--contract.go63
1 files changed, 52 insertions, 11 deletions
diff --git a/contract.go b/contract.go
index e95e50b74..778f3578d 100644
--- a/contract.go
+++ b/contract.go
@@ -1,36 +1,42 @@
package main
import (
+ _"fmt"
)
type Contract struct {
- active int
- amount uint32 // ???
+ t uint32 // contract is always 1
+ amount uint64 // ???
state *Trie
}
-func NewContract(amount uint32, root []byte) *Contract {
- contract := &Contract{active: 1, amount: amount}
+
+func NewContract(amount uint64, root []byte) *Contract {
+ contract := &Contract{t: 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) MarshalRlp() []byte {
+ return Encode([]interface{}{c.t, c.amount, c.state.root})
}
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 t, ok := slice[0].(uint8); ok {
+ c.t = uint32(t)
}
if amount, ok := slice[1].(uint8); ok {
- c.amount = uint32(amount)
+ c.amount = uint64(amount)
+ } else if amount, ok := slice[1].(uint16); ok {
+ c.amount = uint64(amount)
+ } else if amount, ok := slice[1].(uint32); ok {
+ c.amount = uint64(amount)
+ } else if amount, ok := slice[1].(uint64); ok {
+ c.amount = amount
}
if root, ok := slice[2].([]uint8); ok {
@@ -38,3 +44,38 @@ func (c *Contract) UnmarshalRlp(data []byte) {
}
}
}
+
+type Ether struct {
+ t uint32
+ amount uint64
+ nonce string
+}
+
+func NewEtherFromData(data []byte) *Ether {
+ ether := &Ether{}
+ ether.UnmarshalRlp(data)
+
+ return ether
+}
+
+func (e *Ether) MarshalRlp() []byte {
+ return Encode([]interface{}{e.t, e.amount, e.nonce})
+}
+
+func (e *Ether) UnmarshalRlp(data []byte) {
+ t, _ := Decode(data, 0)
+
+ if slice, ok := t.([]interface{}); ok {
+ if t, ok := slice[0].(uint8); ok {
+ e.t = uint32(t)
+ }
+
+ if amount, ok := slice[1].(uint8); ok {
+ e.amount = uint64(amount)
+ }
+
+ if nonce, ok := slice[2].([]uint8); ok {
+ e.nonce = string(nonce)
+ }
+ }
+}