aboutsummaryrefslogtreecommitdiffstats
path: root/ethchain/address.go
diff options
context:
space:
mode:
authorobscuren <geffobscura@gmail.com>2014-02-23 08:56:48 +0800
committerobscuren <geffobscura@gmail.com>2014-02-23 08:56:48 +0800
commitc66cf95b4019eeaf49db0c02cc7cb73c78098f5e (patch)
tree3a2d71c6cb493b84af463d2870a2afd4df18e049 /ethchain/address.go
parent73b9ae95797ce8c38d82cfcb7c793efea268f476 (diff)
downloaddexon-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.gz
dexon-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.tar.zst
dexon-c66cf95b4019eeaf49db0c02cc7cb73c78098f5e.zip
Added address states for storing a session based address
Diffstat (limited to 'ethchain/address.go')
-rw-r--r--ethchain/address.go60
1 files changed, 60 insertions, 0 deletions
diff --git a/ethchain/address.go b/ethchain/address.go
new file mode 100644
index 000000000..a228c7566
--- /dev/null
+++ b/ethchain/address.go
@@ -0,0 +1,60 @@
+package ethchain
+
+import (
+ "github.com/ethereum/eth-go/ethutil"
+ "math/big"
+)
+
+type Address struct {
+ Amount *big.Int
+ Nonce uint64
+}
+
+func NewAddress(amount *big.Int) *Address {
+ return &Address{Amount: amount, Nonce: 0}
+}
+
+func NewAddressFromData(data []byte) *Address {
+ address := &Address{}
+ address.RlpDecode(data)
+
+ return address
+}
+
+func (a *Address) AddFee(fee *big.Int) {
+ a.Amount.Add(a.Amount, fee)
+}
+
+func (a *Address) RlpEncode() []byte {
+ return ethutil.Encode([]interface{}{a.Amount, a.Nonce})
+}
+
+func (a *Address) RlpDecode(data []byte) {
+ decoder := ethutil.NewValueFromBytes(data)
+
+ a.Amount = decoder.Get(0).BigInt()
+ a.Nonce = decoder.Get(1).Uint()
+}
+
+type AddrStateStore struct {
+ states map[string]*AddressState
+}
+
+func NewAddrStateStore() *AddrStateStore {
+ return &AddrStateStore{states: make(map[string]*AddressState)}
+}
+
+func (s *AddrStateStore) Add(addr []byte, account *Address) *AddressState {
+ state := &AddressState{Nonce: account.Nonce, Account: account}
+ s.states[string(addr)] = state
+ return state
+}
+
+func (s *AddrStateStore) Get(addr []byte) *AddressState {
+ return s.states[string(addr)]
+}
+
+type AddressState struct {
+ Nonce uint64
+ Account *Address
+}