Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend evilwallet with account tooling #386

Merged
merged 106 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 105 commits
Commits
Show all changes
106 commits
Select commit Hold shift + click to select a range
32ba9f9
Add account spam to the basic spammer
daria305 Sep 22, 2023
e1dbe76
Add outputType to all outputoptions
jkrvivian Sep 22, 2023
b9c984b
Remove outputOption check
jkrvivian Sep 22, 2023
6ca7381
Fix account output spam
jkrvivian Sep 25, 2023
4ae98ce
Merge branch 'develop' into feat/accounts-tooling
jkrvivian Sep 27, 2023
59df4d6
Update iota.go
jkrvivian Sep 27, 2023
1846f25
Merge branch 'develop' into feat/accounts-tooling
daria305 Sep 28, 2023
aab6dfd
Restructure evil wallet package
daria305 Sep 28, 2023
e50e0cd
Merge branch 'develop' into feat/accounts-tooling
daria305 Sep 28, 2023
cf950c3
Merge branch 'develop' into feat/accounts-tooling
daria305 Sep 28, 2023
f4f7ad5
Fix dependency cycle
daria305 Sep 28, 2023
cc34f8a
Add structure for first account commands
daria305 Sep 28, 2023
d9e022d
Merge branch 'develop' into feat/accounts-tooling
daria305 Sep 28, 2023
643de7c
After merge fix of tx types
daria305 Sep 28, 2023
d0b7e76
Implement read/write file in AccountWallet
jkrvivian Sep 29, 2023
3d062b0
Support multiple subcommands
daria305 Sep 29, 2023
ec6ae16
Update account wallet saving and loading from the file
daria305 Sep 29, 2023
3c9aa9c
Merge branch 'develop' into feat/accounts-tooling
daria305 Sep 29, 2023
60d906f
Update flags and help generation
daria305 Sep 29, 2023
4f86c8b
Move connector to models
daria305 Oct 1, 2023
defd8ad
Move output to models
daria305 Oct 1, 2023
08c2b94
Fix Output type in wallets
jkrvivian Oct 2, 2023
5b085f5
Load api from webClient
jkrvivian Oct 2, 2023
ce3b120
Refactor wallet load/write
jkrvivian Oct 2, 2023
be3d697
Refactor write account states to file
jkrvivian Oct 2, 2023
8541832
Fix help flags
daria305 Oct 2, 2023
0333dbb
Request faucet funds for basic output
daria305 Oct 2, 2023
5902b30
Use account builder and implicit account
daria305 Oct 2, 2023
6450362
Finish createAccount
jkrvivian Oct 2, 2023
62d27a3
Save faucet unspentOutputID
jkrvivian Oct 2, 2023
8230962
Sketch the flow of destroying an account
jkrvivian Oct 2, 2023
d8840b0
Add index and seed to AccountStateData
jkrvivian Oct 2, 2023
4b9dfdf
Move accountWallet options to options.go
jkrvivian Oct 2, 2023
1724b2f
Write/Read lastUsedIndex to AccountStateData
jkrvivian Oct 2, 2023
014005f
Add wait for account commitment method and refactor accountData
daria305 Oct 2, 2023
72ab10e
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 2, 2023
bea12c4
Extend logs and waiting period
daria305 Oct 2, 2023
2465488
Fix AccountData serialization
daria305 Oct 2, 2023
3f1ec3d
Fix wallet name
daria305 Oct 3, 2023
511a280
Add accountAlias param to evil spammer
daria305 Oct 3, 2023
9fc8fa4
Load accData with CustomSpammer
daria305 Oct 3, 2023
4fced08
Introduce AccountStatus
jkrvivian Oct 3, 2023
6e57e40
Refactor getAccount
jkrvivian Oct 3, 2023
7ba01da
Merge branch 'develop' into feat/accounts-tooling
jkrvivian Oct 3, 2023
809754d
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 3, 2023
52fa5b0
Rename wallet to evilwallet
daria305 Oct 3, 2023
a0888c9
Remove redundant constant
daria305 Oct 3, 2023
a0b3e4c
Fix signedTxIDs errors
daria305 Oct 3, 2023
9c83dd3
Fix genesis transaction ID creation
daria305 Oct 3, 2023
d47e845
Fix txID errors in accWallet
daria305 Oct 3, 2023
fe79ef4
Merge branch 'feat/accounts-tooling' of github.com:iotaledger/iota-co…
jkrvivian Oct 3, 2023
8a04767
Use account wallet directly by spammer
daria305 Oct 3, 2023
a4ff71b
Basic and accounts use the same requestfaucetFunds function
daria305 Oct 3, 2023
cb16f88
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 3, 2023
4e36105
Remove redundant options
daria305 Oct 3, 2023
3e5676c
Merge branch 'feat/accounts-tooling' of github.com:iotaledger/iota-co…
jkrvivian Oct 3, 2023
1c69a7a
Use correct outputID in destroyAccount
jkrvivian Oct 4, 2023
ad8be61
Merge branch 'develop' into feat/accounts-tooling
jkrvivian Oct 4, 2023
8cfa9d2
Fix accwallet initialization in evil-spammer
jkrvivian Oct 4, 2023
9f3f541
Add more commands for account wallets
jkrvivian Oct 5, 2023
d4de5b9
Enable account commands usage description
jkrvivian Oct 5, 2023
a119134
Add update command
jkrvivian Oct 5, 2023
abe12f7
Implement list command
jkrvivian Oct 5, 2023
1cd688d
Add accidentally removed defer function
jkrvivian Oct 5, 2023
2b7fe2e
Create block in faucet request function
daria305 Oct 8, 2023
f015002
Read accountID without api
daria305 Oct 8, 2023
e561b0f
Cleanup config files, wallet uses only one file.
daria305 Oct 8, 2023
59aea8d
Refactor faucet and genesis config
daria305 Oct 8, 2023
be96a87
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 8, 2023
0eac6ac
Start replacing post tx with post block
daria305 Oct 9, 2023
9f2990f
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 9, 2023
dcd1554
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 10, 2023
530931f
Move block issuance to evilwallet
daria305 Oct 10, 2023
889b374
Fix import cycle
daria305 Oct 11, 2023
4dea8a3
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 11, 2023
8e9f3b7
Add serializable wallet accountState
daria305 Oct 11, 2023
e29490a
Fix prefix
daria305 Oct 11, 2023
8e7b032
Fix RMC API nil pointer
daria305 Oct 11, 2023
198f41f
Fix: save faucet output to wallet during the split
daria305 Oct 11, 2023
35ecc1a
Add more debug logs
daria305 Oct 11, 2023
f2fecb1
Fix default alias setup
daria305 Oct 11, 2023
076304a
Shorten max awaiting times
daria305 Oct 11, 2023
67a8055
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 11, 2023
469fadd
Fix: genesis output creation is now read from config file
daria305 Oct 12, 2023
fe01733
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 12, 2023
90fa9b9
Remove TODOs already listed in the issue TODO list
daria305 Oct 12, 2023
202ae6a
Cleanup Account data transition during serialization
daria305 Oct 12, 2023
261b533
Pay with the potential or stored mana of the faucet output.
daria305 Oct 12, 2023
bac39b4
Use AllotAllMana from txBuilder
daria305 Oct 12, 2023
9349395
Add allotment strategy to transaction creation process
daria305 Oct 13, 2023
96937a2
Use latest outputID from TxID and index method
jkrvivian Oct 13, 2023
5d1968d
Merge branch 'feat/accounts-tooling' of github.com:iotaledger/iota-co…
jkrvivian Oct 13, 2023
1026cf4
Use allotAll strategy for all tx spams, and noAllotment for data spam
daria305 Oct 13, 2023
4115e97
Merge branch 'develop' into feat/accounts-tooling
daria305 Oct 13, 2023
71339f8
Add fallback strategy if potential mana on genesis is not enough
daria305 Oct 13, 2023
c715d6c
Update go mod
daria305 Oct 13, 2023
5f52f91
Minor refactor
jkrvivian Oct 17, 2023
3fdf369
Read OutputOrSpent in blockIDFromTransactionID
jkrvivian Oct 17, 2023
46dcf5b
Add .dat to gitignore
jkrvivian Oct 17, 2023
5390240
go mod tidy
daria305 Oct 17, 2023
9e8499d
Remove prints
daria305 Oct 17, 2023
b7182f9
Do not use currentAPI, use latest and slot specific
daria305 Oct 17, 2023
5fa3fe8
Fetch faucet unspent output via indexer
jkrvivian Oct 17, 2023
dc216d0
Merge branch 'feat/accounts-tooling' of github.com:iotaledger/iota-co…
jkrvivian Oct 17, 2023
262a131
Refactor, wrap getting faucet output
daria305 Oct 17, 2023
006dfb8
Simplify return
daria305 Oct 17, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions components/restapi/core/accounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func congestionForAccountID(c echo.Context) (*apimodels.CongestionResponse, erro
if err != nil {
rmcSlot = 0
}
rmc, err := deps.Protocol.CandidateEngineInstance().Ledger.RMCManager().RMC(rmcSlot)
rmc, err := deps.Protocol.MainEngineInstance().Ledger.RMCManager().RMC(rmcSlot)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get RMC for slot: %d", rmcSlot)
}
Expand Down Expand Up @@ -141,7 +141,7 @@ func rewardsByOutputID(c echo.Context) (*apimodels.ManaRewardsResponse, error) {

utxoOutput, err := deps.Protocol.MainEngineInstance().Ledger.Output(outputID)
if err != nil {
return nil, ierrors.Wrapf(err, "failed to get output %s from ledger", outputID)
return nil, ierrors.Wrapf(err, "failed to get output %s from ledger", outputID.ToHex())
}

var reward iotago.Mana
Expand Down
13 changes: 8 additions & 5 deletions components/restapi/core/transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ func blockIDByTransactionID(c echo.Context) (iotago.BlockID, error) {

func blockIDFromTransactionID(transactionID iotago.TransactionID) (iotago.BlockID, error) {
// Get the first output of that transaction (using index 0)
outputID := iotago.OutputID{}
copy(outputID[:], transactionID[:])
outputID := iotago.OutputIDFromTransactionIDAndIndex(transactionID, 0)

output, err := deps.Protocol.MainEngineInstance().Ledger.Output(outputID)
output, spent, err := deps.Protocol.MainEngineInstance().Ledger.OutputOrSpent(outputID)
if err != nil {
return iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to get output: %s", outputID.String())
return iotago.EmptyBlockID, ierrors.Wrapf(err, "failed to get output: %s", outputID.ToHex())
}

return output.BlockID(), nil
if output != nil {
return output.BlockID(), nil
}

return spent.BlockID(), nil
}

func blockByTransactionID(c echo.Context) (*model.Block, error) {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/iotaledger/hive.go/stringify v0.0.0-20231010133617-cdbd5387e2af
github.com/iotaledger/inx-app v1.0.0-rc.3.0.20231011161248-cf0bd6e08811
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011154428-257141868dad
github.com/iotaledger/iota.go/v4 v4.0.0-20231011161154-7004432004e1
github.com/iotaledger/iota.go/v4 v4.0.0-20231013092100-ad2a52b5ac9a
github.com/labstack/echo/v4 v4.11.2
github.com/labstack/gommon v0.4.0
github.com/libp2p/go-libp2p v0.30.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011154428-257141868dad h1:TRM9Ek
github.com/iotaledger/inx/go v1.0.0-rc.2.0.20231011154428-257141868dad/go.mod h1:plZ0+8yLdDWHedj3SfHUwQtIETD+lcS6M1iEAxcjzJ4=
github.com/iotaledger/iota.go/v4 v4.0.0-20231011161154-7004432004e1 h1:mz5E00q1U/LDiUi/wVAbwdhGNKX0dNThaO99Fsyjkgs=
github.com/iotaledger/iota.go/v4 v4.0.0-20231011161154-7004432004e1/go.mod h1:XmgOVYZ7805zVEYPwhvqBDVa7XieXRgPrCEGZW35W8k=
github.com/iotaledger/iota.go/v4 v4.0.0-20231013092100-ad2a52b5ac9a h1:S/n3ZTjnnl0IIMCx+S0pu5CZNArO6Z+omiXt6dDmPK4=
github.com/iotaledger/iota.go/v4 v4.0.0-20231013092100-ad2a52b5ac9a/go.mod h1:XmgOVYZ7805zVEYPwhvqBDVa7XieXRgPrCEGZW35W8k=
github.com/ipfs/boxo v0.10.0 h1:tdDAxq8jrsbRkYoF+5Rcqyeb91hgWe2hp7iLu7ORZLY=
github.com/ipfs/boxo v0.10.0/go.mod h1:Fg+BnfxZ0RPzR0nOodzdIq3A7KgoWAOWsEIImrIQdBM=
github.com/ipfs/go-cid v0.4.1 h1:A/T3qGvxi4kpKWWcPC/PgbvDA2bjVLO7n4UeVwnbs/s=
Expand Down
3 changes: 2 additions & 1 deletion tools/evil-spammer/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
*.log
*.json
*.json
*.dat
40 changes: 40 additions & 0 deletions tools/evil-spammer/accountwallet/commands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package accountwallet

import (
"fmt"

"github.com/iotaledger/hive.go/ierrors"
iotago "github.com/iotaledger/iota.go/v4"
)

func (a *AccountWallet) CreateAccount(params *CreateAccountParams) (iotago.AccountID, error) {
implicitAccountOutput, privateKey, err := a.getFunds(params.Amount, iotago.AddressImplicitAccountCreation)
if err != nil {
return iotago.EmptyAccountID, ierrors.Wrap(err, "Failed to create account")
}

accountID := a.registerAccount(params.Alias, implicitAccountOutput.OutputID, a.latestUsedIndex, privateKey)

fmt.Printf("Created account %s with %d tokens\n", accountID.ToHex(), params.Amount)

return accountID, nil
}

func (a *AccountWallet) DestroyAccount(params *DestroyAccountParams) error {
return a.destroyAccount(params.AccountAlias)
}

func (a *AccountWallet) ListAccount() error {
fmt.Printf("%-10s \t%-33s\n\n", "Alias", "AccountID")
for _, accData := range a.accountsAliases {
fmt.Printf("%-10s \t", accData.Alias)
fmt.Printf("%-33s ", accData.Account.ID().ToHex())
fmt.Printf("\n")
}

return nil
}

func (a *AccountWallet) AllotToAccount(params *AllotAccountParams) error {
return nil
}
219 changes: 219 additions & 0 deletions tools/evil-spammer/accountwallet/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,219 @@
package accountwallet

import (
"encoding/json"
"os"

"github.com/iotaledger/hive.go/ds/types"
"github.com/iotaledger/iota-core/tools/evil-spammer/models"
)

// commands

type AccountOperation int

const (
OperationCreateAccount AccountOperation = iota
OperationConvertAccount
OperationDestroyAccound
OperationAllotAccount
OperationDelegateAccount
OperationStakeAccount
OperationListAccounts
OperationUpdateAccount

CmdNameCreateAccount = "create"
CmdNameConvertAccount = "convert"
CmdNameDestroyAccount = "destroy"
CmdNameAllotAccount = "allot"
CmdNameDelegateAccount = "delegate"
CmdNameStakeAccount = "stake"
CmdNameListAccounts = "list"
CmdNameUpdateAccount = "update"
)

func (a AccountOperation) String() string {
return []string{
CmdNameCreateAccount,
CmdNameConvertAccount,
CmdNameDestroyAccount,
CmdNameAllotAccount,
CmdNameDelegateAccount,
CmdNameStakeAccount,
CmdNameListAccounts,
CmdNameUpdateAccount,
}[a]
}

func AvailableCommands(cmd string) bool {
availableCommands := map[string]types.Empty{
CmdNameCreateAccount: types.Void,
CmdNameConvertAccount: types.Void,
CmdNameDestroyAccount: types.Void,
CmdNameAllotAccount: types.Void,
CmdNameDelegateAccount: types.Void,
CmdNameStakeAccount: types.Void,
CmdNameListAccounts: types.Void,
CmdNameUpdateAccount: types.Void,
}

_, ok := availableCommands[cmd]
return ok
}

type Configuration struct {
BindAddress string `json:"bindAddress,omitempty"`
AccountStatesFile string `json:"accountStatesFile,omitempty"`
GenesisSeed string `json:"genesisSeed,omitempty"`
BlockIssuerPrivateKey string `json:"blockIssuerPrivateKey,omitempty"`
AccountID string `json:"accountID,omitempty"`
}

var accountConfigFile = "config.json"

var (
dockerAccountConfigJSON = `{
"bindAddress": "http://localhost:8080",
"accountStatesFile": "wallet.dat",
"genesisSeed": "7R1itJx5hVuo9w9hjg5cwKFmek4HMSoBDgJZN8hKGxih",
"blockIssuerPrivateKey": "db39d2fde6301d313b108dc9db1ee724d0f405f6fde966bd776365bc5f4a5fb31e4b21eb51dcddf65c20db1065e1f1514658b23a3ddbf48d30c0efc926a9a648",
"accountID": "0x6aee704f25558e8aa7630fed0121da53074188abc423b3c5810f80be4936eb6e"}`
)

// LoadConfiguration loads the config file.
func LoadConfiguration() *Configuration {
// open config file
config := new(Configuration)
file, err := os.Open(accountConfigFile)
if err != nil {
if !os.IsNotExist(err) {
panic(err)
}

//nolint:gosec // users should be able to read the file
if err = os.WriteFile(accountConfigFile, []byte(dockerAccountConfigJSON), 0o644); err != nil {
panic(err)
}
if file, err = os.Open(accountConfigFile); err != nil {
panic(err)
}
}
defer file.Close()

// decode config file
if err = json.NewDecoder(file).Decode(config); err != nil {
panic(err)
}

return config
}

func SaveConfiguration(config *Configuration) {
// open config file
file, err := os.Open(accountConfigFile)
if err != nil {
panic(err)
}
defer file.Close()

jsonConfigs, err := json.MarshalIndent(config, "", " ")

if err != nil {
log.Errorf("failed to write configs to file %s", err)
}

//nolint:gosec // users should be able to read the file
if err = os.WriteFile(accountConfigFile, jsonConfigs, 0o644); err != nil {
panic(err)
}
}

type AccountSubcommands interface {
Type() AccountOperation
}

type CreateAccountParams struct {
Alias string
Amount uint64
NoBIF bool
Implicit bool
}

func (c *CreateAccountParams) Type() AccountOperation {
return OperationCreateAccount
}

type DestroyAccountParams struct {
AccountAlias string
ExpirySlot uint64
}

func (d *DestroyAccountParams) Type() AccountOperation {
return OperationDestroyAccound
}

type AllotAccountParams struct {
Amount uint64
To string
From string // if not set we use faucet
}

func (a *AllotAccountParams) Type() AccountOperation {
return OperationAllotAccount
}

type ConvertAccountParams struct {
AccountAlias string
}

func (d *ConvertAccountParams) Type() AccountOperation {
return OperationConvertAccount
}

type DelegateAccountParams struct {
Amount uint64
To string
From string // if not set we use faucet
}

func (a *DelegateAccountParams) Type() AccountOperation {
return OperationDelegateAccount
}

type StakeAccountParams struct {
Alias string
Amount uint64
FixedCost uint64
StartEpoch uint64
EndEpoch uint64
}

func (a *StakeAccountParams) Type() AccountOperation {
return OperationStakeAccount
}

type UpdateAccountParams struct {
Alias string
BlockIssuerKey string
Mana uint64
Amount uint64
ExpirySlot uint64
}

func (a *UpdateAccountParams) Type() AccountOperation {
return OperationUpdateAccount
}

type NoAccountParams struct {
Operation AccountOperation
}

func (a *NoAccountParams) Type() AccountOperation {
return a.Operation
}

type StateData struct {
Seed string `serix:"0,mapKey=seed,lengthPrefixType=uint8"`
LastUsedIndex uint64 `serix:"1,mapKey=lastUsedIndex"`
AccountsData []*models.AccountState `serix:"2,mapKey=accounts,lengthPrefixType=uint8"`
}
Loading
Loading