* This file defines the account, pool, and supply tracker state interactions */ GetAccount() returns an Account structure for a specific address
(address crypto.AddressI)
| 14 | |
| 15 | // GetAccount() returns an Account structure for a specific address |
| 16 | func (s *StateMachine) GetAccount(address crypto.AddressI) (*Account, lib.ErrorI) { |
| 17 | // check cache |
| 18 | if acc, found := s.cache.accounts[lib.MemHash(address.Bytes())]; found { |
| 19 | return acc, nil |
| 20 | } |
| 21 | // retrieve the account from the state store |
| 22 | bz, err := s.Get(KeyForAccount(address)) |
| 23 | if err != nil { |
| 24 | return nil, err |
| 25 | } |
| 26 | // convert the account bytes into a structure |
| 27 | acc, err := s.unmarshalAccount(bz) |
| 28 | if err != nil { |
| 29 | return nil, err |
| 30 | } |
| 31 | // convert the address into bytes and set it |
| 32 | acc.Address = address.Bytes() |
| 33 | return acc, nil |
| 34 | } |
| 35 | |
| 36 | // GetAccounts() returns all Account structures in the state |
| 37 | func (s *StateMachine) GetAccounts() (result []*Account, err lib.ErrorI) { |