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

update prama

parent f06024aa
......@@ -8,6 +8,7 @@ import (
"math/big"
"net/http"
"strconv"
"sync/atomic"
"sync"
......@@ -20,6 +21,7 @@ import (
var mnemonic = "matter someone fee garlic final police during vapor stool cargo snake dove"
var processMap sync.Map
var Running int32 = 0
func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
......@@ -53,7 +55,11 @@ type WebServicer struct {
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)
if err != nil {
......@@ -63,8 +69,15 @@ func (web *WebServicer) AddressHandler(w http.ResponseWriter, r *http.Request) {
resp := struct {
From string `json:"from"`
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++ {
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) {
func (web *WebServicer) WebService(config Config) error {
r := mux.NewRouter()
// 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("/process/{uuid}", web.ProcessHandler)
r.HandleFunc("/txs", web.TxsHandler).Methods("POST")
......@@ -215,9 +228,20 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
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()
......
......@@ -7,6 +7,7 @@ import (
"crypto/sha256"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/google/uuid"
......@@ -25,6 +26,8 @@ const batchTxHashSize = 3
const batchTxHashQueueSize = 10
type ConTxsWithId struct {
SendRedisTime time.Time
OriginalTx common.Hash
Id uuid.UUID
Tx *types.Transaction
}
......
......@@ -269,7 +269,7 @@ func (t *Transactor) sendTransactions() error {
args := hexutil.Encode(data)
method := "eth_sendRawTransaction"
fmt.Printf("\n%s\n", args)
t.logger.Info("send tx", "idx", sent, "TxAsHex", args)
msg, err := t.newMessage(method, args)
if err != nil {
......@@ -285,10 +285,11 @@ func (t *Transactor) sendTransactions() error {
//return ec.c.CallContext(ctx, nil, "eth_sendRawTransaction", hexutil.Encode(data))
// if we have to make way for the next batch
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
}
default:
atomic.StoreInt32(&Running, 0)
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