refactor
This commit is contained in:
parent
58c258d7c3
commit
ee1dd84832
@ -23,7 +23,7 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/vulcanize/tx_spammer/pkg"
|
"github.com/vulcanize/tx_spammer/pkg/manual"
|
||||||
)
|
)
|
||||||
|
|
||||||
// sendTxsCmd represents the sendTxs command
|
// sendTxsCmd represents the sendTxs command
|
||||||
@ -41,11 +41,11 @@ Support standard, optimism L2, optimism L1 to L2, and EIP1559 transactions`,
|
|||||||
}
|
}
|
||||||
|
|
||||||
func sendTxs() {
|
func sendTxs() {
|
||||||
params, err := tx_spammer.NewTxParams()
|
params, err := manual.NewTxParams()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logWithCommand.Fatal(err)
|
logWithCommand.Fatal(err)
|
||||||
}
|
}
|
||||||
txSpammer := tx_spammer.NewTxSpammer(params)
|
txSpammer := manual.NewTxSpammer(params)
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
quitChan := make(chan bool)
|
quitChan := make(chan bool)
|
||||||
txSpammer.Loop(wg, quitChan)
|
txSpammer.Loop(wg, quitChan)
|
||||||
|
@ -14,11 +14,12 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package manual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/ecdsa"
|
"crypto/ecdsa"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||||
"math/big"
|
"math/big"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
@ -32,6 +33,36 @@ import (
|
|||||||
"github.com/spf13/viper"
|
"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
|
// TxParams holds the parameters for a given transaction
|
||||||
type TxParams struct {
|
type TxParams struct {
|
||||||
// Name of this tx in the .toml file
|
// Name of this tx in the .toml file
|
||||||
@ -41,7 +72,7 @@ type TxParams struct {
|
|||||||
Client *rpc.Client
|
Client *rpc.Client
|
||||||
|
|
||||||
// Type of the tx
|
// Type of the tx
|
||||||
Type TxType
|
Type shared.TxType
|
||||||
|
|
||||||
// Chain ID
|
// Chain ID
|
||||||
ChainID uint64
|
ChainID uint64
|
||||||
@ -78,36 +109,6 @@ type TxParams struct {
|
|||||||
Delay time.Duration
|
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
|
// NewConfig returns a new tx spammer config
|
||||||
func NewTxParams() ([]TxParams, error) {
|
func NewTxParams() ([]TxParams, error) {
|
||||||
viper.BindEnv("eth.txs", ETH_TX_LIST)
|
viper.BindEnv("eth.txs", ETH_TX_LIST)
|
||||||
@ -135,7 +136,7 @@ func NewTxParams() ([]TxParams, error) {
|
|||||||
if txTypeStr == "" {
|
if txTypeStr == "" {
|
||||||
return nil, fmt.Errorf("need tx type for tx %s", txName)
|
return nil, fmt.Errorf("need tx type for tx %s", txName)
|
||||||
}
|
}
|
||||||
txType, err := TxTypeFromString(txTypeStr)
|
txType, err := shared.TxTypeFromString(txTypeStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package manual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package manual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"sync"
|
"sync"
|
@ -14,10 +14,11 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package manual
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/vulcanize/tx_spammer/pkg/shared"
|
||||||
"os"
|
"os"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
|
|
||||||
@ -53,9 +54,9 @@ func NewTxGenerator(params []TxParams) *TxGenerator {
|
|||||||
func (tg TxGenerator) GenerateTx(params TxParams) ([]byte, error) {
|
func (tg TxGenerator) GenerateTx(params TxParams) ([]byte, error) {
|
||||||
tx := make([]byte, 0)
|
tx := make([]byte, 0)
|
||||||
switch params.Type {
|
switch params.Type {
|
||||||
case Standard, OptimismL1ToL2, OptimismL2:
|
case shared.Standard, shared.OptimismL1ToL2, shared.OptimismL2:
|
||||||
return tg.gen(params)
|
return tg.gen(params)
|
||||||
case EIP1559:
|
case shared.EIP1559:
|
||||||
return tg.gen1559(params)
|
return tg.gen1559(params)
|
||||||
default:
|
default:
|
||||||
return nil, fmt.Errorf("unsupported tx type: %s", params.Type.String())
|
return nil, fmt.Errorf("unsupported tx type: %s", params.Type.String())
|
||||||
@ -75,7 +76,7 @@ func (gen TxGenerator) gen(params TxParams) ([]byte, error) {
|
|||||||
} else {
|
} else {
|
||||||
tx = types.NewTransaction(nonce, *params.To, params.Amount, params.GasLimit, params.GasPrice, params.Data, params.L1SenderAddr, params.L1RollupTxId, params.QueueOrigin, params.SigHashType)
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
@ -14,7 +14,7 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// 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/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
package tx_spammer
|
package shared
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
Loading…
Reference in New Issue
Block a user