diff options
author | obscuren <geffobscura@gmail.com> | 2014-03-03 18:05:12 +0800 |
---|---|---|
committer | obscuren <geffobscura@gmail.com> | 2014-03-03 18:05:12 +0800 |
commit | 9d492b0509d3614072e0f9ed9fd1dc560ba29fc9 (patch) | |
tree | baf8e50b664cc64e6e8d45a234922aacbc14c860 | |
parent | bfed1c7cac98e135ba176c03bd7b4fe51c0dc932 (diff) | |
download | dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar.gz dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar.bz2 dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar.lz dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar.xz dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.tar.zst dexon-9d492b0509d3614072e0f9ed9fd1dc560ba29fc9.zip |
Renamed Address to Account
-rw-r--r-- | ethchain/address.go | 30 | ||||
-rw-r--r-- | ethchain/block.go | 2 | ||||
-rw-r--r-- | ethchain/block_manager.go | 6 | ||||
-rw-r--r-- | ethchain/state.go | 8 |
4 files changed, 23 insertions, 23 deletions
diff --git a/ethchain/address.go b/ethchain/address.go index a228c7566..aa1709f2c 100644 --- a/ethchain/address.go +++ b/ethchain/address.go @@ -5,31 +5,31 @@ import ( "math/big" ) -type Address struct { +type Account struct { Amount *big.Int Nonce uint64 } -func NewAddress(amount *big.Int) *Address { - return &Address{Amount: amount, Nonce: 0} +func NewAccount(amount *big.Int) *Account { + return &Account{Amount: amount, Nonce: 0} } -func NewAddressFromData(data []byte) *Address { - address := &Address{} +func NewAccountFromData(data []byte) *Account { + address := &Account{} address.RlpDecode(data) return address } -func (a *Address) AddFee(fee *big.Int) { +func (a *Account) AddFee(fee *big.Int) { a.Amount.Add(a.Amount, fee) } -func (a *Address) RlpEncode() []byte { +func (a *Account) RlpEncode() []byte { return ethutil.Encode([]interface{}{a.Amount, a.Nonce}) } -func (a *Address) RlpDecode(data []byte) { +func (a *Account) RlpDecode(data []byte) { decoder := ethutil.NewValueFromBytes(data) a.Amount = decoder.Get(0).BigInt() @@ -37,24 +37,24 @@ func (a *Address) RlpDecode(data []byte) { } type AddrStateStore struct { - states map[string]*AddressState + states map[string]*AccountState } func NewAddrStateStore() *AddrStateStore { - return &AddrStateStore{states: make(map[string]*AddressState)} + return &AddrStateStore{states: make(map[string]*AccountState)} } -func (s *AddrStateStore) Add(addr []byte, account *Address) *AddressState { - state := &AddressState{Nonce: account.Nonce, Account: account} +func (s *AddrStateStore) Add(addr []byte, account *Account) *AccountState { + state := &AccountState{Nonce: account.Nonce, Account: account} s.states[string(addr)] = state return state } -func (s *AddrStateStore) Get(addr []byte) *AddressState { +func (s *AddrStateStore) Get(addr []byte) *AccountState { return s.states[string(addr)] } -type AddressState struct { +type AccountState struct { Nonce uint64 - Account *Address + Account *Account } diff --git a/ethchain/block.go b/ethchain/block.go index b5739102c..20af73ba2 100644 --- a/ethchain/block.go +++ b/ethchain/block.go @@ -142,7 +142,7 @@ func (block *Block) PayFee(addr []byte, fee *big.Int) bool { data := block.state.trie.Get(string(block.Coinbase)) // Get the ether (Coinbase) and add the fee (gief fee to miner) - ether := NewAddressFromData([]byte(data)) + ether := NewAccountFromData([]byte(data)) base = new(big.Int) ether.Amount = base.Add(ether.Amount, fee) diff --git a/ethchain/block_manager.go b/ethchain/block_manager.go index 8ea71ab31..b184fa9c9 100644 --- a/ethchain/block_manager.go +++ b/ethchain/block_manager.go @@ -85,17 +85,17 @@ func NewBlockManager(speaker PublicSpeaker) *BlockManager { } // Watches any given address and puts it in the address state store -func (bm *BlockManager) WatchAddr(addr []byte) *AddressState { +func (bm *BlockManager) WatchAddr(addr []byte) *AccountState { account := bm.bc.CurrentBlock.state.GetAccount(addr) return bm.addrStateStore.Add(addr, account) } -func (bm *BlockManager) GetAddrState(addr []byte) *AddressState { +func (bm *BlockManager) GetAddrState(addr []byte) *AccountState { account := bm.addrStateStore.Get(addr) if account == nil { a := bm.bc.CurrentBlock.state.GetAccount(addr) - account = &AddressState{Nonce: a.Nonce, Account: a} + account = &AccountState{Nonce: a.Nonce, Account: a} } return account diff --git a/ethchain/state.go b/ethchain/state.go index 4cd2c58ef..e6649cf22 100644 --- a/ethchain/state.go +++ b/ethchain/state.go @@ -93,18 +93,18 @@ func Compile(code []string) (script []string) { return } -func (s *State) GetAccount(addr []byte) (account *Address) { +func (s *State) GetAccount(addr []byte) (account *Account) { data := s.trie.Get(string(addr)) if data == "" { - account = NewAddress(big.NewInt(0)) + account = NewAccount(big.NewInt(0)) } else { - account = NewAddressFromData([]byte(data)) + account = NewAccountFromData([]byte(data)) } return } -func (s *State) UpdateAccount(addr []byte, account *Address) { +func (s *State) UpdateAccount(addr []byte, account *Account) { s.trie.Update(string(addr), string(account.RlpEncode())) } |