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

MaxRequestAmount

parent 9f69e02a
......@@ -395,8 +395,8 @@ func FloatRound(f float64, n int) float64 {
}
type TxParams struct {
From string `json:"from,omitempty"`
//RequestAmount int64 `json:"request_amount"`
From string `json:"from,omitempty"`
RequestAmount int64 `json:"request_amount"`
ToAddrs []string `json:"to_addrs"`
BatchTxSize int64 `json:"batch_tx_size,omitempty"`
BatchTxHashSize int64 `json:"batch_tx_hash_size,omitempty"`
......@@ -427,15 +427,30 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
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
}
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() {
if err := web.ProduceTxs(params.From, params.ToAddrs, int(params.TxCount), params.EveryTxAmount, id); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
......@@ -478,24 +493,10 @@ type WebResp struct {
}
func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount int, amount int64, id uuid.UUID) error {
consTxNum := 0
addrsL := len(toAddrs)
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 {
var hashesBytes []byte = make([]byte, 0, 32*batchTxHashSize)
......
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