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
bd65d8fc
Commit
bd65d8fc
authored
Feb 23, 2022
by
李伟@五瓣科技
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
heco testnet test
parent
5176ae54
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
94 additions
and
72 deletions
+94
-72
client_eth.go
client_eth.go
+5
-5
go.mod
go.mod
+1
-0
go.sum
go.sum
+2
-0
originalTx.go
originalTx.go
+81
-63
transactor_test.go
transactor_test.go
+5
-4
No files found.
client_eth.go
View file @
bd65d8fc
...
...
@@ -69,10 +69,10 @@ func (f *EthClientFactory) NewClient(cfg Config) (Client, error) {
buildTxParam
:=
EthClient
{
PrivateKey
:
sendTxPrivatekeyAsECDSA
,
FromAddr
:
sendTxFromAddress
,
//
NodeUrl: "http://13.40.31.153:8545",
NodeUrl
:
"http://13.40.31.153:8545"
,
//https://heco.getblock.io/mainnet/
//NodeUrl: "https://heco.getblock.io/mainnet/",
NodeUrl
:
"https://http-mainnet-node.huobichain.com"
,
//
NodeUrl: "https://http-mainnet-node.huobichain.com",
}
cli
,
err
:=
ethclient
.
Dial
(
buildTxParam
.
NodeUrl
)
...
...
@@ -105,7 +105,7 @@ func (f *EthClientFactory) NewClient(cfg Config) (Client, error) {
func
(
c
*
EthClient
)
GenerateTx
()
(
*
types
.
Transaction
,
error
)
{
select
{
case
md5Data
:=
<-
originalMd5
Queue
:
case
txRootHashList
:=
<-
originalTxsHash
Queue
:
if
c
.
GasLimit
==
0
{
cli
,
err
:=
ethclient
.
Dial
(
c
.
NodeUrl
)
if
err
!=
nil
{
...
...
@@ -114,7 +114,7 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
gasLimit
,
err
:=
cli
.
EstimateGas
(
context
.
Background
(),
ethereum
.
CallMsg
{
To
:
&
toAddress
,
Data
:
*
md5Data
,
Data
:
*
txRootHashList
,
})
if
err
!=
nil
{
return
nil
,
err
...
...
@@ -124,7 +124,7 @@ func (c *EthClient) GenerateTx() (*types.Transaction, error) {
}
tx
,
err
:=
buildSendTx
(
c
.
Nonce
,
toAddress
,
big
.
NewInt
(
1
),
c
.
GasLimit
,
c
.
GasPrice
,
*
md5Data
,
c
.
ChainId
,
c
.
PrivateKey
)
tx
,
err
:=
buildSendTx
(
c
.
Nonce
,
toAddress
,
big
.
NewInt
(
0
),
c
.
GasLimit
,
c
.
GasPrice
,
*
txRootHashList
,
c
.
ChainId
,
c
.
PrivateKey
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
go.mod
View file @
bd65d8fc
...
...
@@ -5,6 +5,7 @@ go 1.17
require (
github.com/StackExchange/wmi v0.0.0-20180116203802-5d049714c4a6 // indirect
github.com/btcsuite/btcd v0.20.1-beta // indirect
github.com/cbergoon/merkletree v0.2.0 // indirect
github.com/cespare/xxhash/v2 v2.1.2 // indirect
github.com/deckarep/golang-set v1.8.0 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
...
...
go.sum
View file @
bd65d8fc
...
...
@@ -68,6 +68,8 @@ github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku
github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
github.com/c-bata/go-prompt v0.2.2/go.mod h1:VzqtzE2ksDBcdln8G7mk2RX9QyGjH+OVqOCSiVIqS34=
github.com/cbergoon/merkletree v0.2.0 h1:Bttqr3OuoiZEo4ed1L7fTasHka9II+BF9fhBfbNEEoQ=
github.com/cbergoon/merkletree v0.2.0/go.mod h1:5c15eckUgiucMGDOCanvalj/yJnD+KAZj1qyJtRW5aM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/cespare/cp v0.1.0/go.mod h1:SOGHArjBr4JWaSDEVpWpo/hNg6RoKrls6Oh40hiwW+s=
github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
...
...
originalTx.go
View file @
bd65d8fc
...
...
@@ -2,92 +2,119 @@ package multisend
import
(
"context"
"crypto/
md5
"
"crypto/
ecdsa
"
"encoding/json"
"fmt"
"math/big"
"sync"
"time"
"crypto/sha256"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/go-redis/redis/v8"
// "github.com/cbergoon/merkletree"
)
var
originalTxParam
EthClient
var
originTxPrivateKey
string
=
"9e0944f587e1043d6e303644738b0c7c77ed15b176ca574ed0be40c0b9bbdc3a"
var
originalMd5Queue
chan
*
[]
byte
=
make
(
chan
*
[]
byte
,
1000
)
var
originalMd5TxQueue
chan
*
Md5tx
=
make
(
chan
*
Md5tx
,
500000
)
var
originalTxsHashQueue
chan
*
[]
byte
=
make
(
chan
*
[]
byte
,
1000
)
var
originalTxsWithFromQueue
chan
*
TxsHash
=
make
(
chan
*
TxsHash
,
2000000
)
const
batchSize
=
8000
const
batchSize
=
5
const
hashRootSize
=
2
func
init
()
{
origin
TxPrivateK
eyAsECDSA
,
err
:=
crypto
.
HexToECDSA
(
originTxPrivateKey
)
origin
alTxPrivatek
eyAsECDSA
,
err
:=
crypto
.
HexToECDSA
(
originTxPrivateKey
)
if
err
!=
nil
{
panic
(
err
)
}
originalTxPublicKey
:=
originalTxPrivatekeyAsECDSA
.
Public
()
originalTxPublicKeyECDSA
,
ok
:=
originalTxPublicKey
.
(
*
ecdsa
.
PublicKey
)
if
!
ok
{
panic
(
"publicKey.(*ecdsa.PublicKey) not ok"
)
}
originalTxFromAddress
:=
crypto
.
PubkeyToAddress
(
*
originalTxPublicKeyECDSA
)
originalTxParam
=
EthClient
{
PrivateKey
:
originTxPrivateKeyAsECDSA
,
PrivateKey
:
originalTxPrivatekeyAsECDSA
,
FromAddr
:
originalTxFromAddress
,
Nonce
:
0
,
}
}
type
Md5tx
struct
{
MD5
string
`json:md5`
Tx
*
types
.
Transaction
`json:tx`
type
TxsHash
struct
{
Hash
[]
byte
Tx
s
[]
TxWithFrom
}
func
ProduceOriginalTx
()
{
type
TxWithFrom
struct
{
From
common
.
Address
`json:md5`
Tx
*
types
.
Transaction
`json:tx`
}
for
{
// //CalculateHash hashes the values of a TestContent
// func (t TxWithFrom) CalculateHash() ([]byte, error) {
// hash := t.Tx.Hash()
// return hash[:], nil
// }
//fmt.Printf("len(originalTxQueue): %d len(originalMd5TxQueue): %d \n", len(originalTxQueue), len(originalMd5TxQueue))
if
len
(
originalMd5Queue
)
<
100
{
// //Equals tests for equality of two Contents
// func (t TxWithFrom) Equals(other merkletree.Content) (bool, error) {
// return t.Tx.Hash().Big().Cmp(other.(TxWithFrom).Tx.Hash().Big()) == 0, nil
// }
var
md5Data
[]
byte
=
make
([]
byte
,
0
,
md5
.
Size
*
(
batchSize
))
func
ProduceOriginalTx
()
error
{
for
i
:=
0
;
i
<
batchSize
;
i
++
{
tx
,
err
:=
buildOriginalTx
(
originalTxParam
.
Nonce
,
toAddress
,
big
.
NewInt
(
256
),
nil
)
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
continue
}
originalTxParam
.
Nonce
+=
1
for
{
txAsBytes
,
err
:=
tx
.
MarshalBinary
()
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
continue
//fmt.Printf("len(originalTxQueue): %d len(originalMd5TxQueue): %d \n", len(originalTxQueue), len(originalMd5TxQueue))
if
len
(
originalTxsHashQueue
)
<
200
{
var
hashesBytes
[]
byte
=
make
([]
byte
,
0
,
hashRootSize
)
for
j
:=
0
;
j
<
hashRootSize
;
j
++
{
var
txsBytes
[]
byte
var
txsWithFrom
[]
TxWithFrom
=
make
([]
TxWithFrom
,
0
,
batchSize
)
for
i
:=
0
;
i
<
batchSize
;
i
++
{
tx
,
err
:=
buildOriginalTx
(
originalTxParam
.
Nonce
,
toAddress
,
big
.
NewInt
(
256
),
nil
)
if
err
!=
nil
{
return
err
}
txsWithFrom
=
append
(
txsWithFrom
,
TxWithFrom
{
From
:
originalTxParam
.
FromAddr
,
Tx
:
tx
,
})
originalTxParam
.
Nonce
+=
1
txAsBytes
,
err
:=
tx
.
MarshalBinary
()
if
err
!=
nil
{
return
err
}
txsBytes
=
append
(
txsBytes
,
txAsBytes
...
)
}
md5Bytes
:=
md5
.
Sum
(
txAsBytes
)
md5Data
=
append
(
md5Data
,
md5Bytes
[
:
]
...
)
}
//startTime := time.Now()
// fp, err := os.Create("bin")
// if err != nil {
// fmt.Println(err)
// return
// }
// defer fp.Close()
// buf := new(bytes.Buffer)
// binary.Write(buf, binary.LittleEndian, md5Data)
// fp.Write(buf.Bytes())
fmt
.
Printf
(
"len(md5Data): %d
\n
"
,
len
(
md5Data
))
h
:=
sha256
.
New
()
if
_
,
err
:=
h
.
Write
(
txsBytes
);
err
!=
nil
{
return
err
}
originalMd5Queue
<-
&
md5Data
hashBytes
:=
h
.
Sum
(
nil
)
hashesBytes
=
append
(
hashesBytes
,
hashBytes
...
)
//fmt.Printf("time.Since(startTime): %s \n", fmt.Sprintf("%.20f", time.Since(startTime).Seconds()))
//md5tx := Md5tx{hex.EncodeToString(md5Bytes[:]), tx}
//originalMd5TxQueue <- &md5tx
txs
:=
TxsHash
{
hashBytes
,
txsWithFrom
}
originalTxsWithFromQueue
<-
&
txs
}
originalTxsHashQueue
<-
&
hashesBytes
}
else
{
return
return
nil
time
.
Sleep
(
time
.
Millisecond
*
1
)
}
}
...
...
@@ -108,27 +135,15 @@ func SendMd5Tx() {
// sendTicker := time.NewTicker(time.Duration(5) * time.Second)
for
{
// if count > 50 {
// // fmt.Printf("current count: %d \n", count)
// // rdb.Context().Err()
// // sendTicker.Reset(time.Duration(5) * time.Second)
// // count = 0
// }
select
{
//case <-sendTicker.C:
// fmt.Printf("5s timeout\n")
// rdb.Context().Err()
// count = 0
case
md5Tx
:=
<-
originalMd5TxQueue
:
md5TxAsJson
,
err
:=
json
.
Marshal
(
md5Tx
)
case
txs
:=
<-
originalTxsWithFromQueue
:
txsAsJson
,
err
:=
json
.
Marshal
(
txs
)
if
err
!=
nil
{
fmt
.
Println
(
err
.
Error
())
continue
}
rdb
.
LPush
(
ctx
,
"list"
,
md5Tx
AsJson
)
rdb
.
LPush
(
ctx
,
"list"
,
txs
AsJson
)
}
}
}
...
...
@@ -140,7 +155,10 @@ func StartProduceTx() {
go
func
()
{
defer
wg
.
Done
()
ProduceOriginalTx
()
if
err
:=
ProduceOriginalTx
();
err
!=
nil
{
fmt
.
Printf
(
"ProduceOriginalTx stop err: %s
\n
"
,
err
.
Error
())
}
}()
go
func
()
{
...
...
transactor_test.go
View file @
bd65d8fc
...
...
@@ -10,23 +10,24 @@ func TestTransactor(t *testing.T) {
go
StartProduceTx
()
for
{
if
len
(
original
Md5
Queue
)
>=
100
{
if
len
(
original
TxsHash
Queue
)
>=
100
{
break
}
t
.
Logf
(
"waiting for produce original tx, len(original
Md5Queue):%d
\n
"
,
len
(
originalMd5
Queue
))
t
.
Logf
(
"waiting for produce original tx, len(original
TxsHashQueue):%d
\n
"
,
len
(
originalTxsHash
Queue
))
time
.
Sleep
(
1
*
time
.
Second
)
}
cfg
:=
Config
{
Rate
:
5
,
Count
:
2
0
,
Count
:
3
0
,
Connections
:
1
,
Time
:
100
,
SendPeriod
:
3
,
ClientFactory
:
"ethclient"
,
}
//wss://ws-mainnet-node.huobichain.com
transactor
,
err
:=
NewTransactor
(
"wss://ws-mainnet-node.huobichain.com"
,
&
cfg
)
//transactor, err := NewTransactor("wss://ws-mainnet-node.huobichain.com", &cfg)
transactor
,
err
:=
NewTransactor
(
"ws://13.40.31.153:8546"
,
&
cfg
)
if
err
!=
nil
{
t
.
Error
(
err
)
...
...
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