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
8e9d6b47
Commit
8e9d6b47
authored
Mar 07, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
web data as hex
parent
a330bbc2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
23 deletions
+52
-23
http.go
http.go
+42
-18
redis.go
redis.go
+10
-5
No files found.
http.go
View file @
8e9d6b47
...
...
@@ -12,7 +12,6 @@ import (
"sync/atomic"
"time"
"encoding/base64"
"sync"
"github.com/ethereum/go-ethereum/common"
...
...
@@ -55,6 +54,11 @@ type ConsTxWithBatchHash struct {
BatchTxsHash
[]
byte
`json:"batch_txs_hash"`
}
type
ConsTxWithBatchHashAsHex
struct
{
ConsTxHash
string
`json:"cons_tx_hash"`
BatchTxsHash
[]
string
`json:"batch_txs_hash"`
}
type
BatchSend
struct
{
SendToRedisBeginTime
int64
`json:"send_to_redis_begin_time"`
SendTxsEndTime
int64
`json:"send_txs_end_time"`
...
...
@@ -132,20 +136,36 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
consTxWithBatchHashAsHex
:=
[]
ConsTxWithBatchHashAsHex
{}
if
record
,
ok
:=
GetSendRecord
(
id
);
ok
{
consTxWithBatchHash
:=
[]
ConsTxWithBatchHash
{}
for
_
,
v
:=
range
record
.
SendRecord
{
consTxWithBatchHash
=
append
(
consTxWithBatchHash
,
v
.
ConsTxWithBatchHash
...
)
}
for
_
,
v1
:=
range
v
.
ConsTxWithBatchHash
{
batchTxsAsHex
:=
[]
string
{}
// for _, hashAsBytes := range v1.BatchTxsHash {
// batchTxsAsHex = append(batchTxsAsHex, fmt.Sprintf("%x", hashAsBytes))
// }
for
i
:=
0
;
;
i
++
{
for
k
,
v
:=
range
consTxWithBatchHash
{
fmt
.
Printf
(
"idx: %d v: %d
\n
"
,
k
,
len
(
v
.
BatchTxsHash
))
if
len
(
v1
.
BatchTxsHash
)
<
32
{
break
}
batchTxsAsHex
=
append
(
batchTxsAsHex
,
fmt
.
Sprintf
(
"%x"
,
v1
.
BatchTxsHash
[
:
32
]))
v1
.
BatchTxsHash
=
v1
.
BatchTxsHash
[
32
:
]
}
consTxWithBatchHashAsHex
=
append
(
consTxWithBatchHashAsHex
,
ConsTxWithBatchHashAsHex
{
ConsTxHash
:
fmt
.
Sprintf
(
"%x"
,
v1
.
ConsTxHash
),
BatchTxsHash
:
batchTxsAsHex
,
})
}
}
recordAsJon
,
err
:=
json
.
Marshal
(
consTxWithBatchHash
)
recordAsJon
,
err
:=
json
.
Marshal
(
consTxWithBatchHash
AsHex
)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
...
...
@@ -195,27 +215,29 @@ func (web *WebServicer) GetTxsList(w http.ResponseWriter, r *http.Request) {
fmt
.
Printf
(
"startAsStr: %s offsetStr: %s startAs: %d offset: %d
\n
"
,
startAsStr
,
numStr
,
startAsInt
,
numInt
)
hashAsBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
hashStr
)
//
hashAsBytes, err := base64.StdEncoding.DecodeString(hashStr)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
//
if err != nil {
//
http.Error(w, err.Error(), http.StatusBadRequest)
//
return
//
}
total
,
err
:=
redisCli
.
LLen
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
hashAsBytes
))
.
Uint64
()
//total, err := redisCli.LLen(context.Background(), fmt.Sprintf("%x", hashAsBytes)).Uint64()
total
,
err
:=
redisCli
.
LLen
(
context
.
Background
(),
hashStr
)
.
Uint64
()
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
res
,
err
:=
redisCli
.
LRange
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
hashAsBytes
),
int64
(
startAsInt
*
numInt
),
int64
((
startAsInt
+
1
)
*
numInt
)
-
1
)
.
Result
()
//res, err := redisCli.LRange(context.Background(), fmt.Sprintf("%x", hashAsBytes), int64(startAsInt*numInt), int64((startAsInt+1)*numInt)-1).Result()
res
,
err
:=
redisCli
.
LRange
(
context
.
Background
(),
hashStr
,
int64
(
startAsInt
*
numInt
),
int64
((
startAsInt
+
1
)
*
numInt
)
-
1
)
.
Result
()
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusBadRequest
)
return
}
fmt
.
Printf
(
"hashStr: %s len(hashStr): %d
len(hashAsBytes): %d int64(startAsInt*numInt): %d int64((startAsInt+1)*numInt): %d res: %v
\n
"
,
hashStr
,
len
(
hashStr
),
len
(
hashAsBytes
),
int64
(
startAsInt
*
numInt
),
int64
((
startAsInt
+
1
)
*
numInt
-
1
),
res
)
fmt
.
Printf
(
"hashStr: %s len(hashStr): %d
int64(startAsInt*numInt): %d int64((startAsInt+1)*numInt): %d res: %v
\n
"
,
hashStr
,
len
(
hashStr
),
int64
(
startAsInt
*
numInt
),
int64
((
startAsInt
+
1
)
*
numInt
-
1
),
res
)
resp
:=
resp
{
HashList
:
res
,
...
...
@@ -412,6 +434,8 @@ type WebResp struct {
func
(
web
*
WebServicer
)
ProduceTxs
(
fromAddr
string
,
toAddrs
[]
string
,
txCount
int
,
amount
int64
,
id
uuid
.
UUID
)
error
{
consTxNum
:=
0
addrsL
:=
len
(
toAddrs
)
for
{
var
hashesBytes
[]
byte
=
make
([]
byte
,
0
,
32
*
batchTxHashSize
)
...
...
@@ -425,7 +449,7 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
txshash
:=
make
([]
string
,
0
,
batchTxSize
)
for
i
:=
0
;
i
<
batchTxSize
;
i
++
{
tx
,
err
:=
buildOriginalTx
(
originalTxParam
.
Nonce
,
toAddress
,
big
.
NewInt
(
256
),
nil
)
tx
,
err
:=
buildOriginalTx
(
originalTxParam
.
Nonce
,
common
.
HexToAddress
(
toAddrs
[
i
%
addrsL
])
,
big
.
NewInt
(
256
),
nil
)
if
err
!=
nil
{
return
err
}
...
...
redis.go
View file @
8e9d6b47
...
...
@@ -91,13 +91,18 @@ func Start(redisAddr, passwd string) {
// panic(err)
// }
for
k
,
v
:=
range
hashs
{
hashstr
:=
[]
string
{}
fmt
.
Printf
(
"idx: %d key: %s v: %s
\n
"
,
k
,
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
v
.
Hex
())
for
_
,
v
:=
range
hashs
{
//fmt.Printf("idx: %d key: %s v: %s \n", k, fmt.Sprintf("%x", batchTxs.Hash), v.Hex())
hashstr
=
append
(
hashstr
,
v
.
Hex
())
}
fmt
.
Printf
(
"batchTxHash %s list: %v
\n
"
,
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
hashstr
)
if
err
:=
client
.
LPush
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
hashstr
);
err
!=
nil
{
if
err
:=
client
.
LPush
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
v
.
Hex
());
err
!=
nil
{
//panic(err)
}
}
count
+=
1
...
...
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