Skip to content

Commit

Permalink
split fund returns and keyfile update
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofel committed May 14, 2024
1 parent 49d172e commit 33d10c7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cmd/seth.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ func RunCLI(args []string) error {
},
Action: func(cCtx *cli.Context) error {
toAddr := cCtx.String("address")
return seth.ReturnFunds(C, toAddr)
return seth.ReturnFundsAndUpdateKeyfile(C, toAddr)
},
},
{
Expand Down
15 changes: 13 additions & 2 deletions keyfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func UpdateAndSplitFunds(c *Client, opts *FundKeyFileCmdOpts) error {
return os.WriteFile(c.Cfg.KeyFilePath, b, os.ModePerm)
}

// ReturnFunds returns funds to the root key from all the test keys in some "keyfile.toml"
// ReturnFundsAndUpdateKeyfile returns funds to the root key from all other keys
func ReturnFunds(c *Client, toAddr string) error {
if toAddr == "" {
toAddr = c.Addresses[0].Hex()
Expand Down Expand Up @@ -140,14 +140,25 @@ func ReturnFunds(c *Client, toAddr string) error {
if err := eg.Wait(); err != nil {
return err
}

return nil
}

// ReturnFundsAndUpdateKeyfile returns funds to the root key from all the test keys in some "keyfile.toml"
func ReturnFundsAndUpdateKeyfile(c *Client, toAddr string) error {
err := ReturnFunds(c, toAddr)
if err != nil {
return err
}
keyFile, err := c.CreateOrUnmarshalKeyFile(nil)
if err != nil {
return err
}
eg, egCtx := errgroup.WithContext(context.Background())
for _, kfd := range keyFile.Keys {
kfd := kfd
eg.Go(func() error {
balance, err := c.Client.BalanceAt(context.Background(), common.HexToAddress(kfd.Address), nil)
balance, err := c.Client.BalanceAt(egCtx, common.HexToAddress(kfd.Address), nil)
if err != nil {
return err
}
Expand Down

0 comments on commit 33d10c7

Please sign in to comment.