}
// GetAccountByAccountID get account value by account ID
-func (store *WalletStore) GetAccountByAccountID(accountID string) []byte {
- return store.walletDB.Get(AccountIDKey(accountID))
+func (store *WalletStore) GetAccountByAccountID(accountID string) (*acc.Account, error) {
+ rawAccount := store.walletDB.Get(AccountIDKey(accountID))
+ if rawAccount == nil {
+ return nil, fmt.Errorf("failed get account, accountID: %s ", accountID)
+ }
+ account := new(acc.Account)
+ if err := json.Unmarshal(rawAccount, account); err != nil {
+ return nil, err
+ }
+ return account, nil
}
// DeleteTransactions delete transactions when orphan block rollback
func getAccountFromACP(program []byte, store WalletStorer) (*account.Account, error) {
var hash common.Hash
- localAccount := account.Account{}
sha3pool.Sum256(hash[:], program)
accountCP, err := store.GetControlProgram(hash)
return nil, fmt.Errorf("failed get account control program:%x ", hash)
}
- accountValue := store.GetAccountByAccountID(accountCP.AccountID)
- if accountValue == nil {
- return nil, fmt.Errorf("failed get account:%s ", accountCP.AccountID)
- }
-
- if err := json.Unmarshal(accountValue, &localAccount); err != nil {
+ account, err := store.GetAccountByAccountID(accountCP.AccountID)
+ if err != nil {
return nil, err
}
-
- return &localAccount, nil
+ if account == nil {
+ return nil, fmt.Errorf("failed get account:%s ", accountCP.AccountID)
+ }
+ return account, nil
}
var emptyJSONObject = json.RawMessage(`{}`)
CommitBatch()
GetAssetDefinition(*bc.AssetID) (*asset.Asset, error)
SetAssetDefinition(*bc.AssetID, []byte)
- GetControlProgram(hash common.Hash) (*acc.CtrlProgram, error)
- GetAccountByAccountID(string) []byte
+ GetControlProgram(common.Hash) (*acc.CtrlProgram, error)
+ GetAccountByAccountID(string) (*acc.Account, error)
DeleteTransactions(uint64)
SetTransaction(uint64, uint32, string, []byte)
DeleteUnconfirmedTransaction(string)