Commit 608a54d4 authored by 李伟@五瓣科技's avatar 李伟@五瓣科技

update prama

parent f06024aa
...@@ -8,6 +8,7 @@ import ( ...@@ -8,6 +8,7 @@ import (
"math/big" "math/big"
"net/http" "net/http"
"strconv" "strconv"
"sync/atomic"
"sync" "sync"
...@@ -20,6 +21,7 @@ import ( ...@@ -20,6 +21,7 @@ import (
var mnemonic = "matter someone fee garlic final police during vapor stool cargo snake dove" var mnemonic = "matter someone fee garlic final police during vapor stool cargo snake dove"
var processMap sync.Map var processMap sync.Map
var Running int32 = 0
func GetSendRecord(id uuid.UUID) (SendRecord, bool) { func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
...@@ -53,7 +55,11 @@ type WebServicer struct { ...@@ -53,7 +55,11 @@ type WebServicer struct {
cli Client cli Client
} }
func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) { const MaxToAddrsNum = 1000
const MaxTxCount = 5 * 1000 * 1000
const MaxRequestAmount = MaxTxCount * 10
func (web *WebServicer) ParamHandler(w http.ResponseWriter, r *http.Request) {
wallet, err := hdwallet.NewFromMnemonic(mnemonic) wallet, err := hdwallet.NewFromMnemonic(mnemonic)
if err != nil { if err != nil {
...@@ -61,10 +67,17 @@ func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) { ...@@ -61,10 +67,17 @@ func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) {
} }
resp := struct { resp := struct {
From string `json:"from"` From string `json:"from"`
ToAddrs []string `json:"to_addrs"` ToAddrs []string `json:"to_addrs"`
MaxToAddrsNum int64 `json:"max_to_addrs_num"`
MaxRequestAmount int64 `json:"max_request_amount"`
MaxTxCount int64 `json:"max_tx_count"`
}{} }{}
resp.MaxToAddrsNum = MaxToAddrsNum
resp.MaxTxCount = MaxTxCount
resp.MaxRequestAmount = MaxRequestAmount
for i := 0; i <= 1000; i++ { for i := 0; i <= 1000; i++ {
path := hdwallet.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/0/%d", i)) path := hdwallet.MustParseDerivationPath(fmt.Sprintf("m/44'/60'/0'/0/%d", i))
...@@ -99,7 +112,7 @@ func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) { ...@@ -99,7 +112,7 @@ func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) {
func (web *WebServicer) WebService(config Config) error { func (web *WebServicer) WebService(config Config) error {
r := mux.NewRouter() r := mux.NewRouter()
// Routes consist of a path and a handler function. // Routes consist of a path and a handler function.
r.HandleFunc("/addrs", web.AddressHandler) r.HandleFunc("/param", web.ParamHandler)
//r.HandleFunc("/faucet/{addr}", web.FaucetHandler) //r.HandleFunc("/faucet/{addr}", web.FaucetHandler)
r.HandleFunc("/process/{uuid}", web.ProcessHandler) r.HandleFunc("/process/{uuid}", web.ProcessHandler)
r.HandleFunc("/txs", web.TxsHandler).Methods("POST") r.HandleFunc("/txs", web.TxsHandler).Methods("POST")
...@@ -215,9 +228,20 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -215,9 +228,20 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
return return
} }
if atomic.LoadInt32(&Running) != 0 {
http.Error(w, fmt.Sprintf("another batch txs is running "), http.StatusBadRequest)
return
}
atomic.StoreInt32(&Running, 1)
// 有余额的话,金额不好判断,由前端校验; // 有余额的话,金额不好判断,由前端校验;
// if params.EveryTxAmount * params.TxCount < params.RequestAmount{ if params.EveryTxAmount*params.TxCount < params.RequestAmount && params.RequestAmount > 5*1000*1000 {
// }
http.Error(w, fmt.Sprintf("params.EveryTxAmount*params.TxCount < params.RequestAmount && params.RequestAmount > 5*1000*1000"), http.StatusBadRequest)
return
}
//startTime := time.Now() //startTime := time.Now()
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"crypto/sha256" "crypto/sha256"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/google/uuid" "github.com/google/uuid"
...@@ -25,8 +26,10 @@ const batchTxHashSize = 3 ...@@ -25,8 +26,10 @@ const batchTxHashSize = 3
const batchTxHashQueueSize = 10 const batchTxHashQueueSize = 10
type ConTxsWithId struct { type ConTxsWithId struct {
Id uuid.UUID SendRedisTime time.Time
Tx *types.Transaction OriginalTx common.Hash
Id uuid.UUID
Tx *types.Transaction
} }
type OriginalBatchTxs struct { type OriginalBatchTxs struct {
......
...@@ -269,7 +269,7 @@ func (t *Transactor) sendTransactions() error { ...@@ -269,7 +269,7 @@ func (t *Transactor) sendTransactions() error {
args := hexutil.Encode(data) args := hexutil.Encode(data)
method := "eth_sendRawTransaction" method := "eth_sendRawTransaction"
fmt.Printf("\n%s\n", args) t.logger.Info("send tx", "idx", sent, "TxAsHex", args)
msg, err := t.newMessage(method, args) msg, err := t.newMessage(method, args)
if err != nil { if err != nil {
...@@ -285,10 +285,11 @@ func (t *Transactor) sendTransactions() error { ...@@ -285,10 +285,11 @@ func (t *Transactor) sendTransactions() error {
//return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data)) //return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
// if we have to make way for the next batch // if we have to make way for the next batch
if time.Since(batchStartTime) >= time.Duration(t.config.SendPeriod)*time.Second { if time.Since(batchStartTime) >= time.Duration(t.config.SendPeriod)*time.Second {
fmt.Printf("time.Since(batchStartTime): %s \n", fmt.Sprintf("%.20f", time.Since(batchStartTime).Seconds())) t.logger.Info("send batch txs timeout", "time.Since(batchStartTime)", fmt.Sprintf("%.20f s", time.Since(batchStartTime).Seconds()))
break break
} }
default: default:
atomic.StoreInt32(&Running, 0)
t.logger.Info("there is no tx in queue", "now", time.Now().Format("15:04:05")) t.logger.Info("there is no tx in queue", "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