Skip to content

Commit

Permalink
Merge pull request #42 from iotaledger/feat/claiming
Browse files Browse the repository at this point in the history
Refactor and implement claiming and allotment
  • Loading branch information
daria305 authored Feb 2, 2024
2 parents 4e894c6 + c218270 commit e9bef74
Show file tree
Hide file tree
Showing 52 changed files with 1,945 additions and 1,430 deletions.
57 changes: 52 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,20 @@ go build
./evil-tools [spammer,accounts] [[script-flag-set]]
```

The evil-tools app has two applications:
The evil-tools app has three applications:
- spammer - to spam the network with transactions, nested conflicts, etc.
- accounts - to create, convert and destroy accounts.
- info - to print details about the network, accounts, delegations, etc.
List of all possible flags can be found in [configuration.md](configuration.md)

### Setup
To run the evil spammer tool on a network different than the local docker network, remember to provide:
- `--tool.nodeURLs` - the list of URLs of the nodes in the network
- `--tool.faucetURL` - the URL of the faucet in the network
- `--tool.blockIssuerPrivateKey` - the private key of the existing block issuer account, best some account created in the genesis. Spammer will mostly use mana from this account to pay for the issuance.
- `--tools.accountID` - the corresponding account ID of the existing block issuer account.


### `spammer`
Usage for spammer tool:
`./evil-tools spammer [FLAGS]`
Expand All @@ -37,15 +46,18 @@ Infinite spam is enabled when no duration flag is provided.
```bash
./evil-tools spammer --spammer.type tx --spammer.rate 10
```
You can provide urls for clients:
You can provide urls for clients and the faucet, each client should run the inx-indexer:
```bash
./evil-tools spammer --spammer.urls "http://localhost:8050,http://localhost:8060" --spammer.type tx --spammer.rate 10
./evil-tools spammer --tool.nodeURLs "http://localhost:8050" --tool.faucetURL "http://localhost:8088" --spammer.type tx --spammer.rate 10
```
Enable deep spam:
```bash
./evil-tools spammer --spammer.type tx --spammer.rate 10 --spammer.duration 100s --spammer.deep
./evil-tools spammer --spammer.type tx --spammer.rate 10 --spammer.duration 100s --spammer.deepSpamEnabled
```
Spam with the account created by the evil-tools app:
```bash
./evil-tools spammer --spammer.type tx --spammer.rate 10 --spammer.duration 100s --spammer.accountAlias A
```

### Examples for the accounts
Create implicit account with alias `A`:
```bash
Expand All @@ -55,6 +67,41 @@ Create account with genesis account paying for creation transaction:
```bash
./evil-tools accounts create --accounts.create.alias A
```
Delegate 1000 tokens (requested from the Faucet) and store it under alias `A`:
```bash
./evil-tools accounts delegate --accounts.delegate.fromAlias A --accounts.delegate.amount 100000
```
Allot at least `amount` of mana to the account with alias `A`:
```bash
./evil-tools accounts allot --accounts.allot.alias A --accounts.allot.amount 100000
```
Claim all rewards under alias `A`:
```bash
./evil-tools accounts claim --accounts.claim.alias A
```

### Examples for printing tool details and info about the network
List all accounts stored in the wallet.dat file of the evil-tools app:
```bash
./evil-tools info accounts
```
List all delegations done with the evil-tools app to be claimed:
```bash
./evil-tools info delegations
```
Request validators endpoint:
```bash
./evil-tools info validators
```
Request committee endpoint:
```bash
./evil-tools info committee
```
List rewards endpoint responses for all delegations done by the app:
```bash
./evil-tools info rewards
```


### Scenario diagrams:
##### No conflicts
Expand Down
101 changes: 48 additions & 53 deletions components/accounts/component.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import (

"go.uber.org/dig"

"github.com/iotaledger/evil-tools/pkg/accountwallet"
"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 All @@ -19,67 +20,61 @@ func init() {
Component = &app.Component{
Name: "Accounts",
Params: params,
DepsFunc: func(cDeps dependencies) { deps = cDeps },
Run: run,
Provide: func(c *dig.Container) error {
return c.Provide(provideWallet)
},
IsEnabled: func(_ *dig.Container) bool { return true },
DepsFunc: func(cDeps dependencies) { deps = cDeps },
}
}

var (
Component *app.Component
deps dependencies
)

type dependencies struct {
dig.In

AccountWallets *accountwallet.AccountWallets
ParamsTool *models.ParametersTool
}

var (
Component *app.Component
deps dependencies
)

func run() error {
Component.LogInfo("Starting evil-tools accounts ... done")
// save wallet state on shutdown
defer func() {
err := accountwallet.SaveState(deps.AccountWallets)
if err != nil {
Component.LogErrorf("Error while saving wallet state: %v", err)
}
}()

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,
}),
)
if err != nil {
Component.LogError(err.Error())

return err
}

accountsSubcommandsFlags := parseAccountCommands(getCommands(os.Args[2:]), ParamsAccounts)
accountsSubcommands(
Component.Daemon().ContextStopped(),
deps.AccountWallets,
accManager,
accountsSubcommandsFlags,
)

return nil
}

func provideWallet() *accountwallet.AccountWallets {
// load wallet
accWallet, err := accountwallet.Run(Component.Daemon().ContextStopped(), Component.Logger,
accountwallet.WithClientURL(ParamsAccounts.NodeURLs[0]),
accountwallet.WithFaucetURL(ParamsAccounts.FaucetURL),
accountwallet.WithAccountStatesFile(ParamsAccounts.AccountStatesFile),
accountwallet.WithFaucetAccountParams(&accountwallet.GenesisAccountParams{
FaucetPrivateKey: ParamsAccounts.BlockIssuerPrivateKey,
FaucetAccountID: ParamsAccounts.AccountID,
}),
)
if err != nil {
Component.LogPanic(err.Error())
}

return accWallet
}
func accountsSubcommands(ctx context.Context, accManager *walletmanager.Manager, subcommands []walletmanager.AccountSubcommands) {
// save wallet state on shutdown
defer func() {
err := accManager.SaveStateToFile()
if err != nil {
Component.LogErrorf("Error while saving wallet state: %v", err)
}
}()

func accountsSubcommands(ctx context.Context, wallets *accountwallet.AccountWallets, subcommands []accountwallet.AccountSubcommands) {
for _, sub := range subcommands {
err := accountsSubcommand(ctx, wallets, sub)
err := accountsSubcommand(ctx, accManager, sub)
if err != nil {
Component.LogFatal(ierrors.Wrap(err, "failed to run subcommand").Error())

Expand All @@ -89,13 +84,13 @@ func accountsSubcommands(ctx context.Context, wallets *accountwallet.AccountWall
}

//nolint:all,forcetypassert
func accountsSubcommand(ctx context.Context, wallets *accountwallet.AccountWallets, subCommand accountwallet.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 accountwallet.OperationCreateAccount:
case walletmanager.OperationCreateAccount:
//nolint:forcetypassert // we can safely assume that the type is correct
accParams := subCommand.(*accountwallet.CreateAccountParams)
accParams := subCommand.(*walletmanager.CreateAccountParams)

accountID, err := wallets.CreateAccount(ctx, accParams)
if err != nil {
Expand All @@ -104,35 +99,35 @@ func accountsSubcommand(ctx context.Context, wallets *accountwallet.AccountWalle

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

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

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

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

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

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

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

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

if err := wallets.Rewards(ctx, params); err != nil {
if err := wallets.Claim(ctx, accParams); err != nil {
return ierrors.Wrap(err, "failed to get rewards")
}

Expand Down
23 changes: 5 additions & 18 deletions components/accounts/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ type (
}

ParametersAccountsAllot struct {
AllotToAccount string `default:"" usage:"The alias name of the account to allot mana to"`
Amount int64 `default:"1000" usage:"The amount of mana to allot"`
Alias string `default:"" usage:"The alias name of the account to allot mana to"`
Amount uint64 `default:"10000" usage:"The amount of mana to allot"`
}

ParametersAccountsStake struct {
Expand All @@ -34,12 +34,12 @@ type (
EndEpoch int64 `default:"0" usage:"The end epoch of the account to stake"`
}

ParametersRewards struct {
ParametersClaim struct {
Alias string `default:"" usage:"The alias name of the wallet to get rewards for"`
}

ParametersAccountsDelegate struct {
FromAlias string `default:"" usage:"The alias of the account to delegate IOTA tokens from"`
FromAlias string `default:"default" usage:"The alias of the delegator, does not need to have an account"`
ToAddress string `default:"rms1pzg8cqhfxqhq7pt37y8cs4v5u4kcc48lquy2k73ehsdhf5ukhya3y5rx2w6" usage:"The account address of the account to delegate IOTA tokens to"`
Amount int64 `default:"100" usage:"The amount of mana to delegate"`
CheckPool bool `default:"false" usage:"Check if the delegation is added to pool stake when the start epoch is committed"`
Expand All @@ -53,28 +53,15 @@ type (
ExpirySlot int64 `default:"0" usage:"Update the expiry slot of the account"`
}

ParameterAccountsInfo struct {
Alias string `default:"" usage:"Alias name of the account to get info"`
Verbose bool `default:"false" usage:"Verbose output"`
}

ParametersAccounts struct {
NodeURLs []string `default:"http://localhost:8050" usage:"API URLs for clients used in test separated with commas"`
FaucetURL string `default:"http://localhost:8088" usage:"Faucet URL used in test"`

AccountStatesFile string `default:"wallet.dat" usage:"File to store account states in"`
BlockIssuerPrivateKey string `default:"db39d2fde6301d313b108dc9db1ee724d0f405f6fde966bd776365bc5f4a5fb31e4b21eb51dcddf65c20db1065e1f1514658b23a3ddbf48d30c0efc926a9a648" usage:"Block issuer private key (in hex) to use for genesis account"`
AccountID string `default:"0x6aee704f25558e8aa7630fed0121da53074188abc423b3c5810f80be4936eb6e" usage:"Account ID to use for genesis account"`

Create ParametersAccountsCreate
Convert ParametersAccountsConvert
Destroy ParametersAccountsDestroy
Allot ParametersAccountsAllot
Stake ParametersAccountsStake
Rewards ParametersRewards
Claim ParametersClaim
Delegate ParametersAccountsDelegate
Update ParametersAccountsUpdate
Info ParameterAccountsInfo
}
)

Expand Down
Loading

0 comments on commit e9bef74

Please sign in to comment.