forked from cerc-io/plugeth
Renamed Address to Account
This commit is contained in:
parent
bfed1c7cac
commit
9d492b0509
@ -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
|
||||
}
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
@ -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()))
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user