Skip to content

Commit

Permalink
Rename accountmanager to walletmanager
Browse files Browse the repository at this point in the history
  • Loading branch information
daria305 committed Feb 2, 2024
1 parent 3114e9f commit f02a1a5
Show file tree
Hide file tree
Showing 20 changed files with 90 additions and 90 deletions.
36 changes: 18 additions & 18 deletions components/accounts/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import (

"go.uber.org/dig"

"github.com/iotaledger/evil-tools/pkg/accountmanager"
"github.com/iotaledger/evil-tools/pkg/models"
"github.com/iotaledger/evil-tools/pkg/walletmanager"
"github.com/iotaledger/hive.go/app"
"github.com/iotaledger/hive.go/ierrors"
)
Expand Down Expand Up @@ -39,11 +39,11 @@ var (
func run() error {
Component.LogInfo("Starting evil-tools accounts ... done")

accManager, err := accountmanager.RunManager(Component.Logger,
accountmanager.WithClientURL(deps.ParamsTool.NodeURLs[0]),
accountmanager.WithFaucetURL(deps.ParamsTool.FaucetURL),
accountmanager.WithAccountStatesFile(deps.ParamsTool.AccountStatesFile),
accountmanager.WithFaucetAccountParams(&accountmanager.GenesisAccountParams{
accManager, err := walletmanager.RunManager(Component.Logger,
walletmanager.WithClientURL(deps.ParamsTool.NodeURLs[0]),
walletmanager.WithFaucetURL(deps.ParamsTool.FaucetURL),
walletmanager.WithAccountStatesFile(deps.ParamsTool.AccountStatesFile),
walletmanager.WithFaucetAccountParams(&walletmanager.GenesisAccountParams{
FaucetPrivateKey: deps.ParamsTool.BlockIssuerPrivateKey,
FaucetAccountID: deps.ParamsTool.AccountID,
}),
Expand All @@ -64,7 +64,7 @@ func run() error {
return nil
}

func accountsSubcommands(ctx context.Context, accManager *accountmanager.Manager, subcommands []accountmanager.AccountSubcommands) {
func accountsSubcommands(ctx context.Context, accManager *walletmanager.Manager, subcommands []walletmanager.AccountSubcommands) {
// save wallet state on shutdown
defer func() {
err := accManager.SaveStateToFile()
Expand All @@ -84,13 +84,13 @@ func accountsSubcommands(ctx context.Context, accManager *accountmanager.Manager
}

//nolint:all,forcetypassert
func accountsSubcommand(ctx context.Context, wallets *accountmanager.Manager, subCommand accountmanager.AccountSubcommands) error {
func accountsSubcommand(ctx context.Context, wallets *walletmanager.Manager, subCommand walletmanager.AccountSubcommands) error {
Component.LogInfof("Run subcommand: %s, with parameter set: %v", subCommand.Type().String(), subCommand)

switch subCommand.Type() {
case accountmanager.OperationCreateAccount:
case walletmanager.OperationCreateAccount:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountmanager.CreateAccountParams)
accParams := subCommand.(*walletmanager.CreateAccountParams)

accountID, err := wallets.CreateAccount(ctx, accParams)
if err != nil {
Expand All @@ -99,33 +99,33 @@ func accountsSubcommand(ctx context.Context, wallets *accountmanager.Manager, su

Component.LogInfof("Created account %s", accountID)

case accountmanager.OperationDestroyAccount:
case walletmanager.OperationDestroyAccount:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountmanager.DestroyAccountParams)
accParams := subCommand.(*walletmanager.DestroyAccountParams)

if err := wallets.DestroyAccount(ctx, accParams); err != nil {
return ierrors.Wrap(err, "failed to destroy account")
}

case accountmanager.OperationAllotAccount:
case walletmanager.OperationAllotAccount:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountmanager.AllotAccountParams)
accParams := subCommand.(*walletmanager.AllotAccountParams)

if err := wallets.AllotToAccount(ctx, accParams); err != nil {
return ierrors.Wrap(err, "failed to allot to account")
}

case accountmanager.OperationDelegate:
case walletmanager.OperationDelegate:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountmanager.DelegateAccountParams)
accParams := subCommand.(*walletmanager.DelegateAccountParams)

if err := wallets.DelegateToAccount(ctx, accParams); err != nil {
return ierrors.Wrap(err, "failed to delegate to account")
}

case accountmanager.OperationClaim:
case walletmanager.OperationClaim:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountmanager.ClaimAccountParams)
accParams := subCommand.(*walletmanager.ClaimAccountParams)

if err := wallets.Claim(ctx, accParams); err != nil {
return ierrors.Wrap(err, "failed to get rewards")
Expand Down
70 changes: 35 additions & 35 deletions components/accounts/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"strings"

"github.com/iotaledger/evil-tools/pkg/accountmanager"
"github.com/iotaledger/evil-tools/pkg/walletmanager"
"github.com/iotaledger/hive.go/ierrors"
iotago "github.com/iotaledger/iota.go/v4"
)
Expand All @@ -21,7 +21,7 @@ func getCommands(args []string) []string {
continue
}

if !accountmanager.AvailableCommands(arg) {
if !walletmanager.AvailableCommands(arg) {
// skip as it might be a flag parameter
continue
}
Expand All @@ -31,58 +31,58 @@ func getCommands(args []string) []string {
return commands
}

func parseAccountCommands(commands []string, paramsAccounts *ParametersAccounts) []accountmanager.AccountSubcommands {
parsedCmds := make([]accountmanager.AccountSubcommands, 0)
func parseAccountCommands(commands []string, paramsAccounts *ParametersAccounts) []walletmanager.AccountSubcommands {
parsedCmds := make([]walletmanager.AccountSubcommands, 0)

for _, cmd := range commands {
switch cmd {
case accountmanager.OperationCreateAccount.String():
case walletmanager.OperationCreateAccount.String():
createAccountParams, err := parseCreateAccountParams(&paramsAccounts.Create)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, createAccountParams)

case accountmanager.OperationConvertAccount.String():
case walletmanager.OperationConvertAccount.String():
convertAccountParams := parseConvertAccountFlags(&paramsAccounts.Convert)
parsedCmds = append(parsedCmds, convertAccountParams)

case accountmanager.OperationDestroyAccount.String():
case walletmanager.OperationDestroyAccount.String():
destroyAccountParams, err := parseDestroyAccountFlags(&paramsAccounts.Destroy)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, destroyAccountParams)

case accountmanager.OperationAllotAccount.String():
case walletmanager.OperationAllotAccount.String():
allotAccountParams, err := parseAllotAccountFlags(&paramsAccounts.Allot)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, allotAccountParams)

case accountmanager.OperationDelegate.String():
case walletmanager.OperationDelegate.String():
delegatingAccountParams, err := parseDelegateAccountFlags(&paramsAccounts.Delegate)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, delegatingAccountParams)

case accountmanager.OperationStakeAccount.String():
case walletmanager.OperationStakeAccount.String():
stakingAccountParams, err := parseStakeAccountFlags(&paramsAccounts.Stake)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, stakingAccountParams)

case accountmanager.OperationClaim.String():
case walletmanager.OperationClaim.String():
rewardsParams, err := parseRewardsFlags(&paramsAccounts.Claim)
if err != nil {
continue
}
parsedCmds = append(parsedCmds, rewardsParams)

case accountmanager.OperationUpdateAccount.String():
case walletmanager.OperationUpdateAccount.String():
updateAccountParams, err := parseUpdateAccountFlags(&paramsAccounts.Update)
if err != nil {
continue
Expand All @@ -100,29 +100,29 @@ func parseAccountCommands(commands []string, paramsAccounts *ParametersAccounts)

func accountUsage() {
fmt.Println("Usage for accounts [COMMAND] [FLAGS], multiple commands can be chained together.")
fmt.Printf("COMMAND: %s\n", accountmanager.OperationCreateAccount)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationCreateAccount)
_, _ = parseCreateAccountParams(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationConvertAccount)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationConvertAccount)
_ = parseConvertAccountFlags(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationDestroyAccount)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationDestroyAccount)
_, _ = parseDestroyAccountFlags(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationAllotAccount)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationAllotAccount)
_, _ = parseAllotAccountFlags(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationDelegate)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationDelegate)
_, _ = parseDelegateAccountFlags(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationStakeAccount)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationStakeAccount)
_, _ = parseStakeAccountFlags(nil)

fmt.Printf("COMMAND: %s\n", accountmanager.OperationClaim)
fmt.Printf("COMMAND: %s\n", walletmanager.OperationClaim)
_, _ = parseRewardsFlags(nil)
}

func parseCreateAccountParams(paramsAccountCreate *ParametersAccountsCreate) (*accountmanager.CreateAccountParams, error) {
func parseCreateAccountParams(paramsAccountCreate *ParametersAccountsCreate) (*walletmanager.CreateAccountParams, error) {
if paramsAccountCreate == nil {
return nil, ierrors.New("paramsAccountCreate missing for create account")
}
Expand All @@ -136,48 +136,48 @@ func parseCreateAccountParams(paramsAccountCreate *ParametersAccountsCreate) (*a
paramsAccountCreate.Transition = true
}

return &accountmanager.CreateAccountParams{
return &walletmanager.CreateAccountParams{
Alias: paramsAccountCreate.Alias,
NoBIF: paramsAccountCreate.NoBlockIssuerFeature,
Implicit: paramsAccountCreate.Implicit,
Transition: paramsAccountCreate.Transition,
}, nil
}

func parseConvertAccountFlags(paramsAccountConvert *ParametersAccountsConvert) *accountmanager.ConvertAccountParams {
return &accountmanager.ConvertAccountParams{
func parseConvertAccountFlags(paramsAccountConvert *ParametersAccountsConvert) *walletmanager.ConvertAccountParams {
return &walletmanager.ConvertAccountParams{
AccountAlias: paramsAccountConvert.Alias,
}
}

func parseDestroyAccountFlags(paramsAccountDestroy *ParametersAccountsDestroy) (*accountmanager.DestroyAccountParams, error) {
func parseDestroyAccountFlags(paramsAccountDestroy *ParametersAccountsDestroy) (*walletmanager.DestroyAccountParams, error) {
if paramsAccountDestroy == nil {
return nil, ierrors.New("paramsAccountDestroy missing for destroy account")
}

return &accountmanager.DestroyAccountParams{
return &walletmanager.DestroyAccountParams{
AccountAlias: paramsAccountDestroy.Alias,
ExpirySlot: uint64(paramsAccountDestroy.ExpirySlot),
}, nil
}

func parseAllotAccountFlags(paramsAccountAllot *ParametersAccountsAllot) (*accountmanager.AllotAccountParams, error) {
func parseAllotAccountFlags(paramsAccountAllot *ParametersAccountsAllot) (*walletmanager.AllotAccountParams, error) {
if paramsAccountAllot == nil {
return nil, ierrors.New("paramsAccountAllot missing for allot account")
}

return &accountmanager.AllotAccountParams{
return &walletmanager.AllotAccountParams{
Alias: paramsAccountAllot.Alias,
Amount: iotago.Mana(paramsAccountAllot.Amount),
}, nil
}

func parseStakeAccountFlags(paramsAccountStake *ParametersAccountsStake) (*accountmanager.StakeAccountParams, error) {
func parseStakeAccountFlags(paramsAccountStake *ParametersAccountsStake) (*walletmanager.StakeAccountParams, error) {
if paramsAccountStake == nil {
return nil, ierrors.New("paramsAccountStake missing for stake account")
}

return &accountmanager.StakeAccountParams{
return &walletmanager.StakeAccountParams{
Alias: paramsAccountStake.Alias,
Amount: uint64(paramsAccountStake.Amount),
FixedCost: uint64(paramsAccountStake.FixedCost),
Expand All @@ -186,35 +186,35 @@ func parseStakeAccountFlags(paramsAccountStake *ParametersAccountsStake) (*accou
}, nil
}

func parseRewardsFlags(paramsRewards *ParametersClaim) (*accountmanager.ClaimAccountParams, error) {
func parseRewardsFlags(paramsRewards *ParametersClaim) (*walletmanager.ClaimAccountParams, error) {
if paramsRewards == nil {
return nil, ierrors.New("paramsRewards missing for rewards account")
}

return &accountmanager.ClaimAccountParams{
return &walletmanager.ClaimAccountParams{
Alias: paramsRewards.Alias,
}, nil
}

func parseDelegateAccountFlags(paramsAccountDelegate *ParametersAccountsDelegate) (*accountmanager.DelegateAccountParams, error) {
func parseDelegateAccountFlags(paramsAccountDelegate *ParametersAccountsDelegate) (*walletmanager.DelegateAccountParams, error) {
if paramsAccountDelegate == nil {
return nil, ierrors.New("paramsAccountDelegate missing for delegate account")
}

return &accountmanager.DelegateAccountParams{
return &walletmanager.DelegateAccountParams{
FromAlias: paramsAccountDelegate.FromAlias,
ToAddress: paramsAccountDelegate.ToAddress,
Amount: iotago.BaseToken(paramsAccountDelegate.Amount),
CheckPool: paramsAccountDelegate.CheckPool,
}, nil
}

func parseUpdateAccountFlags(paramsAccountUpdate *ParametersAccountsUpdate) (*accountmanager.UpdateAccountParams, error) {
func parseUpdateAccountFlags(paramsAccountUpdate *ParametersAccountsUpdate) (*walletmanager.UpdateAccountParams, error) {
if paramsAccountUpdate == nil {
return nil, ierrors.New("paramsAccountUpdate missing for update account")
}

return &accountmanager.UpdateAccountParams{
return &walletmanager.UpdateAccountParams{
Alias: paramsAccountUpdate.Alias,
BlockIssuerKey: paramsAccountUpdate.BlockIssuerKey,
Amount: uint64(paramsAccountUpdate.Amount),
Expand Down
12 changes: 6 additions & 6 deletions components/spammer/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package spammer
import (
"go.uber.org/dig"

"github.com/iotaledger/evil-tools/pkg/accountmanager"
"github.com/iotaledger/evil-tools/pkg/models"
"github.com/iotaledger/evil-tools/pkg/walletmanager"
"github.com/iotaledger/evil-tools/programs"
"github.com/iotaledger/hive.go/app"
)
Expand Down Expand Up @@ -35,11 +35,11 @@ var (

func run() error {
Component.LogInfo("Starting evil-tools spammer ... done")
accWallet, err := accountmanager.RunManager(Component.Logger,
accountmanager.WithClientURL(deps.ParamsTool.NodeURLs[0]),
accountmanager.WithFaucetURL(deps.ParamsTool.FaucetURL),
accountmanager.WithAccountStatesFile(deps.ParamsTool.AccountStatesFile),
accountmanager.WithFaucetAccountParams(&accountmanager.GenesisAccountParams{
accWallet, err := walletmanager.RunManager(Component.Logger,
walletmanager.WithClientURL(deps.ParamsTool.NodeURLs[0]),
walletmanager.WithFaucetURL(deps.ParamsTool.FaucetURL),
walletmanager.WithAccountStatesFile(deps.ParamsTool.AccountStatesFile),
walletmanager.WithFaucetAccountParams(&walletmanager.GenesisAccountParams{
FaucetPrivateKey: deps.ParamsTool.BlockIssuerPrivateKey,
FaucetAccountID: deps.ParamsTool.AccountID,
}),
Expand Down
6 changes: 3 additions & 3 deletions pkg/evilwallet/evilwallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"context"
"time"

"github.com/iotaledger/evil-tools/pkg/accountmanager"
"github.com/iotaledger/evil-tools/pkg/models"
"github.com/iotaledger/evil-tools/pkg/utils"
"github.com/iotaledger/evil-tools/pkg/walletmanager"
"github.com/iotaledger/hive.go/ds/types"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
Expand Down Expand Up @@ -41,7 +41,7 @@ type EvilWallet struct {
log.Logger

wallets *Wallets
accManager *accountmanager.Manager
accManager *walletmanager.Manager
connector models.Connector
outputManager *OutputManager
aliasManager *AliasManager
Expand Down Expand Up @@ -673,7 +673,7 @@ func WithFaucetClient(url string) options.Option[EvilWallet] {
}
}

func WithAccountsManager(manager *accountmanager.Manager) options.Option[EvilWallet] {
func WithAccountsManager(manager *walletmanager.Manager) options.Option[EvilWallet] {
return func(opts *EvilWallet) {
opts.accManager = manager
}
Expand Down
Loading

0 comments on commit f02a1a5

Please sign in to comment.