// deleteAccountUtxos deletes utxos matching accountID
func (m *Manager) deleteAccountUtxos(accountID string) error {
- rawUTXOs := m.store.GetAccountUTXOs(accountID)
-
- for _, rawUTXO := range rawUTXOs {
- utxo := new(UTXO)
- if err := json.Unmarshal(rawUTXO, utxo); err != nil {
- return err
- }
- if accountID == utxo.AccountID {
- m.store.DeleteStandardUTXO(utxo.OutputID)
- }
+ if err := m.store.DeleteAccountUTXOs(accountID); err != nil {
+ return err
}
-
return nil
}
DeleteBip44ContractIndex(string)
DeleteContractIndex(string)
GetContractIndex(string) uint64
- GetAccountUTXOs(string) [][]byte
+ DeleteAccountUTXOs(string) error
DeleteStandardUTXO(bc.Hash)
GetCoinbaseArbitrary() []byte
SetCoinbaseArbitrary([]byte)
return index
}
-// GetAccountUTXOs get account utxos by account id
-func (store *AccountStore) GetAccountUTXOs(accountID string) [][]byte {
+// DeleteStandardUTXO delete utxo by outpu id
+func (store *AccountStore) DeleteStandardUTXO(outputID bc.Hash) {
+ if store.batch == nil {
+ store.accountDB.Delete(StandardUTXOKey(outputID))
+ } else {
+ store.batch.Delete(StandardUTXOKey(outputID))
+ }
+}
+
+// DeleteAccountUTXOs delete account utxos by accountID
+func (store *AccountStore) DeleteAccountUTXOs(accountID string) error {
+ batch := store.accountDB.NewBatch()
+ if store.batch != nil {
+ batch = store.batch
+ }
+
accountUtxoIter := store.accountDB.IteratorPrefix([]byte(UTXOPrefix))
defer accountUtxoIter.Release()
- utxos := make([][]byte, 0)
for accountUtxoIter.Next() {
- utxos = append(utxos, accountUtxoIter.Value())
+ accountUtxo := &acc.UTXO{}
+ if err := json.Unmarshal(accountUtxoIter.Value(), accountUtxo); err != nil {
+ return err
+ }
+ if accountID == accountUtxo.AccountID {
+ batch.Delete(StandardUTXOKey(accountUtxo.OutputID))
+ }
}
- return utxos
-}
-// DeleteStandardUTXO delete utxo by outpu id
-func (store *AccountStore) DeleteStandardUTXO(outputID bc.Hash) {
if store.batch == nil {
- store.accountDB.Delete(StandardUTXOKey(outputID))
- } else {
- store.batch.Delete(StandardUTXOKey(outputID))
+ batch.Write()
}
+ return nil
}
// GetCoinbaseArbitrary get coinbase arbitrary