Skip to content

Commit

Permalink
Remove tempIDs while removing a wallet
Browse files Browse the repository at this point in the history
  • Loading branch information
daria305 committed Apr 17, 2024
1 parent e541c25 commit 3052423
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 4 additions & 1 deletion pkg/evilwallet/evilwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,10 @@ func (e *EvilWallet) useFreshIfInputWalletNotProvided(buildOptions *Options) (*W
}
}

w, err := e.wallets.freshWallet()
deleteTempIDFunc := func(tempID models.TempOutputID) {
e.outputManager.ClearTempIDs(tempID)
}
w, err := e.wallets.freshWallet(deleteTempIDFunc)
if err != nil {
return nil, ierrors.Wrap(err, "no Fresh wallet is available")
}
Expand Down
15 changes: 12 additions & 3 deletions pkg/evilwallet/wallets.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package evilwallet
import (
"go.uber.org/atomic"

"github.com/iotaledger/evil-tools/pkg/models"
"github.com/iotaledger/hive.go/ds/shrinkingmap"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/runtime/syncutils"
Expand Down Expand Up @@ -117,7 +118,7 @@ func (w *Wallets) isFaucetWalletAvailable() bool {

// freshWallet returns the first non-empty wallet from the faucetWallets queue. If current wallet is empty,
// it is removed and the next enqueued one is returned.
func (w *Wallets) freshWallet() (*Wallet, error) {
func (w *Wallets) freshWallet(deleteTempIDFunc func(tempID models.TempOutputID)) (*Wallet, error) {
w.mu.Lock()
defer w.mu.Unlock()

Expand All @@ -127,7 +128,7 @@ func (w *Wallets) freshWallet() (*Wallet, error) {

wallet := lo.Return1(w.wallets.Get(w.faucetWallets[0]))
if wallet.IsEmpty() {
w.removeFreshWallet()
w.removeFreshWallet(deleteTempIDFunc)
if !w.isFaucetWalletAvailable() {
return nil, NoFreshOutputsAvailable
}
Expand Down Expand Up @@ -161,8 +162,16 @@ func (w *Wallets) reuseWallet(outputsNeeded int) *Wallet {
}

// removeWallet removes wallet, for Fresh wallet it will be the first wallet in a queue.
func (w *Wallets) removeFreshWallet() {
func (w *Wallets) removeFreshWallet(deleteTempIDFunc func(tempID models.TempOutputID)) {
removedID := w.faucetWallets[0]
wallet, exists := w.wallets.Get(removedID)
if exists {
for _, out := range wallet.UnspentOutputs() {
deleteTempIDFunc(out.TempID)
}
wallet.Clear()
}

w.faucetWallets = w.faucetWallets[1:]
w.wallets.Delete(removedID)
}
Expand Down

0 comments on commit 3052423

Please sign in to comment.