Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
ChainGrpcPro
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
duanjinfei
ChainGrpcPro
Commits
cce4e4ad
Commit
cce4e4ad
authored
Mar 10, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
change signTx func to batchSign
parent
f1fb7079
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
48 additions
and
36 deletions
+48
-36
startTest.go
startTest.go
+3
-2
bathTest.go
transaction/bathTest.go
+1
-2
signedTx.go
transaction/signedTx.go
+44
-32
No files found.
startTest.go
View file @
cce4e4ad
...
...
@@ -26,7 +26,8 @@ func startTest() {
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
SignCount
=
txCount
/
100
cfg
.
BatchCount
=
batchCount
arr
,
fromAddrArr
:=
transaction
.
SignedTxArr
(
SendTxAccountArr
,
cfg
)
arr
:=
transaction
.
SignedTxArr
(
SendTxAccountArr
,
cfg
)
log
.
Info
(
"Sign tx successful"
)
if
batchSign
{
if
err
:=
transaction
.
BatchSignHandler
(
arr
,
cfg
);
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
...
...
@@ -40,7 +41,7 @@ func startTest() {
}
}
if
batchRecoverTx
{
if
err
:=
transaction
.
BatchRecoverTxHandler
(
arr
,
fromAddrArr
,
cfg
);
err
!=
nil
{
if
err
:=
transaction
.
BatchRecoverTxHandler
(
arr
,
cfg
);
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
return
}
...
...
transaction/bathTest.go
View file @
cce4e4ad
...
...
@@ -8,7 +8,6 @@ import (
v1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
crypterv1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/crypter/v1"
metatypes
"github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
...
...
@@ -244,7 +243,7 @@ func batchRecoverTx(client crypterv1.CrypterServiceClient, sleepTime int) {
}
// BatchRecoverTxHandler 处理批量发送的签名交易
func
BatchRecoverTxHandler
(
tranArr
[]
*
types
.
Transaction
,
fromAddrArr
[]
common
.
Address
,
cfg
*
tool
.
Config
)
error
{
func
BatchRecoverTxHandler
(
tranArr
[]
*
types
.
Transaction
,
cfg
*
tool
.
Config
)
error
{
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
log
.
Error
(
"dial nebula failed"
,
"err"
,
err
)
...
...
transaction/signedTx.go
View file @
cce4e4ad
...
...
@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"sync"
"sync
/atomic
"
"time"
)
...
...
@@ -28,6 +28,12 @@ type Transactor struct {
receivedAddr
common
.
Address
}
var
(
tran
=
make
(
chan
*
Transactor
,
0
)
tranArr
=
make
([]
*
types
.
Transaction
,
0
)
batchSignCount
int32
)
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
signerKey
,
err
:=
crypto
.
HexToECDSA
(
cfg
.
PrivateKey
)
if
err
!=
nil
{
...
...
@@ -50,17 +56,14 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
return
&
res
,
nil
}
var
accountsNonceMap
sync
.
Map
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
([]
*
types
.
Transaction
,
[]
common
.
Address
)
{
tranArr
:=
make
([]
*
types
.
Transaction
,
0
)
fromAddrArr
:=
make
([]
common
.
Address
,
0
)
var
signedTx
*
types
.
Transaction
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
go
signedTxFunc
(
)
}
for
_
,
rows
:=
range
sendTxAccountArr
{
fromAddrArr
=
append
(
fromAddrArr
,
common
.
HexToAddress
(
rows
[
0
]))
privateKey
:=
rows
[
1
]
nonce
:=
big
.
NewInt
(
1
)
nonce
:=
big
.
NewInt
(
0
)
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
tranCfg
:=
TranConfig
{
Amount
:
cfg
.
Amount
,
...
...
@@ -71,21 +74,26 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) ([]*types.Transa
Nonce
:
nonce
,
}
t
,
err
:=
newTransactor
(
tranCfg
)
signedTx
,
err
=
t
.
signedTx
()
txcache
.
Add
(
signedTx
.
Hash
()
.
Hex
(),
rows
[
0
])
nonce
=
big
.
NewInt
(
1
)
.
Add
(
nonce
,
big
.
NewInt
(
1
))
if
err
!=
nil
||
signedTx
==
nil
{
if
err
!=
nil
{
log
.
Errorf
(
"signed tx error %s "
,
err
)
continue
}
tranArr
=
append
(
tranArr
,
signedTx
)
tran
<-
t
nonce
=
big
.
NewInt
(
1
)
.
Add
(
nonce
,
big
.
NewInt
(
1
))
}
}
for
{
if
len
(
sendTxAccountArr
)
*
cfg
.
SignCount
==
int
(
batchSignCount
)
{
return
tranArr
}
}
return
tranArr
,
fromAddrArr
}
// signedTx 签名本币转账交易
func
(
t
*
Transactor
)
signedTx
()
(
*
types
.
Transaction
,
error
)
{
// signedTxFunc 签名本币转账交易
func
signedTxFunc
()
(
*
types
.
Transaction
,
error
)
{
for
{
select
{
case
t
:=
<-
tran
:
txData
:=
types
.
LegacyTx
{
Nonce
:
t
.
config
.
Nonce
.
Uint64
(),
To
:
&
t
.
receivedAddr
,
...
...
@@ -101,5 +109,9 @@ func (t *Transactor) signedTx() (*types.Transaction, error) {
time
.
Sleep
(
time
.
Second
)
return
nil
,
err
}
return
signedTx
,
nil
txcache
.
Add
(
signedTx
.
Hash
()
.
Hex
(),
t
.
sender
.
Hex
())
tranArr
=
append
(
tranArr
,
signedTx
)
atomic
.
AddInt32
(
&
batchSignCount
,
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