SetAccount() upserts an account into the state
(account *Account)
| 82 | |
| 83 | // SetAccount() upserts an account into the state |
| 84 | func (s *StateMachine) SetAccount(account *Account) lib.ErrorI { |
| 85 | // add to cache |
| 86 | s.cache.accounts[lib.MemHash(account.Address)] = account |
| 87 | // convert bytes to the address object |
| 88 | address := crypto.NewAddressFromBytes(account.Address) |
| 89 | // if the amount is 0, delete the account from state to prevent unnecessary bloat |
| 90 | if account.Amount == 0 { |
| 91 | return s.Delete(KeyForAccount(address)) |
| 92 | } |
| 93 | // convert the account into bytes |
| 94 | bz, err := s.marshalAccount(account) |
| 95 | if err != nil { |
| 96 | return err |
| 97 | } |
| 98 | // set the account into state using the 'prefixed' key for the account |
| 99 | if err = s.Set(KeyForAccount(address), bz); err != nil { |
| 100 | return err |
| 101 | } |
| 102 | return nil |
| 103 | } |
| 104 | |
| 105 | // SetAccount() upserts multiple accounts into the state |
| 106 | func (s *StateMachine) SetAccounts(accounts []*Account, supply *Supply) (err lib.ErrorI) { |