"fmt"
"sort"
+ acc "github.com/vapor/account"
"github.com/vapor/asset"
"github.com/vapor/blockchain/query"
"github.com/vapor/blockchain/signers"
}
}
-// // GetRawProgram get raw program by hash
-// func (store *WalletStore) GetRawProgram(hash common.Hash) ([]byte, error) {
-// rawProgram := store.walletDB.Get(ContractKey(hash))
-// if rawProgram == nil {
-// return nil, fmt.Errorf("failed get account control program:%x ", hash)
-// }
-
-// accountCP := new(account.CtrlProgram)
-// if err := json.Unmarshal(rawProgram, &accountCP); err != nil {
-// return nil, err
-// }
-// return accountCP, nil
-// }
-
-// GetRawProgram get raw program by hash
-func (store *WalletStore) GetRawProgram(hash common.Hash) []byte {
- return store.walletDB.Get(ContractKey(hash))
+// GetControlProgram get raw program by hash
+func (store *WalletStore) GetControlProgram(hash common.Hash) (*acc.CtrlProgram, error) {
+ rawProgram := store.walletDB.Get(ContractKey(hash))
+ if rawProgram == nil {
+ return nil, fmt.Errorf("failed get account control program:%x ", hash)
+ }
+ accountCP := new(acc.CtrlProgram)
+ if err := json.Unmarshal(rawProgram, &accountCP); err != nil {
+ return nil, err
+ }
+ return accountCP, nil
}
// GetAccountByAccountID get account value by account ID
func getAccountFromACP(program []byte, store WalletStorer) (*account.Account, error) {
var hash common.Hash
- accountCP := account.CtrlProgram{}
localAccount := account.Account{}
sha3pool.Sum256(hash[:], program)
- rawProgram := store.GetRawProgram(hash)
- if rawProgram == nil {
- return nil, fmt.Errorf("failed get account control program:%x ", hash)
- }
-
- if err := json.Unmarshal(rawProgram, &accountCP); err != nil {
+ accountCP, err := store.GetControlProgram(hash)
+ if err != nil {
return nil, err
}
+ if accountCP == nil {
+ return nil, fmt.Errorf("failed get account control program:%x ", hash)
+ }
accountValue := store.GetAccountByAccountID(accountCP.AccountID)
if accountValue == nil {
var hash [32]byte
sha3pool.Sum256(hash[:], v.ControlProgram())
- if bytes := w.store.GetRawProgram(hash); bytes != nil {
+ cp, err := w.store.GetControlProgram(hash)
+ if err != nil {
+ log.WithFields(log.Fields{"module": logModule, "err": err, "hash": string(hash[:])}).Error("filterAccountTxs fail.")
+ continue
+ }
+ if cp != nil {
annotatedTxs = append(annotatedTxs, w.buildAnnotatedTransaction(tx, b, statusFail, pos))
continue transactionLoop
}
package wallet
import (
+ acc "github.com/vapor/account"
"github.com/vapor/asset"
"github.com/vapor/blockchain/query"
"github.com/vapor/common"
CommitBatch()
GetAssetDefinition(*bc.AssetID) (*asset.Asset, error)
SetAssetDefinition(*bc.AssetID, []byte)
- GetRawProgram(common.Hash) []byte
+ GetControlProgram(hash common.Hash) (*acc.CtrlProgram, error)
GetAccountByAccountID(string) []byte
DeleteTransactions(uint64)
SetTransaction(uint64, uint32, string, []byte)
for _, v := range tx.Outputs {
var hash [32]byte
sha3pool.Sum256(hash[:], v.ControlProgram())
- if bytes := w.store.GetRawProgram(hash); bytes != nil {
+ cp, err := w.store.GetControlProgram(hash)
+ if err != nil {
+ log.WithFields(log.Fields{"module": logModule, "err": err, "hash": string(hash[:])}).Error("checkRelatedTransaction fail.")
+ continue
+ }
+ if cp != nil {
return true
}
}
var hash [32]byte
sha3pool.Sum256(hash[:], []byte(s))
- data := w.store.GetRawProgram(hash)
- if data == nil {
+ cp, err := w.store.GetControlProgram(hash)
+ if err != nil {
+ log.WithFields(log.Fields{"module": logModule, "err": err}).Error("filterAccountUtxo fail.")
continue
}
-
- cp := &account.CtrlProgram{}
- if err := json.Unmarshal(data, cp); err != nil {
- log.WithFields(log.Fields{"module": logModule, "err": err}).Error("filterAccountUtxo fail on unmarshal control program")
+ if cp == nil {
continue
}