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
a330bbc2
Commit
a330bbc2
authored
Mar 07, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
txs list page
parent
c2d0ede1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
73 additions
and
12 deletions
+73
-12
http.go
http.go
+55
-6
redis.go
redis.go
+18
-6
No files found.
http.go
View file @
a330bbc2
package
multisend
import
(
"context"
"crypto/sha256"
"encoding/json"
"fmt"
...
...
@@ -165,12 +166,34 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
}
type
resp
struct
{
HashList
[]
string
`json:"hash_list"`
Total
uint64
`json:"total"`
}
func
(
web
*
WebServicer
)
GetTxsList
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
vars
:=
mux
.
Vars
(
r
)
hashStr
:=
vars
[
"hash"
]
// hashAsBytes := []byte(hashStr)
startAsStr
:=
r
.
URL
.
Query
()
.
Get
(
"start"
)
numStr
:=
r
.
URL
.
Query
()
.
Get
(
"num"
)
startAsInt
,
err
:=
strconv
.
Atoi
(
startAsStr
)
if
err
!=
nil
{
startAsInt
=
0
}
numInt
,
err
:=
strconv
.
Atoi
(
numStr
)
if
err
!=
nil
{
numInt
=
10
}
if
startAsInt
!=
0
{
startAsInt
=
startAsInt
-
1
}
fmt
.
Printf
(
"startAsStr: %s offsetStr: %s startAs: %d offset: %d
\n
"
,
startAsStr
,
numStr
,
startAsInt
,
numInt
)
hashAsBytes
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
hashStr
)
...
...
@@ -179,12 +202,38 @@ func (web *WebServicer) GetTxsList(w http.ResponseWriter, r *http.Request) {
return
}
// if err := json.Unmarshal(hashStr, &hashAsBytes); err != nil {
// http.Error(w, err.Error(), http.StatusBadRequest)
// return
// }
total
,
err
:=
redisCli
.
LLen
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
hashAsBytes
))
.
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
()
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
)
resp
:=
resp
{
HashList
:
res
,
Total
:
total
,
}
recordAsJon
,
err
:=
json
.
Marshal
(
resp
)
if
err
!=
nil
{
http
.
Error
(
w
,
err
.
Error
(),
http
.
StatusInternalServerError
)
return
}
w
.
Header
()
.
Set
(
"Content-Type"
,
"application/json"
)
w
.
WriteHeader
(
http
.
StatusOK
)
w
.
Write
(
recordAsJon
)
return
fmt
.
Printf
(
"hashStr: %s len(hashStr): %d len(hashAsBytes): %d
\n
"
,
hashStr
,
len
(
hashStr
),
len
(
hashAsBytes
))
}
func
(
web
*
WebServicer
)
WebService
(
config
Config
)
error
{
...
...
redis.go
View file @
a330bbc2
...
...
@@ -13,6 +13,8 @@ import (
"golang.org/x/time/rate"
)
var
redisCli
*
redis
.
Client
func
initClient
(
poolSize
int
,
redisAddr
,
passwd
string
)
*
redis
.
Client
{
client
:=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
redisAddr
,
...
...
@@ -36,6 +38,11 @@ func Start(redisAddr, passwd string) {
logger
:=
logging
.
NewLogrusLogger
(
fmt
.
Sprintf
(
"redis[%s]"
,
redisAddr
))
client
:=
initClient
(
10
,
redisAddr
,
passwd
)
if
redisCli
==
nil
{
redisCli
=
client
}
count
:=
0
limiter
:=
rate
.
NewLimiter
(
rate
.
Every
(
time
.
Millisecond
*
100
),
1
)
cxt
,
_
:=
context
.
WithCancel
(
context
.
TODO
())
...
...
@@ -78,14 +85,19 @@ func Start(redisAddr, passwd string) {
panic
(
err
)
}
hashlistAsJson
,
err
:=
json
.
Marshal
(
hashs
)
//
hashlistAsJson, err := json.Marshal(hashs)
if
err
!=
nil
{
panic
(
err
)
}
//
if err != nil {
//
panic(err)
//
}
if
err
:=
client
.
LPush
(
context
.
Background
(),
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
hashlistAsJson
);
err
!=
nil
{
panic
(
err
)
for
k
,
v
:=
range
hashs
{
fmt
.
Printf
(
"idx: %d key: %s v: %s
\n
"
,
k
,
fmt
.
Sprintf
(
"%x"
,
batchTxs
.
Hash
),
v
.
Hex
())
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