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

send tx private key as cmd param

parent 94a698f6
...@@ -13,7 +13,6 @@ import ( ...@@ -13,7 +13,6 @@ import (
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
) )
var sendTxPrivatekey string = "a1994419e9b06a7b27e8d094840ae26a6b7806633bb8be55a1a835f1620d8cec"
var toAddress common.Address = common.HexToAddress("0x0071B39fd266F8aeF392fb50F078A233b2218a0b") var toAddress common.Address = common.HexToAddress("0x0071B39fd266F8aeF392fb50F078A233b2218a0b")
func init() { func init() {
...@@ -47,7 +46,7 @@ func (f *EthClientFactory) ValidateConfig(cfg Config) error { ...@@ -47,7 +46,7 @@ func (f *EthClientFactory) ValidateConfig(cfg Config) error {
func (f *EthClientFactory) NewClient(cfg Config) (Client, error) { func (f *EthClientFactory) NewClient(cfg Config) (Client, error) {
sendTxPrivatekeyAsECDSA, err := crypto.HexToECDSA(sendTxPrivatekey) sendTxPrivatekeyAsECDSA, err := crypto.HexToECDSA(cfg.SendTxPrivateKey)
if err != nil { if err != nil {
panic(err) panic(err)
} }
......
...@@ -18,6 +18,7 @@ func Execute() { ...@@ -18,6 +18,7 @@ func Execute() {
var ( var (
rate, sendPeriod, count, expectedTime int rate, sendPeriod, count, expectedTime int
websocketAddr, redisAddr, redisPasswd string websocketAddr, redisAddr, redisPasswd string
sendTxPrivateKey string
) )
func init() { func init() {
...@@ -29,7 +30,7 @@ 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().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(&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(&redisPasswd, "redisPasswd", "redis20220217", "redis password")
rootCmd.PersistentFlags().StringVar(&sendTxPrivateKey, "sendTxPrivateKey", "a1994419e9b06a7b27e8d094840ae26a6b7806633bb8be55a1a835f1620d8cec", "send tx to the chain with the private key")
} }
var rootCmd = &cobra.Command{ var rootCmd = &cobra.Command{
...@@ -37,12 +38,13 @@ var rootCmd = &cobra.Command{ ...@@ -37,12 +38,13 @@ var rootCmd = &cobra.Command{
Short: "send batch txs hash to chain and original txs to redis", Short: "send batch txs hash to chain and original txs to redis",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
cfg := multisend.Config{ cfg := multisend.Config{
Rate: rate, Rate: rate,
Count: count, Count: count,
Connections: 1, Connections: 1,
Time: int(expectedTime), Time: int(expectedTime),
SendPeriod: int(sendPeriod), SendPeriod: int(sendPeriod),
ClientFactory: "ethclient", ClientFactory: "ethclient",
SendTxPrivateKey: sendTxPrivateKey,
} }
transactor, err := multisend.NewTransactor(websocketAddr, &cfg) transactor, err := multisend.NewTransactor(websocketAddr, &cfg)
......
...@@ -36,6 +36,7 @@ type Config struct { ...@@ -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. 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). 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. 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{}{ var validBroadcastTxMethods = map[string]interface{}{
......
...@@ -3,6 +3,7 @@ package multisend ...@@ -3,6 +3,7 @@ package multisend
import ( import (
"context" "context"
"encoding/json" "encoding/json"
"fmt"
//"fmt" //"fmt"
"runtime" "runtime"
...@@ -15,8 +16,6 @@ import ( ...@@ -15,8 +16,6 @@ import (
var ( var (
jobnum = runtime.NumCPU() jobnum = runtime.NumCPU()
loggerRedis = logging.NewLogrusLogger("redis")
) )
type Job struct { type Job struct {
...@@ -44,6 +43,8 @@ func initClient(poolSize int, redisAddr, passwd string) *redis.Client { ...@@ -44,6 +43,8 @@ func initClient(poolSize int, redisAddr, passwd string) *redis.Client {
func Start(redisAddr, passwd string) { func Start(redisAddr, passwd string) {
logger := logging.NewLogrusLogger(fmt.Sprintf("redis[%s]", redisAddr))
client := initClient(10, redisAddr, passwd) client := initClient(10, redisAddr, passwd)
count := 0 count := 0
limiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 1) limiter := rate.NewLimiter(rate.Every(time.Millisecond*100), 1)
...@@ -68,7 +69,7 @@ func Start(redisAddr, passwd string) { ...@@ -68,7 +69,7 @@ func Start(redisAddr, passwd string) {
count += 1 count += 1
case <-logTicker.C: 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