MCPcopy
hub / github.com/canopy-network/canopy / SetAccount

Method SetAccount

fsm/account.go:84–103  ·  view source on GitHub ↗

SetAccount() upserts an account into the state

(account *Account)

Source from the content-addressed store, hash-verified

82
83// SetAccount() upserts an account into the state
84func (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
106func (s *StateMachine) SetAccounts(accounts []*Account, supply *Supply) (err lib.ErrorI) {

Callers 11

SetAccountsMethod · 0.95
AccountAddMethod · 0.95
AccountSubMethod · 0.95
TestSetGetAccountFunction · 0.80
TestGetAccountsPaginatedFunction · 0.80
TestAccountDeductFeesFunction · 0.80
TestAccountAddFunction · 0.80
TestAccountSubFunction · 0.80
newDexChainFunction · 0.80

Calls 6

DeleteMethod · 0.95
marshalAccountMethod · 0.95
SetMethod · 0.95
MemHashFunction · 0.92
NewAddressFromBytesFunction · 0.92
KeyForAccountFunction · 0.70

Tested by 8

TestSetGetAccountFunction · 0.64
TestGetAccountsPaginatedFunction · 0.64
TestAccountDeductFeesFunction · 0.64
TestAccountAddFunction · 0.64
TestAccountSubFunction · 0.64
newDexChainFunction · 0.64