diff --git a/accountwallet/faucet.go b/accountwallet/faucet.go index 743bd66..2ab321a 100644 --- a/accountwallet/faucet.go +++ b/accountwallet/faucet.go @@ -8,6 +8,7 @@ import ( "github.com/mr-tron/base58" "github.com/iotaledger/evil-tools/models" + "github.com/iotaledger/evil-tools/utils" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" "github.com/iotaledger/iota-core/pkg/blockhandler" @@ -45,32 +46,9 @@ func (a *AccountWallet) RequestFaucetFunds(clt models.Client, receiveAddr iotago return nil, ierrors.Wrap(err, "failed to request funds from faucet") } - indexer, err := clt.Indexer() - if err != nil { - return nil, ierrors.Wrap(err, "failed to get indexer client") - } - - addrBech := receiveAddr.Bech32(clt.CommittedAPI().ProtocolParameters().Bech32HRP()) - - time.Sleep(10 * time.Second) - - res, err := indexer.Outputs(context.Background(), &apimodels.BasicOutputsQuery{ - AddressBech32: addrBech, - }) + outputID, outputStruct, err := utils.AwaitAddressUnspentOutputToBeAccepted(clt, receiveAddr, 10*time.Second) if err != nil { - return nil, ierrors.Wrap(err, "indexer request failed in request faucet funds") - } - - var outputStruct iotago.Output - var outputID iotago.OutputID - for res.Next() { - unspents, err := res.Outputs(context.TODO()) - if err != nil { - return nil, ierrors.Wrap(err, "failed to get faucet unspent outputs") - } - - outputStruct = unspents[0] - outputID = lo.Return1(res.Response.Items.OutputIDs())[0] + return nil, ierrors.Wrap(err, "failed to await faucet funds") } return &models.Output{ diff --git a/evilwallet/evilwallet.go b/evilwallet/evilwallet.go index fd2e796..4621fb6 100644 --- a/evilwallet/evilwallet.go +++ b/evilwallet/evilwallet.go @@ -8,6 +8,7 @@ import ( "github.com/iotaledger/evil-tools/accountwallet" evillogger "github.com/iotaledger/evil-tools/logger" "github.com/iotaledger/evil-tools/models" + "github.com/iotaledger/evil-tools/utils" "github.com/iotaledger/hive.go/ds/types" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" @@ -285,7 +286,7 @@ func (e *EvilWallet) requestFaucetFunds(wallet *Wallet) (output *models.Output, return nil, ierrors.Wrap(err, "failed to request funds from faucet") } - outputID, iotaOutput, err := AwaitAddressUnspentOutputToBeAccepted(clt, receiveAddr, 10*time.Second) + outputID, iotaOutput, err := utils.AwaitAddressUnspentOutputToBeAccepted(clt, receiveAddr, 10*time.Second) if err != nil { return nil, ierrors.Wrap(err, "failed to await faucet output acceptance") } @@ -371,7 +372,7 @@ func (e *EvilWallet) splitOutputs(inputWallet, outputWallet *Wallet) ([]iotago.T } func (e *EvilWallet) createSplitOutputs(input *models.Output, splitNumber int, receiveWallet *Wallet) []*OutputOption { - balances := SplitBalanceEqually(splitNumber, input.Balance) + balances := utils.SplitBalanceEqually(splitNumber, input.Balance) outputs := make([]*OutputOption, splitNumber) for i, bal := range balances { outputs[i] = &OutputOption{amount: bal, address: receiveWallet.Address(), outputType: iotago.OutputBasic} @@ -744,7 +745,7 @@ func (e *EvilWallet) updateOutputBalances(buildOptions *Options) (err error) { totalBalance += in.Balance } } - balances := SplitBalanceEqually(len(buildOptions.outputs)+len(buildOptions.aliasOutputs), totalBalance) + balances := utils.SplitBalanceEqually(len(buildOptions.outputs)+len(buildOptions.aliasOutputs), totalBalance) i := 0 for out, output := range buildOptions.aliasOutputs { switch output.Type() { diff --git a/evilwallet/output_manager.go b/evilwallet/output_manager.go index e371c48..d27c68f 100644 --- a/evilwallet/output_manager.go +++ b/evilwallet/output_manager.go @@ -7,6 +7,7 @@ import ( "go.uber.org/atomic" "github.com/iotaledger/evil-tools/models" + "github.com/iotaledger/evil-tools/utils" "github.com/iotaledger/hive.go/ds/types" "github.com/iotaledger/hive.go/logger" "github.com/iotaledger/hive.go/runtime/syncutils" @@ -116,7 +117,7 @@ func (o *OutputManager) Track(outputIDs ...iotago.OutputID) (allConfirmed bool) go func(id iotago.OutputID, clt models.Client) { defer wg.Done() - if !AwaitOutputToBeAccepted(clt, id, awaitOutputToBeConfirmed) { + if !utils.AwaitOutputToBeAccepted(clt, id, awaitOutputToBeConfirmed) { unconfirmedOutputFound.Store(true) } }(ID, o.connector.GetClient()) @@ -238,7 +239,7 @@ func (o *OutputManager) AwaitTransactionsAcceptance(txIDs ...iotago.TransactionI defer func() { <-semaphore }() - err := AwaitTransactionToBeAccepted(clt, txID, waitForAcceptance, txLeft) + err := utils.AwaitTransactionToBeAccepted(clt, txID, waitForAcceptance, txLeft) txLeft.Dec() if err != nil { o.log.Errorf("Error awaiting transaction %s to be accepted: %s", txID.String(), err) diff --git a/go.mod b/go.mod index 34bf2fc..4367fdc 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,6 @@ require ( github.com/AlecAivazis/survey/v2 v2.3.7 github.com/google/martian v2.1.0+incompatible github.com/iotaledger/hive.go/app v0.0.0-20231020115340-13da292c580b - github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231020115340-13da292c580b github.com/iotaledger/hive.go/ds v0.0.0-20231020115340-13da292c580b github.com/iotaledger/hive.go/ierrors v0.0.0-20231024193930-47c6046e38a8 github.com/iotaledger/hive.go/lo v0.0.0-20231020115340-13da292c580b @@ -40,6 +39,7 @@ require ( github.com/iotaledger/grocksdb v1.7.5-0.20230220105546-5162e18885c7 // indirect github.com/iotaledger/hive.go/ads v0.0.0-20231020115340-13da292c580b // indirect github.com/iotaledger/hive.go/constraints v0.0.0-20231020115340-13da292c580b // indirect + github.com/iotaledger/hive.go/core v1.0.0-rc.3.0.20231020115340-13da292c580b // indirect github.com/iotaledger/hive.go/crypto v0.0.0-20231020115340-13da292c580b // indirect github.com/iotaledger/hive.go/kvstore v0.0.0-20231020115340-13da292c580b // indirect github.com/iotaledger/hive.go/log v0.0.0-20231020115340-13da292c580b // indirect diff --git a/spammer/spamming_functions.go b/spammer/spamming_functions.go index 6e3733f..17dd7ba 100644 --- a/spammer/spamming_functions.go +++ b/spammer/spamming_functions.go @@ -5,8 +5,8 @@ import ( "sync" "time" - "github.com/iotaledger/evil-tools/evilwallet" "github.com/iotaledger/evil-tools/models" + "github.com/iotaledger/evil-tools/utils" "github.com/iotaledger/hive.go/ierrors" "github.com/iotaledger/hive.go/lo" iotago "github.com/iotaledger/iota.go/v4" @@ -138,7 +138,7 @@ func createBlowBallCenter(s *Spammer) (iotago.BlockID, error) { }, }, s.IssuerAlias, clt) - err := evilwallet.AwaitBlockToBeConfirmed(clt, centerID, 30*time.Second) + err := utils.AwaitBlockToBeConfirmed(clt, centerID, 30*time.Second) return centerID, err } diff --git a/evilwallet/utils.go b/utils/utils.go similarity index 95% rename from evilwallet/utils.go rename to utils/utils.go index 11181af..194a376 100644 --- a/evilwallet/utils.go +++ b/utils/utils.go @@ -1,4 +1,4 @@ -package evilwallet +package utils import ( "context" @@ -15,6 +15,11 @@ import ( var UtilsLogger = evillogger.New("Utils") +const ( + waitForAcceptance = 20 * time.Second + awaitAcceptationSleep = 1 * time.Second +) + // SplitBalanceEqually splits the balance equally between `splitNumber` outputs. func SplitBalanceEqually(splitNumber int, balance iotago.BaseToken) []iotago.BaseToken { outputBalances := make([]iotago.BaseToken, 0) @@ -92,7 +97,7 @@ func AwaitTransactionToBeAccepted(clt models.Client, txID iotago.TransactionID, return nil } -func AwaitAddressUnspentOutputToBeAccepted(clt models.Client, addr *iotago.Ed25519Address, waitFor time.Duration) (outputID iotago.OutputID, output iotago.Output, err error) { +func AwaitAddressUnspentOutputToBeAccepted(clt models.Client, addr iotago.Address, waitFor time.Duration) (outputID iotago.OutputID, output iotago.Output, err error) { indexer, err := clt.Indexer() if err != nil { return iotago.EmptyOutputID, nil, ierrors.Wrap(err, "failed to get indexer client")