refactor
This commit is contained in:
parent
58c258d7c3
commit
ee1dd84832
@ -23,7 +23,7 @@ import (
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/vulcanize/tx_spammer/pkg"
|
||||
"github.com/vulcanize/tx_spammer/pkg/manual"
|
||||
)
|
||||
|
||||
// sendTxsCmd represents the sendTxs command
|
||||
@ -41,11 +41,11 @@ Support standard, optimism L2, optimism L1 to L2, and EIP1559 transactions`,
|
||||
}
|
||||
|
||||
func sendTxs() {
|
||||
params, err := tx_spammer.NewTxParams()
|
||||
params, err := manual.NewTxParams()
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
txSpammer := tx_spammer.NewTxSpammer(params)
|
||||
txSpammer := manual.NewTxSpammer(params)
|
||||
wg := new(sync.WaitGroup)
|
||||
quitChan := make(chan bool)
|
||||
txSpammer.Loop(wg, quitChan)
|
||||
|
@ -14,11 +14,12 @@
|
||||
// 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 tx_spammer
|
||||
package manual
|
||||
|
||||
import (
|
||||
"crypto/ecdsa"
|
||||
"fmt"
|
||||
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||
"math/big"
|
||||
"os"
|
||||
"strings"
|
||||
@ -32,6 +33,36 @@ import (
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
const (
|
||||
ETH_TX_LIST = "ETH_TX_LIST"
|
||||
ETH_ADDR_LOG = "ETH_ADDR_LOG"
|
||||
|
||||
defaultGenKeyWritePathPrefix = "./accounts/keys/"
|
||||
defaultAddrLogPath = "./accounts/addresses/accounts"
|
||||
|
||||
typeSuffix = ".type"
|
||||
httpPathSuffix = ".http"
|
||||
toSuffix = ".to"
|
||||
amountSuffix = ".amount"
|
||||
gasLimitSuffix = ".gasLimit"
|
||||
gasPriceSuffix = ".gasPrice"
|
||||
gasPremiumSuffix = ".gasPremium"
|
||||
feeCapSuffix = ".feeCap"
|
||||
dataSuffix = ".data"
|
||||
senderKeyPathSuffix = ".senderKeyPath"
|
||||
writeSenderPathSuffix = ".writeSenderPath"
|
||||
l1SenderSuffix = ".l1Sender"
|
||||
l1RollupTxIdSuffix = ".l1RollupTxId"
|
||||
sigHashTypeSuffix = ".sigHashType"
|
||||
frequencySuffix = ".frequency"
|
||||
totalNumberSuffix = ".totalNumber"
|
||||
delaySuffix = ".delay"
|
||||
startingNonceSuffix = ".startingNonce"
|
||||
queueOriginSuffix = ".queueOrigin"
|
||||
chainIDSuffix = ".chainID"
|
||||
contractWriteSuffix = ".writeDeploymentAddrPath"
|
||||
)
|
||||
|
||||
// TxParams holds the parameters for a given transaction
|
||||
type TxParams struct {
|
||||
// Name of this tx in the .toml file
|
||||
@ -41,7 +72,7 @@ type TxParams struct {
|
||||
Client *rpc.Client
|
||||
|
||||
// Type of the tx
|
||||
Type TxType
|
||||
Type shared.TxType
|
||||
|
||||
// Chain ID
|
||||
ChainID uint64
|
||||
@ -78,36 +109,6 @@ type TxParams struct {
|
||||
Delay time.Duration
|
||||
}
|
||||
|
||||
const (
|
||||
ETH_TX_LIST = "ETH_TX_LIST"
|
||||
ETH_ADDR_LOG = "ETH_ADDR_LOG"
|
||||
|
||||
defaultGenKeyWritePathPrefix = "./accounts/keys/"
|
||||
defaultAddrLogPath = "./accounts/addresses/accounts"
|
||||
|
||||
typeSuffix = ".type"
|
||||
httpPathSuffix = ".http"
|
||||
toSuffix = ".to"
|
||||
amountSuffix = ".amount"
|
||||
gasLimitSuffix = ".gasLimit"
|
||||
gasPriceSuffix = ".gasPrice"
|
||||
gasPremiumSuffix = ".gasPremium"
|
||||
feeCapSuffix = ".feeCap"
|
||||
dataSuffix = ".data"
|
||||
senderKeyPathSuffix = ".senderKeyPath"
|
||||
writeSenderPathSuffix = ".writeSenderPath"
|
||||
l1SenderSuffix = ".l1Sender"
|
||||
l1RollupTxIdSuffix = ".l1RollupTxId"
|
||||
sigHashTypeSuffix = ".sigHashType"
|
||||
frequencySuffix = ".frequency"
|
||||
totalNumberSuffix = ".totalNumber"
|
||||
delaySuffix = ".delay"
|
||||
startingNonceSuffix = ".startingNonce"
|
||||
queueOriginSuffix = ".queueOrigin"
|
||||
chainIDSuffix = ".chainID"
|
||||
contractWriteSuffix = ".writeDeploymentAddrPath"
|
||||
)
|
||||
|
||||
// NewConfig returns a new tx spammer config
|
||||
func NewTxParams() ([]TxParams, error) {
|
||||
viper.BindEnv("eth.txs", ETH_TX_LIST)
|
||||
@ -135,7 +136,7 @@ func NewTxParams() ([]TxParams, error) {
|
||||
if txTypeStr == "" {
|
||||
return nil, fmt.Errorf("need tx type for tx %s", txName)
|
||||
}
|
||||
txType, err := TxTypeFromString(txTypeStr)
|
||||
txType, err := shared.TxTypeFromString(txTypeStr)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
// 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 tx_spammer
|
||||
package manual
|
||||
|
||||
import (
|
||||
"context"
|
@ -14,7 +14,7 @@
|
||||
// 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 tx_spammer
|
||||
package manual
|
||||
|
||||
import (
|
||||
"sync"
|
@ -14,10 +14,11 @@
|
||||
// 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 tx_spammer
|
||||
package manual
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||
"os"
|
||||
"sync/atomic"
|
||||
|
||||
@ -53,9 +54,9 @@ func NewTxGenerator(params []TxParams) *TxGenerator {
|
||||
func (tg TxGenerator) GenerateTx(params TxParams) ([]byte, error) {
|
||||
tx := make([]byte, 0)
|
||||
switch params.Type {
|
||||
case Standard, OptimismL1ToL2, OptimismL2:
|
||||
case shared.Standard, shared.OptimismL1ToL2, shared.OptimismL2:
|
||||
return tg.gen(params)
|
||||
case EIP1559:
|
||||
case shared.EIP1559:
|
||||
return tg.gen1559(params)
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported tx type: %s", params.Type.String())
|
||||
@ -75,7 +76,7 @@ func (gen TxGenerator) gen(params TxParams) ([]byte, error) {
|
||||
} else {
|
||||
tx = types.NewTransaction(nonce, *params.To, params.Amount, params.GasLimit, params.GasPrice, params.Data, params.L1SenderAddr, params.L1RollupTxId, params.QueueOrigin, params.SigHashType)
|
||||
}
|
||||
signer, err := TxSigner(params.Type, params.ChainID)
|
||||
signer, err := shared.TxSigner(params.Type, params.ChainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
@ -14,7 +14,7 @@
|
||||
// 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 tx_spammer
|
||||
package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
@ -14,7 +14,7 @@
|
||||
// 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 tx_spammer
|
||||
package shared
|
||||
|
||||
import (
|
||||
"fmt"
|
Loading…
Reference in New Issue
Block a user