OSDN Git Service

finish wallet
[bytom/vapor.git] / wallet / utxo.go
index 3c172ff..78b6e0f 100644 (file)
@@ -26,8 +26,18 @@ func (w *Wallet) GetAccountUtxos(accountID string, id string, unconfirmed, isSma
                accountUtxos = w.AccountMgr.ListUnconfirmedUtxo(accountID, isSmartContract)
        }
 
-       confirmedUtxos := w.store.GetAccountUtxos(prefix + id)
-       accountUtxos = append(accountUtxos, confirmedUtxos...)
+       rawConfirmedUTXOs := w.store.GetAccountUTXOs(prefix + id)
+       confirmedUTXOs := []*account.UTXO{}
+       for _, rawConfirmedUTXO := range rawConfirmedUTXOs {
+               confirmedUTXO := new(account.UTXO)
+               if err := json.Unmarshal(rawConfirmedUTXO, confirmedUTXO); err != nil {
+                       log.WithFields(log.Fields{"module": logModule, "err": err}).Warn("GetAccountUTXOs fail on unmarshal utxo")
+                       continue
+               }
+               confirmedUTXOs = append(confirmedUTXOs, confirmedUTXO)
+       }
+       accountUtxos = append(accountUtxos, confirmedUTXOs...)
+
        newAccountUtxos := []*account.UTXO{}
        for _, accountUtxo := range accountUtxos {
                if vote && accountUtxo.Vote == nil {
@@ -53,9 +63,9 @@ func (w *Wallet) attachUtxos(b *types.Block, txStatus *bc.TransactionStatus) {
                inputUtxos := txInToUtxos(tx, statusFail)
                for _, inputUtxo := range inputUtxos {
                        if segwit.IsP2WScript(inputUtxo.ControlProgram) {
-                               w.store.DeleteStardardUTXOByOutputID(inputUtxo.OutputID)
+                               w.store.DeleteStardardUTXO(inputUtxo.OutputID)
                        } else {
-                               w.store.DeleteContractUTXOByOutputID(inputUtxo.OutputID)
+                               w.store.DeleteContractUTXO(inputUtxo.OutputID)
                        }
                }
 
@@ -63,7 +73,7 @@ func (w *Wallet) attachUtxos(b *types.Block, txStatus *bc.TransactionStatus) {
                outputUtxos := txOutToUtxos(tx, statusFail, b.Height)
                utxos := w.filterAccountUtxo(outputUtxos)
                if err := w.saveUtxos(utxos); err != nil {
-                       log.WithFields(log.Fields{"module": logModule, "err": err}).Error("attachUtxos fail on batchSaveUtxos")
+                       log.WithFields(log.Fields{"module": logModule, "err": err}).Error("attachUtxos fail on saveUtxos")
                }
        }
 }
@@ -83,9 +93,9 @@ func (w *Wallet) detachUtxos(b *types.Block, txStatus *bc.TransactionStatus) {
                        }
 
                        if segwit.IsP2WScript(code) {
-                               w.store.DeleteStardardUTXOByOutputID(*tx.ResultIds[j])
+                               w.store.DeleteStardardUTXO(*tx.ResultIds[j])
                        } else {
-                               w.store.DeleteContractUTXOByOutputID(*tx.ResultIds[j])
+                               w.store.DeleteContractUTXO(*tx.ResultIds[j])
                        }
                }
 
@@ -122,7 +132,7 @@ func (w *Wallet) filterAccountUtxo(utxos []*account.UTXO) []*account.UTXO {
 
                var hash [32]byte
                sha3pool.Sum256(hash[:], []byte(s))
-               data := w.store.GetRawProgramByAccountHash(hash)
+               data := w.store.GetRawProgram(hash)
                if data == nil {
                        continue
                }