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
2a3647b6
Commit
2a3647b6
authored
Mar 08, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
first tx amount with diff from
parent
ba73e98d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
109 additions
and
1 deletion
+109
-1
http.go
http.go
+72
-1
redis_test.go
redis_test.go
+36
-0
transactor.go
transactor.go
+1
-0
No files found.
http.go
View file @
2a3647b6
...
@@ -15,6 +15,7 @@ import (
...
@@ -15,6 +15,7 @@ import (
"sync"
"sync"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/google/uuid"
"github.com/google/uuid"
"github.com/gorilla/mux"
"github.com/gorilla/mux"
hdwallet
"github.com/miguelmota/go-ethereum-hdwallet"
hdwallet
"github.com/miguelmota/go-ethereum-hdwallet"
...
@@ -27,6 +28,24 @@ var mnemonic = "matter someone fee garlic final police during vapor stool cargo
...
@@ -27,6 +28,24 @@ var mnemonic = "matter someone fee garlic final police during vapor stool cargo
var
processMap
sync
.
Map
var
processMap
sync
.
Map
var
Running
int32
=
0
var
Running
int32
=
0
var
systemFromAddr
string
func
init
()
{
wallet
,
err
:=
hdwallet
.
NewFromMnemonic
(
mnemonic
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
path
:=
hdwallet
.
MustParseDerivationPath
(
fmt
.
Sprintf
(
"m/44'/60'/0'/0/%d"
,
0
))
account
,
err
:=
wallet
.
Derive
(
path
,
false
)
if
err
!=
nil
{
panic
(
err
)
}
systemFromAddr
=
account
.
Address
.
Hex
()
}
func
GetSendRecord
(
id
uuid
.
UUID
)
(
SendRecord
,
bool
)
{
func
GetSendRecord
(
id
uuid
.
UUID
)
(
SendRecord
,
bool
)
{
if
vAsInterface
,
ok
:=
processMap
.
Load
(
id
);
ok
{
if
vAsInterface
,
ok
:=
processMap
.
Load
(
id
);
ok
{
...
@@ -36,11 +55,39 @@ func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
...
@@ -36,11 +55,39 @@ func GetSendRecord(id uuid.UUID) (SendRecord, bool) {
}
}
}
}
recordAsJson
,
err
:=
redisCli
.
Get
(
context
.
Background
(),
id
.
String
())
.
Result
()
if
err
!=
nil
{
panic
(
err
)
}
fmt
.
Printf
(
"recordAsJson: %s
\n
"
,
recordAsJson
)
// sendRec := SendRecord{}
// if err := json.Unmarshal([]byte(recordAsJson), sendRec); err != nil {
// panic(err)
// }
return
SendRecord
{},
false
return
SendRecord
{},
false
}
}
func
SetSendRecord
(
id
uuid
.
UUID
,
value
SendRecord
)
{
func
SetSendRecord
(
id
uuid
.
UUID
,
value
SendRecord
)
{
processMap
.
Store
(
id
,
value
)
processMap
.
Store
(
id
,
value
)
sent
:=
0
for
_
,
v
:=
range
value
.
SendRecord
{
sent
+=
v
.
TxNum
}
if
sent
==
int
(
value
.
TotalConsTx
)
{
recoradAsJson
,
err
:=
json
.
Marshal
(
value
)
if
err
!=
nil
{
panic
(
err
)
}
redisCli
.
Set
(
context
.
Background
(),
id
.
String
(),
recoradAsJson
,
time
.
Hour
*
24
)
}
}
}
type
SendRecord
struct
{
type
SendRecord
struct
{
...
@@ -175,6 +222,8 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
...
@@ -175,6 +222,8 @@ func (web *WebServicer) GetTreeHandler(w http.ResponseWriter, r *http.Request) {
}
}
// record := redisCli.Get(context.Background(), id.String()).Scan()
if
err
!=
nil
{
if
err
!=
nil
{
http
.
Error
(
w
,
fmt
.
Sprintf
(
"can not find the uuid: %s "
,
id
.
String
()),
http
.
StatusInternalServerError
)
http
.
Error
(
w
,
fmt
.
Sprintf
(
"can not find the uuid: %s "
,
id
.
String
()),
http
.
StatusInternalServerError
)
return
return
...
@@ -432,6 +481,8 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
...
@@ -432,6 +481,8 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
addrsL
:=
len
(
toAddrs
)
addrsL
:=
len
(
toAddrs
)
first
:=
true
for
{
for
{
var
hashesBytes
[]
byte
=
make
([]
byte
,
0
,
32
*
batchTxHashSize
)
var
hashesBytes
[]
byte
=
make
([]
byte
,
0
,
32
*
batchTxHashSize
)
...
@@ -445,7 +496,17 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
...
@@ -445,7 +496,17 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
txshash
:=
make
([]
string
,
0
,
batchTxSize
)
txshash
:=
make
([]
string
,
0
,
batchTxSize
)
for
i
:=
0
;
i
<
batchTxSize
;
i
++
{
for
i
:=
0
;
i
<
batchTxSize
;
i
++
{
tx
,
err
:=
buildOriginalTx
(
originalTxParam
.
Nonce
,
common
.
HexToAddress
(
toAddrs
[
i
%
addrsL
]),
amount
,
big
.
NewInt
(
256
),
nil
)
var
tx
*
types
.
Transaction
var
err
error
if
fromAddr
!=
systemFromAddr
&&
first
{
tx
,
err
=
buildOriginalTx
(
originalTxParam
.
Nonce
,
common
.
HexToAddress
(
fromAddr
),
amount
*
int64
(
txCount
),
big
.
NewInt
(
256
),
nil
)
first
=
false
}
else
{
tx
,
err
=
buildOriginalTx
(
originalTxParam
.
Nonce
,
common
.
HexToAddress
(
toAddrs
[
i
%
addrsL
]),
amount
,
big
.
NewInt
(
256
),
nil
)
}
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
@@ -465,6 +526,16 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
...
@@ -465,6 +526,16 @@ func (web *WebServicer) ProduceTxs(fromAddr string, toAddrs []string, txCount in
txsBytes
=
append
(
txsBytes
,
txAsBytes
...
)
txsBytes
=
append
(
txsBytes
,
txAsBytes
...
)
if
fromAddr
!=
systemFromAddr
&&
first
{
txs
=
append
(
txs
,
TxWithFrom
{
[]
byte
(
systemFromAddr
),
tx
})
}
else
{
txs
=
append
(
txs
,
TxWithFrom
{
originalTxParam
.
FromAddr
[
:
],
tx
})
}
txs
=
append
(
txs
,
TxWithFrom
{
txs
=
append
(
txs
,
TxWithFrom
{
originalTxParam
.
FromAddr
[
:
],
originalTxParam
.
FromAddr
[
:
],
tx
})
tx
})
...
...
redis_test.go
View file @
2a3647b6
package
multisend
package
multisend
import
(
import
(
"context"
"encoding/json"
"testing"
"testing"
"time"
"github.com/google/uuid"
)
)
func
TestRateLimit
(
t
*
testing
.
T
)
{
func
TestRateLimit
(
t
*
testing
.
T
)
{
...
@@ -23,3 +28,34 @@ func TestRateLimit(t *testing.T) {
...
@@ -23,3 +28,34 @@ func TestRateLimit(t *testing.T) {
// }
// }
}
}
type
Person
struct
{
Name
string
`json:"name"`
Age
int64
`json:"age"`
}
func
TestSetGetJson
(
t
*
testing
.
T
)
{
client
:=
initClient
(
10
,
"13.40.18.11:6379"
,
"redis20220217"
)
id
:=
uuid
.
New
()
p1
:=
Person
{
Name
:
"alice"
,
Age
:
10
,
}
p1AsJson
,
err
:=
json
.
Marshal
(
p1
)
if
err
!=
nil
{
panic
(
err
)
}
client
.
Set
(
context
.
Background
(),
id
.
String
(),
p1AsJson
,
time
.
Hour
*
24
)
recordAsJson
,
err
:=
client
.
Get
(
context
.
Background
(),
"111"
)
.
Result
()
if
err
!=
nil
{
panic
(
err
)
}
t
.
Logf
(
"recordAsJson: %s
\n
"
,
recordAsJson
)
}
transactor.go
View file @
2a3647b6
...
@@ -322,6 +322,7 @@ func (t *Transactor) sendTransactions() error {
...
@@ -322,6 +322,7 @@ func (t *Transactor) sendTransactions() error {
record
.
SendRecord
=
append
(
record
.
SendRecord
,
b
)
record
.
SendRecord
=
append
(
record
.
SendRecord
,
b
)
SetSendRecord
(
id
,
record
)
SetSendRecord
(
id
,
record
)
}
}
return
nil
return
nil
...
...
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