OSDN Git Service

update
authorChengcheng Zhang <943420582@qq.com>
Tue, 2 Jul 2019 14:08:52 +0000 (22:08 +0800)
committerChengcheng Zhang <943420582@qq.com>
Tue, 2 Jul 2019 14:08:52 +0000 (22:08 +0800)
wallet/annotated.go
wallet/unconfirmed.go
wallet/unconfirmed_test.go
wallet/wallet.go

index 3a956d3..b6b9290 100644 (file)
@@ -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
 }
 
index eff8a5c..8e58ec4 100644 (file)
@@ -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
index 2abdff1..9b4906e 100644 (file)
@@ -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
index 1aed902..d3e0685 100644 (file)
@@ -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