From: Chengcheng Zhang <943420582@qq.com> Date: Tue, 2 Jul 2019 14:08:52 +0000 (+0800) Subject: update X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=c52e4cb7f7caddc910db09a2819293ce851e9436;p=bytom%2Fvapor.git update --- diff --git a/wallet/annotated.go b/wallet/annotated.go index 3a956d34..b6b9290f 100644 --- a/wallet/annotated.go +++ b/wallet/annotated.go @@ -70,14 +70,14 @@ func (w *Wallet) getAliasDefinition(assetID bc.AssetID) (string, json.RawMessage } // annotateTxs adds account data to transactions -func annotateTxsAccount(txs []*query.AnnotatedTx, store WalletStore) { +func (w *Wallet) annotateTxsAccount(txs []*query.AnnotatedTx) { for i, tx := range txs { for j, input := range tx.Inputs { //issue asset tx input SpentOutputID is nil if input.SpentOutputID == nil { continue } - localAccount, err := getAccountFromACP(input.ControlProgram, store) + localAccount, err := w.getAccountFromACP(input.ControlProgram) if localAccount == nil || err != nil { continue } @@ -85,7 +85,7 @@ func annotateTxsAccount(txs []*query.AnnotatedTx, store WalletStore) { txs[i].Inputs[j].AccountID = localAccount.ID } for j, output := range tx.Outputs { - localAccount, err := getAccountFromACP(output.ControlProgram, store) + localAccount, err := w.getAccountFromACP(output.ControlProgram) if localAccount == nil || err != nil { continue } @@ -95,18 +95,19 @@ func annotateTxsAccount(txs []*query.AnnotatedTx, store WalletStore) { } } -func getAccountFromACP(program []byte, store WalletStore) (*account.Account, error) { +func (w *Wallet) getAccountFromACP(program []byte) (*account.Account, error) { var hash [32]byte sha3pool.Sum256(hash[:], program) - accountCP, err := store.GetControlProgram(bc.NewHash(hash)) + accountCP, err := w.store.GetControlProgram(bc.NewHash(hash)) if err != nil { return nil, err } - account, err := store.GetAccount(accountCP.AccountID) + account, err := w.AccountMgr.FindByID(accountCP.AccountID) if err != nil { return nil, err } + return account, nil } diff --git a/wallet/unconfirmed.go b/wallet/unconfirmed.go index eff8a5c1..8e58ec43 100644 --- a/wallet/unconfirmed.go +++ b/wallet/unconfirmed.go @@ -149,7 +149,7 @@ func (w *Wallet) saveUnconfirmedTx(tx *types.Tx) error { annotatedTx := w.buildAnnotatedUnconfirmedTx(tx) annotatedTxs := []*query.AnnotatedTx{} annotatedTxs = append(annotatedTxs, annotatedTx) - annotateTxsAccount(annotatedTxs, w.store) + w.annotateTxsAccount(annotatedTxs) if err := w.store.SetUnconfirmedTransaction(tx.ID.String(), annotatedTxs[0]); err != nil { return err diff --git a/wallet/unconfirmed_test.go b/wallet/unconfirmed_test.go index 2abdff10..9b4906ed 100644 --- a/wallet/unconfirmed_test.go +++ b/wallet/unconfirmed_test.go @@ -129,7 +129,7 @@ func AnnotatedTxs(txs []*types.Tx, w *Wallet) []*query.AnnotatedTx { annotatedTxs = append(annotatedTxs, annotatedTx) } - annotateTxsAccount(annotatedTxs, w.store) + w.annotateTxsAccount(annotatedTxs) annotateTxsAsset(w, annotatedTxs) return annotatedTxs diff --git a/wallet/wallet.go b/wallet/wallet.go index 1aed9029..d3e06850 100644 --- a/wallet/wallet.go +++ b/wallet/wallet.go @@ -190,7 +190,7 @@ func (w *Wallet) AttachBlock(block *types.Block) error { if err := saveExternalAssetDefinition(block, w.store); err != nil { return err } - annotateTxsAccount(annotatedTxs, w.store) + w.annotateTxsAccount(annotatedTxs) if err := w.store.InitBatch(); err != nil { return err