2020-10-23 15:30:33 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2020 Vulcanize
|
|
|
|
|
|
|
|
// 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 auto
|
|
|
|
|
2020-10-23 17:27:49 +00:00
|
|
|
import (
|
|
|
|
"crypto/ecdsa"
|
2022-11-03 02:33:18 +00:00
|
|
|
"github.com/sirupsen/logrus"
|
2020-10-23 17:27:49 +00:00
|
|
|
"time"
|
2020-10-23 15:30:33 +00:00
|
|
|
|
2020-10-23 17:27:49 +00:00
|
|
|
"github.com/ethereum/go-ethereum/common"
|
|
|
|
"github.com/ethereum/go-ethereum/rpc"
|
|
|
|
"github.com/vulcanize/tx_spammer/pkg/shared"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
contractDeploymentDelay = time.Duration(15) * time.Second
|
|
|
|
)
|
|
|
|
|
|
|
|
// ContractDeployer is responsible for deploying contracts
|
2020-10-23 15:30:33 +00:00
|
|
|
type ContractDeployer struct {
|
2020-10-23 17:27:49 +00:00
|
|
|
client *rpc.Client
|
|
|
|
txGenerator *TxGenerator
|
2020-10-28 16:03:41 +00:00
|
|
|
senderKeys []*ecdsa.PrivateKey
|
2020-10-23 17:27:49 +00:00
|
|
|
senderAddrs []common.Address
|
2020-10-28 16:03:41 +00:00
|
|
|
config *DeploymentConfig
|
2020-10-23 15:30:33 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 17:27:49 +00:00
|
|
|
// NewContractDeployer returns a new ContractDeployer
|
|
|
|
func NewContractDeployer(config *Config, gen *TxGenerator) *ContractDeployer {
|
2020-10-23 15:30:33 +00:00
|
|
|
return &ContractDeployer{
|
2022-11-03 02:33:18 +00:00
|
|
|
client: config.RpcClient,
|
2020-10-23 17:27:49 +00:00
|
|
|
txGenerator: gen,
|
2020-10-28 16:03:41 +00:00
|
|
|
config: config.DeploymentConfig,
|
|
|
|
senderKeys: config.SenderKeys,
|
2020-10-23 17:27:49 +00:00
|
|
|
senderAddrs: config.SenderAddrs,
|
2020-10-23 15:30:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 17:27:49 +00:00
|
|
|
// Deploy deploys the contracts according to the config provided at construction
|
2020-10-28 16:03:41 +00:00
|
|
|
func (cp *ContractDeployer) Deploy() ([]common.Address, error) {
|
|
|
|
contractAddrs := make([]common.Address, 0, cp.config.Number*uint64(len(cp.senderKeys)))
|
2020-10-23 17:27:49 +00:00
|
|
|
ticker := time.NewTicker(contractDeploymentDelay)
|
2020-10-28 16:03:41 +00:00
|
|
|
defer ticker.Stop()
|
2020-10-23 17:27:49 +00:00
|
|
|
for i := uint64(0); i < cp.config.Number; i++ {
|
2020-10-28 16:03:41 +00:00
|
|
|
<-ticker.C
|
2020-10-23 17:27:49 +00:00
|
|
|
for i, key := range cp.senderKeys {
|
2022-11-03 02:33:18 +00:00
|
|
|
logrus.Debugf("Generating contract deployment for %s.", cp.senderAddrs[i].Hex())
|
|
|
|
signedTx, contractAddr, err := cp.txGenerator.GenerateTx(&GenParams{
|
|
|
|
ChainID: cp.config.ChainID,
|
2020-10-28 16:03:41 +00:00
|
|
|
Sender: cp.senderAddrs[i],
|
2020-10-23 17:27:49 +00:00
|
|
|
SenderKey: key,
|
2020-10-28 16:03:41 +00:00
|
|
|
GasLimit: cp.config.GasLimit,
|
2022-11-03 02:33:18 +00:00
|
|
|
GasFeeCap: cp.config.GasFeeCap,
|
|
|
|
GasTipCap: cp.config.GasTipCap,
|
2020-10-28 16:03:41 +00:00
|
|
|
Data: cp.config.Data,
|
2020-10-23 17:27:49 +00:00
|
|
|
})
|
|
|
|
if err != nil {
|
2020-10-28 16:03:41 +00:00
|
|
|
return nil, err
|
2020-10-23 17:27:49 +00:00
|
|
|
}
|
2022-11-03 02:33:18 +00:00
|
|
|
if err := shared.SendTransaction(cp.client, signedTx); err != nil {
|
2020-10-28 16:03:41 +00:00
|
|
|
return nil, err
|
2020-10-23 17:27:49 +00:00
|
|
|
}
|
2020-10-28 16:03:41 +00:00
|
|
|
contractAddrs = append(contractAddrs, contractAddr)
|
2020-10-23 17:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-28 16:03:41 +00:00
|
|
|
return contractAddrs, nil
|
2020-10-23 15:30:33 +00:00
|
|
|
}
|