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
Hide 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() {
...
@@ -26,7 +26,8 @@ func startTest() {
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
GoRoutineCount
=
goRoutineCount
cfg
.
SignCount
=
txCount
/
100
cfg
.
SignCount
=
txCount
/
100
cfg
.
BatchCount
=
batchCount
cfg
.
BatchCount
=
batchCount
arr
,
fromAddrArr
:=
transaction
.
SignedTxArr
(
SendTxAccountArr
,
cfg
)
arr
:=
transaction
.
SignedTxArr
(
SendTxAccountArr
,
cfg
)
log
.
Info
(
"Sign tx successful"
)
if
batchSign
{
if
batchSign
{
if
err
:=
transaction
.
BatchSignHandler
(
arr
,
cfg
);
err
!=
nil
{
if
err
:=
transaction
.
BatchSignHandler
(
arr
,
cfg
);
err
!=
nil
{
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
...
@@ -40,7 +41,7 @@ func startTest() {
...
@@ -40,7 +41,7 @@ func startTest() {
}
}
}
}
if
batchRecoverTx
{
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
)
log
.
Errorf
(
"Bath Send Tran error: %s"
,
err
)
return
return
}
}
...
...
transaction/bathTest.go
View file @
cce4e4ad
...
@@ -8,7 +8,6 @@ import (
...
@@ -8,7 +8,6 @@ import (
v1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
v1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/base/v1"
crypterv1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/crypter/v1"
crypterv1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/crypter/v1"
metatypes
"github.com/CaduceusMetaverseProtocol/MetaTypes/types"
metatypes
"github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/grpc/credentials/insecure"
...
@@ -244,7 +243,7 @@ func batchRecoverTx(client crypterv1.CrypterServiceClient, sleepTime int) {
...
@@ -244,7 +243,7 @@ func batchRecoverTx(client crypterv1.CrypterServiceClient, sleepTime int) {
}
}
// BatchRecoverTxHandler 处理批量发送的签名交易
// 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
()))
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"dial nebula failed"
,
"err"
,
err
)
log
.
Error
(
"dial nebula failed"
,
"err"
,
err
)
...
...
transaction/signedTx.go
View file @
cce4e4ad
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/crypto"
"math/big"
"math/big"
"sync"
"sync
/atomic
"
"time"
"time"
)
)
...
@@ -28,6 +28,12 @@ type Transactor struct {
...
@@ -28,6 +28,12 @@ type Transactor struct {
receivedAddr
common
.
Address
receivedAddr
common
.
Address
}
}
var
(
tran
=
make
(
chan
*
Transactor
,
0
)
tranArr
=
make
([]
*
types
.
Transaction
,
0
)
batchSignCount
int32
)
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
func
newTransactor
(
cfg
TranConfig
)
(
*
Transactor
,
error
)
{
signerKey
,
err
:=
crypto
.
HexToECDSA
(
cfg
.
PrivateKey
)
signerKey
,
err
:=
crypto
.
HexToECDSA
(
cfg
.
PrivateKey
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -50,17 +56,14 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
...
@@ -50,17 +56,14 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
return
&
res
,
nil
return
&
res
,
nil
}
}
var
accountsNonceMap
sync
.
Map
// SignedTxArr 获取全部签名数据
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
([]
*
types
.
Transaction
,
[]
common
.
Address
)
{
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
tranArr
:=
make
([]
*
types
.
Transaction
,
0
)
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
fromAddrArr
:=
make
([]
common
.
Address
,
0
)
go
signedTxFunc
(
)
var
signedTx
*
types
.
Transaction
}
for
_
,
rows
:=
range
sendTxAccountArr
{
for
_
,
rows
:=
range
sendTxAccountArr
{
fromAddrArr
=
append
(
fromAddrArr
,
common
.
HexToAddress
(
rows
[
0
]))
privateKey
:=
rows
[
1
]
privateKey
:=
rows
[
1
]
nonce
:=
big
.
NewInt
(
1
)
nonce
:=
big
.
NewInt
(
0
)
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
for
signCount
:=
0
;
signCount
<
cfg
.
SignCount
;
signCount
++
{
tranCfg
:=
TranConfig
{
tranCfg
:=
TranConfig
{
Amount
:
cfg
.
Amount
,
Amount
:
cfg
.
Amount
,
...
@@ -71,35 +74,44 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) ([]*types.Transa
...
@@ -71,35 +74,44 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) ([]*types.Transa
Nonce
:
nonce
,
Nonce
:
nonce
,
}
}
t
,
err
:=
newTransactor
(
tranCfg
)
t
,
err
:=
newTransactor
(
tranCfg
)
signedTx
,
err
=
t
.
signedTx
()
if
err
!=
nil
{
txcache
.
Add
(
signedTx
.
Hash
()
.
Hex
(),
rows
[
0
])
nonce
=
big
.
NewInt
(
1
)
.
Add
(
nonce
,
big
.
NewInt
(
1
))
if
err
!=
nil
||
signedTx
==
nil
{
log
.
Errorf
(
"signed tx error %s "
,
err
)
log
.
Errorf
(
"signed tx error %s "
,
err
)
continue
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 签名本币转账交易
// signedTxFunc 签名本币转账交易
func
(
t
*
Transactor
)
signedTx
()
(
*
types
.
Transaction
,
error
)
{
func
signedTxFunc
()
(
*
types
.
Transaction
,
error
)
{
txData
:=
types
.
LegacyTx
{
for
{
Nonce
:
t
.
config
.
Nonce
.
Uint64
(),
select
{
To
:
&
t
.
receivedAddr
,
case
t
:=
<-
tran
:
Value
:
big
.
NewInt
(
t
.
config
.
Amount
),
txData
:=
types
.
LegacyTx
{
Gas
:
300000
,
Nonce
:
t
.
config
.
Nonce
.
Uint64
(),
GasPrice
:
big
.
NewInt
(
1000000001
),
To
:
&
t
.
receivedAddr
,
Data
:
nil
,
Value
:
big
.
NewInt
(
t
.
config
.
Amount
),
}
Gas
:
300000
,
newtx
:=
types
.
NewTx
(
&
txData
)
GasPrice
:
big
.
NewInt
(
1000000001
),
signedTx
,
err
:=
types
.
SignTx
(
newtx
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
t
.
config
.
ChainId
)),
t
.
signerKey
)
Data
:
nil
,
if
err
!=
nil
{
}
log
.
Errorf
(
"Send tx nonce: %d , From: %s , to: %s , error: %s"
,
t
.
config
.
Nonce
,
crypto
.
PubkeyToAddress
(
t
.
signerKey
.
PublicKey
),
t
.
receivedAddr
,
err
.
Error
())
newtx
:=
types
.
NewTx
(
&
txData
)
time
.
Sleep
(
time
.
Second
)
signedTx
,
err
:=
types
.
SignTx
(
newtx
,
types
.
NewEIP155Signer
(
big
.
NewInt
(
t
.
config
.
ChainId
)),
t
.
signerKey
)
return
nil
,
err
if
err
!=
nil
{
log
.
Errorf
(
"Send tx nonce: %d , From: %s , to: %s , error: %s"
,
t
.
config
.
Nonce
,
crypto
.
PubkeyToAddress
(
t
.
signerKey
.
PublicKey
),
t
.
receivedAddr
,
err
.
Error
())
time
.
Sleep
(
time
.
Second
)
return
nil
,
err
}
txcache
.
Add
(
signedTx
.
Hash
()
.
Hex
(),
t
.
sender
.
Hex
())
tranArr
=
append
(
tranArr
,
signedTx
)
atomic
.
AddInt32
(
&
batchSignCount
,
1
)
}
}
}
return
signedTx
,
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