Commit 8fa9bb61 authored by gshx's avatar gshx

Merge branch 'heco-testnet' of https://code.wuban.net.cn/liwei/multisend into heco-testnet

parents e3d40a14 3c810609
...@@ -395,8 +395,8 @@ func FloatRound(f float64, n int) float64 { ...@@ -395,8 +395,8 @@ func FloatRound(f float64, n int) float64 {
} }
type TxParams struct { type TxParams struct {
From string `json:"from,omitempty"` From string `json:"from,omitempty"`
//RequestAmount int64 `json:"request_amount"` RequestAmount int64 `json:"request_amount"`
ToAddrs []string `json:"to_addrs"` ToAddrs []string `json:"to_addrs"`
BatchTxSize int64 `json:"batch_tx_size,omitempty"` BatchTxSize int64 `json:"batch_tx_size,omitempty"`
BatchTxHashSize int64 `json:"batch_tx_hash_size,omitempty"` BatchTxHashSize int64 `json:"batch_tx_hash_size,omitempty"`
...@@ -427,17 +427,32 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) { ...@@ -427,17 +427,32 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
atomic.StoreInt32(&Running, 1) atomic.StoreInt32(&Running, 1)
if params.EveryTxAmount*params.TxCount > MaxRequestAmount { if params.RequestAmount > MaxRequestAmount || params.RequestAmount < params.EveryTxAmount*params.TxCount {
http.Error(w, fmt.Sprintf("params.EveryTxAmount*params.TxCount > MaxRequestAmount > %d", MaxRequestAmount), http.StatusBadRequest) http.Error(w, fmt.Sprintf("params.RequestAmount %d > MaxRequestAmount %d|| params.RequestAmount %d < params.EveryTxAmount*params.TxCount %d *%d ", params.RequestAmount, MaxRequestAmount, params.RequestAmount, params.EveryTxAmount, params.TxCount), http.StatusBadRequest)
return return
} }
id := uuid.New() id := uuid.New()
consTxNum := 0
total := int(params.TxCount)
if params.From != systemFromAddr {
total = total + 1
}
consTxNum = total / (batchTxHashSize * batchTxSize)
if total%(batchTxHashSize*batchTxSize) != 0 {
consTxNum = consTxNum + 1
}
SetSendRecord(id, SendRecord{TotalConsTx: int64(consTxNum)})
go func() { go func() {
if err := web.ProduceTxs(params.From, params.ToAddrs, int(params.TxCount), params.EveryTxAmount, id); err != nil { if err := web.ProduceTxs(params.From, params.ToAddrs, int(params.TxCount), params.EveryTxAmount, id, params.RequestAmount); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
return return
} }
...@@ -477,25 +492,11 @@ type WebResp struct { ...@@ -477,25 +492,11 @@ type WebResp struct {
AllTxs []ConsTxHashs `json:"all_txs"` AllTxs []ConsTxHashs `json:"all_txs"`
} }
func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID) error { func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID, requestAmount int64) error {
consTxNum := 0
addrsL := len(toAddrs) addrsL := len(toAddrs)
first := true first := true
total := txCount
if fromAddr != systemFromAddr {
total = total + 1
}
consTxNum = total / (batchTxHashSize * batchTxSize)
if total%(batchTxHashSize*batchTxSize) != 0 {
consTxNum = consTxNum + 1
}
SetSendRecord(id, SendRecord{TotalConsTx: int64(consTxNum)})
for { for {
var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize) var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize)
...@@ -517,7 +518,7 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in ...@@ -517,7 +518,7 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
if fromAddr != systemFromAddr && first { if fromAddr != systemFromAddr && first {
txCount++ txCount++
tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(fromAddr), amount*int64(txCount), big.NewInt(256), nil) tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(fromAddr), requestAmount, big.NewInt(256), nil)
} else { } else {
tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(toAddrs[i%addrsL]), amount, big.NewInt(256), nil) tx, err = buildOriginalTx(originalTxParam.Nonce, common.HexToAddress(toAddrs[i%addrsL]), amount, big.NewInt(256), nil)
......
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