From e09decb0e8852c7480920348682772cdc9fc7d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daria=20Dziuba=C5=82towska?= Date: Mon, 29 Jan 2024 12:00:59 +0100 Subject: [PATCH] URLs clean up --- components/accounts/component.go | 4 +++- components/info/component.go | 1 + components/spammer/component.go | 5 ++++- pkg/accountmanager/manager.go | 3 +++ pkg/evilwallet/evilwallet.go | 11 ++++++----- pkg/spammer/spammer.go | 5 ++--- programs/spammers.go | 9 +++++---- 7 files changed, 24 insertions(+), 14 deletions(-) diff --git a/components/accounts/component.go b/components/accounts/component.go index ca7e022..3d6dacf 100644 --- a/components/accounts/component.go +++ b/components/accounts/component.go @@ -38,7 +38,9 @@ func run() error { }), ) if err != nil { - Component.LogPanic(err.Error()) + Component.LogError(err.Error()) + + return err } accountsSubcommandsFlags := parseAccountCommands(getCommands(os.Args[2:]), ParamsAccounts) diff --git a/components/info/component.go b/components/info/component.go index ac1a71e..adeb921 100644 --- a/components/info/component.go +++ b/components/info/component.go @@ -33,6 +33,7 @@ func Run() error { if err != nil { return err } + err = info.Run(ParamsTool, ParamsInfo, logger) if err != nil { return err diff --git a/components/spammer/component.go b/components/spammer/component.go index abbf9f4..d33db6e 100644 --- a/components/spammer/component.go +++ b/components/spammer/component.go @@ -34,13 +34,16 @@ func run() error { }), ) if err != nil { - Component.LogPanic(err.Error()) + Component.LogErrorf(err.Error()) + + return err } programs.RunSpammer( Component.Daemon().ContextStopped(), Component.Logger, ParamsTool.NodeURLs, + ParamsTool.FaucetURL, ParamsSpammer, accWallet) diff --git a/pkg/accountmanager/manager.go b/pkg/accountmanager/manager.go index c464b5b..6986a25 100644 --- a/pkg/accountmanager/manager.go +++ b/pkg/accountmanager/manager.go @@ -78,6 +78,8 @@ func newManager(logger log.Logger, opts ...options.Option[Manager]) (*Manager, e err := m.setupClient() if err != nil { innerErr = err + + return } m.setupGenesisAccount() @@ -92,6 +94,7 @@ func (m *Manager) setupClient() error { return ierrors.Wrap(err, "failed to create web client") } + m.API = m.Client.LatestAPI() return nil diff --git a/pkg/evilwallet/evilwallet.go b/pkg/evilwallet/evilwallet.go index f525e3c..b11bccc 100644 --- a/pkg/evilwallet/evilwallet.go +++ b/pkg/evilwallet/evilwallet.go @@ -31,9 +31,6 @@ const ( ) var ( - defaultClientsURLs = []string{"http://localhost:8050"} - defaultFaucetURL = "http://localhost:8088" - NoFreshOutputsAvailable = ierrors.New("no fresh wallet is available") ) @@ -62,8 +59,6 @@ func NewEvilWallet(logger log.Logger, opts ...options.Option[EvilWallet]) *EvilW wallets: NewWallets(), aliasManager: NewAliasManager(), minOutputStorageDeposit: MinOutputStorageDeposit, - optsClientURLs: defaultClientsURLs, - optsFaucetURL: defaultFaucetURL, }, opts, func(w *EvilWallet) { connector := lo.PanicOnErr(models.NewWebClients(w.optsClientURLs, w.optsFaucetURL)) w.connector = connector @@ -672,6 +667,12 @@ func WithClients(urls ...string) options.Option[EvilWallet] { } } +func WithFaucetClient(url string) options.Option[EvilWallet] { + return func(opts *EvilWallet) { + opts.optsFaucetURL = url + } +} + func WithAccountsManager(manager *accountmanager.Manager) options.Option[EvilWallet] { return func(opts *EvilWallet) { opts.accManager = manager diff --git a/pkg/spammer/spammer.go b/pkg/spammer/spammer.go index c08e832..35b9868 100644 --- a/pkg/spammer/spammer.go +++ b/pkg/spammer/spammer.go @@ -115,11 +115,10 @@ func (s *Spammer) setup() { switch s.SpamType { case SpamEvilWallet: if s.EvilWallet == nil { - s.EvilWallet = evilwallet.NewEvilWallet(s.Logger) + panic("evil wallet is nil") } + s.Clients = s.EvilWallet.Connector() - // case SpamCommitments: - // s.CommitmentManager.Setup(s.log) } s.setupSpamDetails() diff --git a/programs/spammers.go b/programs/spammers.go index 6153aa8..079f6bf 100644 --- a/programs/spammers.go +++ b/programs/spammers.go @@ -13,8 +13,9 @@ import ( "github.com/iotaledger/evil-tools/pkg/spammer" ) -func RunSpammer(ctx context.Context, logger log.Logger, nodeURLs []string, paramsSpammer *spammer.ParametersSpammer, accManager *accountmanager.Manager) { - w := evilwallet.NewEvilWallet(logger, evilwallet.WithClients(nodeURLs...), evilwallet.WithAccountsManager(accManager)) +func RunSpammer(ctx context.Context, logger log.Logger, nodeURLs []string, faucetURL string, paramsSpammer *spammer.ParametersSpammer, accManager *accountmanager.Manager) { + fmt.Println("RunSpammer") + w := evilwallet.NewEvilWallet(logger, evilwallet.WithClients(nodeURLs...), evilwallet.WithAccountsManager(accManager), evilwallet.WithFaucetClient(faucetURL)) wg := sync.WaitGroup{} logger.LogInfof("Start spamming with rate: %d, spamming type: %s.", paramsSpammer.Rate, paramsSpammer.Type) @@ -125,8 +126,8 @@ func SpamTransaction(logger log.Logger, w *evilwallet.EvilWallet, paramsSpammer } func SpamDoubleSpends(logger log.Logger, w *evilwallet.EvilWallet, paramsSpammer *spammer.ParametersSpammer) *spammer.Spammer { - if w.NumOfClient() < 2 { - logger.LogInfof("Warning: At least two client are needed to spam, and %d was provided", w.NumOfClient()) + if w.NumOfClient() < 1 { + logger.LogInfo("Warning: At least one client are needed to spam") } scenarioOptions := []evilwallet.ScenarioOption{