tx-spammer/cmd/sendTxs.go

63 lines
1.8 KiB
Go
Raw Normal View History

2020-10-14 15:58:21 +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 (
2020-10-14 17:29:14 +00:00
"os"
"os/signal"
2020-10-14 15:58:21 +00:00
2020-10-21 13:43:42 +00:00
"github.com/sirupsen/logrus"
2020-10-14 15:58:21 +00:00
"github.com/spf13/cobra"
2020-10-22 19:12:05 +00:00
"github.com/vulcanize/tx_spammer/pkg/manual"
2020-10-14 15:58:21 +00:00
)
// sendTxsCmd represents the sendTxs command
var sendTxsCmd = &cobra.Command{
Use: "sendTxs",
2020-10-16 03:10:18 +00:00
Short: "Send large volumes of different tx types to different nodes for testing purposes",
2020-10-14 17:29:14 +00:00
Long: `Loads tx configuration from .toml config file
2020-10-16 03:10:18 +00:00
Generates txs from configuration and sends them to designated node according to set frequency and number
Support standard, optimism L2, optimism L1 to L2, and EIP1559 transactions`,
2020-10-14 15:58:21 +00:00
Run: func(cmd *cobra.Command, args []string) {
2020-10-21 13:43:42 +00:00
subCommand = cmd.CalledAs()
logWithCommand = *logrus.WithField("SubCommand", subCommand)
2020-10-14 17:29:14 +00:00
sendTxs()
2020-10-14 15:58:21 +00:00
},
}
2020-10-14 17:29:14 +00:00
func sendTxs() {
2020-10-22 19:12:05 +00:00
params, err := manual.NewTxParams()
2020-10-14 17:29:14 +00:00
if err != nil {
logWithCommand.Fatal(err)
}
2020-10-22 19:12:05 +00:00
txSpammer := manual.NewTxSpammer(params)
2020-10-14 17:29:14 +00:00
quitChan := make(chan bool)
2020-10-23 15:30:33 +00:00
doneChan := txSpammer.Loop(quitChan)
2020-10-14 17:29:14 +00:00
2020-10-16 03:10:18 +00:00
go func() {
shutdown := make(chan os.Signal)
signal.Notify(shutdown, os.Interrupt)
<-shutdown
close(quitChan)
}()
2020-10-23 15:30:33 +00:00
<-doneChan
2020-10-14 17:29:14 +00:00
}
2020-10-14 15:58:21 +00:00
func init() {
rootCmd.AddCommand(sendTxsCmd)
}