tx-spammer/cmd/autoSend.go

64 lines
1.9 KiB
Go
Raw Permalink Normal View History

2020-10-23 15:30:33 +00:00
// Copyright © 2020 Vulcanize, Inc
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
package cmd
import (
"os"
"os/signal"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
2022-12-20 22:56:12 +00:00
"github.com/cerc-io/tx-spammer/pkg/auto"
2020-10-23 15:30:33 +00:00
)
// autoSendCmd represents the autoSend command
var autoSendCmd = &cobra.Command{
Use: "autoSend",
Short: "Send large volumes of different tx types to different nodes for testing purposes",
Long: `Loads tx configuration from .toml config file
Generates txs from configuration and provided private keys and sends them to designated node according to set frequency and number
Support standard, optimism L2, optimism L1 to L2, and EIP1559 transactions`,
Run: func(cmd *cobra.Command, args []string) {
subCommand = cmd.CalledAs()
logWithCommand = *logrus.WithField("SubCommand", subCommand)
autoSend()
},
}
func autoSend() {
config, err := auto.NewConfig()
if err != nil {
logWithCommand.Fatal(err)
}
txSpammer := auto.NewTxSpammer(config)
quitChan := make(chan bool)
2020-10-23 17:27:49 +00:00
doneChan, err := txSpammer.Loop(quitChan)
if err != nil {
logWithCommand.Fatal(err)
}
2020-10-23 15:30:33 +00:00
go func() {
shutdown := make(chan os.Signal)
signal.Notify(shutdown, os.Interrupt)
<-shutdown
close(quitChan)
}()
<-doneChan
}
2020-10-23 17:27:49 +00:00
2020-10-23 15:30:33 +00:00
func init() {
rootCmd.AddCommand(autoSendCmd)
}