Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multisend
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
李伟@五瓣科技
multisend
Commits
2db7e343
Commit
2db7e343
authored
Mar 04, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update process api
parent
608a54d4
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
49 additions
and
21 deletions
+49
-21
http.go
http.go
+28
-14
originalTx.go
originalTx.go
+5
-4
transactor.go
transactor.go
+16
-3
No files found.
http.go
View file @
2db7e343
...
...
@@ -9,9 +9,11 @@ import (
"net/http"
"strconv"
"sync/atomic"
"time"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/google/uuid"
"github.com/gorilla/mux"
hdwallet
"github.com/miguelmota/go-ethereum-hdwallet"
...
...
@@ -46,9 +48,11 @@ type SendRecord struct {
}
type
BatchSend
struct
{
BeginTime
int64
`json:"begin_time"`
EndTime
int64
`json:"end_time"`
TxNum
int
`json:"tx_num"`
SendToRedisBeginTime
int64
`json:"send_to_redis_begin_time"`
SendTxsEndTime
int64
`json:"send_txs_end_time"`
TxNum
int
`json:"cons_tx_num"`
BeginOriginalTx
common
.
Hash
`json:"begin_original_tx"`
EndOriginalTx
common
.
Hash
`json:"end_original_tx"`
}
type
WebServicer
struct
{
...
...
@@ -223,8 +227,8 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
return
}
if
params
.
TxCount
>
1000
*
1000
{
//百万
http
.
Error
(
w
,
fmt
.
Sprintf
(
"max tx count
1000*1000 "
),
http
.
StatusBadRequest
)
if
params
.
TxCount
>
MaxTxCount
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"max tx count
%d "
,
MaxTxCount
),
http
.
StatusBadRequest
)
return
}
...
...
@@ -235,24 +239,19 @@ func (web *WebServicer) TxsHandler(w http.ResponseWriter, r *http.Request) {
atomic
.
StoreInt32
(
&
Running
,
1
)
// 有余额的话,金额不好判断,由前端校验;
if
params
.
EveryTxAmount
*
params
.
TxCount
<
params
.
RequestAmount
&&
params
.
RequestAmount
>
5
*
1000
*
1000
{
if
params
.
EveryTxAmount
*
params
.
TxCount
<
params
.
RequestAmount
&&
params
.
RequestAmount
>
MaxRequestAmount
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"params.EveryTxAmount*params.TxCount < params.RequestAmount && params.RequestAmount >
5*1000*1000"
),
http
.
StatusBadRequest
)
http
.
Error
(
w
,
fmt
.
Sprintf
(
"params.EveryTxAmount*params.TxCount < params.RequestAmount && params.RequestAmount >
%d"
,
MaxRequestAmount
),
http
.
StatusBadRequest
)
return
}
//startTime := time.Now()
res
,
err
:=
web
.
ProduceTxs
(
params
.
From
,
params
.
ToAddrs
,
int
(
params
.
TxCount
),
params
.
EveryTxAmount
)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
//fmt.Printf("takes time: %s \n", time.Since(startTime).String())
resAsJson
,
err
:=
json
.
Marshal
(
res
)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
...
...
@@ -294,6 +293,9 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
for
{
var
hashesBytes
[]
byte
=
make
([]
byte
,
0
,
32
*
batchTxHashSize
)
var
beginOriginalTx
common
.
Hash
var
endOriginalTx
common
.
Hash
var
sendRedisBeginTime
time
.
Time
for
j
:=
0
;
j
<
batchTxHashSize
;
j
++
{
var
txsBytes
[]
byte
...
...
@@ -306,6 +308,12 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
return
nil
,
err
}
if
j
==
i
&&
i
==
0
{
beginOriginalTx
=
tx
.
Hash
()
}
endOriginalTx
=
tx
.
Hash
()
originalTxParam
.
Nonce
+=
1
txAsBytes
,
err
:=
tx
.
MarshalBinary
()
...
...
@@ -346,6 +354,9 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
batchTxs
:=
OriginalBatchTxs
{
Hash
:
hashBytes
,
Txs
:
txs
}
batchTxsForRedis
<-
&
batchTxs
if
j
==
0
{
sendRedisBeginTime
=
time
.
Now
()
}
if
txCount
==
0
{
break
...
...
@@ -359,6 +370,9 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
}
conTxsQueue
<-
ConTxsWithId
{
SendRedisTime
:
sendRedisBeginTime
,
BeginOriginalTx
:
beginOriginalTx
,
EndOriginalTx
:
endOriginalTx
,
Id
:
id
,
Tx
:
tx
}
...
...
originalTx.go
View file @
2db7e343
...
...
@@ -27,7 +27,8 @@ const batchTxHashQueueSize = 10
type
ConTxsWithId
struct
{
SendRedisTime
time
.
Time
OriginalTx
common
.
Hash
BeginOriginalTx
common
.
Hash
EndOriginalTx
common
.
Hash
Id
uuid
.
UUID
Tx
*
types
.
Transaction
}
...
...
transactor.go
View file @
2db7e343
...
...
@@ -11,6 +11,7 @@ import (
"time"
"code.wuban.net.cn/multisend/internal/logging"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/google/uuid"
"github.com/gorilla/websocket"
...
...
@@ -255,12 +256,22 @@ func (t *Transactor) sendTransactions() error {
}()
t
.
logger
.
Info
(
"Sending batch of transactions"
,
"now"
,
time
.
Now
()
.
Format
(
"15:04:05"
),
"toSend"
,
toSend
)
batchStartTime
:=
time
.
Now
()
var
sendToRedisStartTime
time
.
Time
var
beginTx
common
.
Hash
var
endTx
common
.
Hash
id
:=
uuid
.
UUID
{}
for
;
sent
<
toSend
;
sent
++
{
select
{
case
txWithId
:=
<-
conTxsQueue
:
id
=
txWithId
.
Id
sendToRedisStartTime
=
txWithId
.
SendRedisTime
if
sent
==
0
{
beginTx
=
txWithId
.
BeginOriginalTx
}
endTx
=
txWithId
.
EndOriginalTx
data
,
err
:=
txWithId
.
Tx
.
MarshalBinary
()
if
err
!=
nil
{
return
err
...
...
@@ -296,8 +307,10 @@ func (t *Transactor) sendTransactions() error {
if
record
,
ok
:=
GetSendRecord
(
id
);
ok
{
b
:=
BatchSend
{
BeginTime
:
batchStartTime
.
Unix
(),
EndTime
:
time
.
Now
()
.
Unix
(),
BeginOriginalTx
:
beginTx
,
EndOriginalTx
:
endTx
,
SendToRedisBeginTime
:
sendToRedisStartTime
.
Unix
(),
SendTxsEndTime
:
time
.
Now
()
.
Unix
(),
TxNum
:
sent
,
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment