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
64c2cd69
Commit
64c2cd69
authored
Feb 21, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
send tx to redis
parent
c66bf6c0
Changes
4
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
67 additions
and
10 deletions
+67
-10
client_eth.go
client_eth.go
+42
-8
go.mod
go.mod
+3
-0
go.sum
go.sum
+20
-0
transactor_test.go
transactor_test.go
+2
-2
No files found.
client_eth.go
View file @
64c2cd69
...
@@ -4,9 +4,13 @@ import (
...
@@ -4,9 +4,13 @@ import (
"context"
"context"
"crypto/ecdsa"
"crypto/ecdsa"
"crypto/md5"
"crypto/md5"
"encoding/hex"
"encoding/json"
"fmt"
"fmt"
"math/big"
"math/big"
"github.com/go-redis/redis/v8"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
...
@@ -85,7 +89,7 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
...
@@ -85,7 +89,7 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
txs
,
md5data
,
err
:=
getBatchTx
(
80
00
,
c
.
NodeRpcURL
,
false
)
txs
,
md5data
,
err
:=
getBatchTx
(
1
00
,
c
.
NodeRpcURL
,
false
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -104,9 +108,21 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
...
@@ -104,9 +108,21 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
return
signedTx
,
nil
return
signedTx
,
nil
}
}
func
getBatchTx
(
txNum
int
,
nodeUrl
string
,
signed
bool
)
([]
*
types
.
Transaction
,
[]
byte
,
error
)
{
type
Md5tx
struct
{
MD5
string
`json:md5`
Tx
*
types
.
Transaction
`json:tx`
}
var
ctx
=
context
.
Background
()
var
rdb
=
redis
.
NewClient
(
&
redis
.
Options
{
Addr
:
"54.250.115.98:6379"
,
Password
:
"redis20220217"
,
// no password set
DB
:
0
,
// use default DB
})
res
:=
make
([]
*
types
.
Transaction
,
0
,
txNum
)
func
getBatchTx
(
txNum
int
,
nodeUrl
string
,
signed
bool
)
([]
Md5tx
,
[]
byte
,
error
)
{
res
:=
make
([]
Md5tx
,
0
,
txNum
)
md5Data
:=
make
([]
byte
,
0
,
md5
.
Size
*
(
txNum
))
md5Data
:=
make
([]
byte
,
0
,
md5
.
Size
*
(
txNum
))
//publicKey := privateKey.Public()
//publicKey := privateKey.Public()
// publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
// publicKeyECDSA, ok := publicKey.(*ecdsa.PublicKey)
...
@@ -147,8 +163,6 @@ func getBatchTx(txNum int, nodeUrl string, signed bool) ([]*types.Transaction, [
...
@@ -147,8 +163,6 @@ func getBatchTx(txNum int, nodeUrl string, signed bool) ([]*types.Transaction, [
tx
:=
types
.
NewTransaction
(
0
+
uint64
(
i
),
toAddress
,
big
.
NewInt
(
10000000000000
),
4178026
,
big
.
NewInt
(
1000000000
),
nil
)
tx
:=
types
.
NewTransaction
(
0
+
uint64
(
i
),
toAddress
,
big
.
NewInt
(
10000000000000
),
4178026
,
big
.
NewInt
(
1000000000
),
nil
)
if
signed
{
if
signed
{
signedTx
,
err
:=
types
.
SignTx
(
tx
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
256
)),
privateKeyAsECDSA
)
signedTx
,
err
:=
types
.
SignTx
(
tx
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
256
)),
privateKeyAsECDSA
)
//signedTx, err := types.SignTx(tx, types.NewEIP155Signer(chainID), privateKey)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
...
@@ -160,9 +174,29 @@ func getBatchTx(txNum int, nodeUrl string, signed bool) ([]*types.Transaction, [
...
@@ -160,9 +174,29 @@ func getBatchTx(txNum int, nodeUrl string, signed bool) ([]*types.Transaction, [
return
nil
,
nil
,
err
return
nil
,
nil
,
err
}
}
hash
:=
md5
.
Sum
(
txAsBytes
)
md5Bytes
:=
md5
.
Sum
(
txAsBytes
)
md5Data
=
append
(
md5Data
,
hash
[
:
]
...
)
md5Data
=
append
(
md5Data
,
md5Bytes
[
:
]
...
)
res
=
append
(
res
,
tx
)
md5tx
:=
Md5tx
{
hex
.
EncodeToString
(
md5Bytes
[
:
]),
tx
}
res
=
append
(
res
,
md5tx
)
md5TxAsJson
,
err
:=
json
.
Marshal
(
md5tx
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
i
==
txNum
{
err
=
rdb
.
LPush
(
ctx
,
"list"
,
md5TxAsJson
)
.
Err
()
}
else
{
rdb
.
LPush
(
ctx
,
"list"
,
md5TxAsJson
)
}
if
err
!=
nil
{
panic
(
err
)
}
}
}
return
res
,
md5Data
,
nil
return
res
,
md5Data
,
nil
...
...
go.mod
View file @
64c2cd69
...
@@ -5,9 +5,12 @@ go 1.17
...
@@ -5,9 +5,12 @@ go 1.17
require (
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/ethereum/go-ethereum v1.10.16 // indirect
github.com/ethereum/go-ethereum v1.10.16 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-ole/go-ole v1.2.1 // indirect
github.com/go-redis/redis/v8 v8.11.4 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/go-stack/stack v1.8.0 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/gorilla/websocket v1.4.2 // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
github.com/shirou/gopsutil v3.21.4-0.20210419000835-c7a38de76ee5+incompatible // indirect
...
...
go.sum
View file @
64c2cd69
This diff is collapsed.
Click to expand it.
transactor_test.go
View file @
64c2cd69
...
@@ -21,9 +21,9 @@ func TestTransactor(t *testing.T) {
...
@@ -21,9 +21,9 @@ func TestTransactor(t *testing.T) {
if
err
!=
nil
{
if
err
!=
nil
{
t
.
Error
(
err
)
t
.
Error
(
err
)
}
}
//
transactor.sendTransactions()
transactor
.
sendTransactions
()
//transactor.sendLoop()
//transactor.sendLoop()
transactor
.
Start
()
//
transactor.Start()
time
.
Sleep
(
time
.
Second
*
60
)
time
.
Sleep
(
time
.
Second
*
60
)
...
...
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