Commit 42718ddf authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

send tx private key as cmd param

parent 94a698f6
......@@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/crypto"
)
var sendTxPrivatekey string = "a1994419e9b06a7b27e8d094840ae26a6b7806633bb8be55a1a835f1620d8cec"
var toAddress common.Address = common.HexToAddress("0x0071B39fd266F8aeF392fb50F078A233b2218a0b")
func init() {
......@@ -47,7 +46,7 @@ func (f *EthClientFactory) ValidateConfig(cfg Config) error {
func (f *EthClientFactory) NewClient(cfg Config) (Client, error) {
sendTxPrivatekeyAsECDSA, err := crypto.HexToECDSA(sendTxPrivatekey)
sendTxPrivatekeyAsECDSA, err := crypto.HexToECDSA(cfg.SendTxPrivateKey)
if err != nil {
panic(err)
}
......
......@@ -18,6 +18,7 @@ func Execute() {
var (
rate, sendPeriod, count, expectedTime int
websocketAddr, redisAddr, redisPasswd string
sendTxPrivateKey string
)
func init() {
......@@ -29,7 +30,7 @@ func init() {
rootCmd.PersistentFlags().IntVar(&expectedTime, "expectedTime", 3600, "the expected time used to send the total tx number")
rootCmd.PersistentFlags().StringVar(&redisAddr, "redisAddr", "127.0.0.1:6379", "commit the original txs to the redis queue")
rootCmd.PersistentFlags().StringVar(&redisPasswd, "redisPasswd", "redis20220217", "redis password")
rootCmd.PersistentFlags().StringVar(&sendTxPrivateKey, "sendTxPrivateKey", "a1994419e9b06a7b27e8d094840ae26a6b7806633bb8be55a1a835f1620d8cec", "send tx to the chain with the private key")
}
var rootCmd = &cobra.Command{
......@@ -37,12 +38,13 @@ var rootCmd = &cobra.Command{
Short: "send batch txs hash to chain and original txs to redis",
Run: func(cmd *cobra.Command, args []string) {
cfg := multisend.Config{
Rate: rate,
Count: count,
Connections: 1,
Time: int(expectedTime),
SendPeriod: int(sendPeriod),
ClientFactory: "ethclient",
Rate: rate,
Count: count,
Connections: 1,
Time: int(expectedTime),
SendPeriod: int(sendPeriod),
ClientFactory: "ethclient",
SendTxPrivateKey: sendTxPrivateKey,
}
transactor, err := multisend.NewTransactor(websocketAddr, &cfg)
......
......@@ -36,6 +36,7 @@ type Config struct {
PeerConnectTimeout int `json:"peer_connect_timeout"` // The maximum time to wait (in seconds) for all peers to connect, if ExpectPeers > 0.
StatsOutputFile string `json:"stats_output_file"` // Where to store the final aggregate statistics file (in CSV format).
NoTrapInterrupts bool `json:"no_trap_interrupts"` // Should we avoid trapping Ctrl+Break? Only relevant for standalone execution mode.
SendTxPrivateKey string `json:"send_tx_private_key"` // Send tx to the chain with the private key.
}
var validBroadcastTxMethods = map[string]interface{}{
......
......@@ -3,6 +3,7 @@ package multisend
import (
"context"
"encoding/json"
"fmt"
//"fmt"
"runtime"
......@@ -15,8 +16,6 @@ import (
var (
jobnum = runtime.NumCPU()
loggerRedis = logging.NewLogrusLogger("redis")
)
type Job struct {
......@@ -44,6 +43,8 @@ func initClient(poolSize int, redisAddr, passwd string) *redis.Client {
func Start(redisAddr, passwd string) {
logger := logging.NewLogrusLogger(fmt.Sprintf("redis[%s]", redisAddr))
client := initClient(10, redisAddr, passwd)
count := 0
limiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 1)
......@@ -68,7 +69,7 @@ func Start(redisAddr, passwd string) {
count += 1
case <-logTicker.C:
loggerRedis.Info("Sending batchTxs to redis", "idx", count, "toRedis", redisAddr, "totaltxsCount", batchTxSize*count, "now", time.Now().Format("15:04:05"))
logger.Info("Sending batchTxs to redis", "idx", count, "totaltxsCount", batchTxSize*count, "now", time.Now().Format("15:04:05"))
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment