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
31b788f2
Commit
31b788f2
authored
Mar 10, 2023
by
duanjinfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix nil point err
parent
521b6f8d
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
93 additions
and
7 deletions
+93
-7
app.json
config/app.json
+1
-1
main.go
main.go
+1
-1
grpc_test.go
test/grpc_test.go
+63
-0
bathTest.go
transaction/bathTest.go
+3
-1
signedTx.go
transaction/signedTx.go
+25
-4
No files found.
config/app.json
View file @
31b788f2
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
"receiveAddr"
:
"0x0Fb196385c8826e3806ebA2cA2cb78B26E08fEEe"
,
"receiveAddr"
:
"0x0Fb196385c8826e3806ebA2cA2cb78B26E08fEEe"
,
"count"
:
100
,
"count"
:
100
,
"type"
:
1
,
"type"
:
1
,
"rpcNode"
:
"
35.78.87.116:38002
"
,
"rpcNode"
:
"
54.168.125.67:8545
"
,
"amount"
:
10000000
,
"amount"
:
10000000
,
"chainId"
:
100
,
"chainId"
:
100
,
"initAccountPrv"
:
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
,
"initAccountPrv"
:
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
,
...
...
main.go
View file @
31b788f2
...
@@ -22,7 +22,7 @@ func init() {
...
@@ -22,7 +22,7 @@ func init() {
startCmd
.
PersistentFlags
()
.
StringVar
(
&
cpuProfile
,
"cpuProfile"
,
"cpuProfile.prof"
,
"Statistics cpu profile"
)
startCmd
.
PersistentFlags
()
.
StringVar
(
&
cpuProfile
,
"cpuProfile"
,
"cpuProfile.prof"
,
"Statistics cpu profile"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
startCount
,
"startCount"
,
0
,
"read excel start count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
startCount
,
"startCount"
,
0
,
"read excel start count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
endCount
,
"endCount"
,
100
,
"read excel end count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
endCount
,
"endCount"
,
100
,
"read excel end count"
)
startCmd
.
PersistentFlags
()
.
BoolVar
(
&
broadcastTxArr
,
"broadcastTxArr"
,
fals
e
,
"test grpc interface -> broadcastTxArr"
)
startCmd
.
PersistentFlags
()
.
BoolVar
(
&
broadcastTxArr
,
"broadcastTxArr"
,
tru
e
,
"test grpc interface -> broadcastTxArr"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
txCount
,
"txCount"
,
1000
,
"send tran count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
txCount
,
"txCount"
,
1000
,
"send tran count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
goRoutineCount
,
"goRoutineCount"
,
10
,
"send tran goRoutine count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
goRoutineCount
,
"goRoutineCount"
,
10
,
"send tran goRoutine count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
batchCount
,
"batchCount"
,
100
,
"batch send tran count"
)
startCmd
.
PersistentFlags
()
.
IntVar
(
&
batchCount
,
"batchCount"
,
100
,
"batch send tran count"
)
...
...
test/grpc_test.go
0 → 100644
View file @
31b788f2
package
test
import
(
"context"
"crypto/ecdsa"
ringv1
"github.com/CaduceusMetaverseProtocol/MetaProtocol/gen/proto/go/ring/v1"
metatypes
"github.com/CaduceusMetaverseProtocol/MetaTypes/types"
"github.com/ethereum/go-ethereum/crypto"
"google.golang.org/grpc"
"net"
"strings"
"testing"
"time"
)
func
TestNonce
(
t
*
testing
.
T
)
{
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
publicKey
:=
local
.
Public
()
publicKeyECDSA
,
_
:=
publicKey
.
(
*
ecdsa
.
PublicKey
)
fromAddr
:=
crypto
.
PubkeyToAddress
(
*
publicKeyECDSA
)
c
:=
StartGRPCClient
(
"54.168.125.67:8545"
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
8
)
defer
cancel
()
nonce
,
err
:=
c
.
Nonce
(
ctx
,
&
ringv1
.
NonceRequest
{
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
())})
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
t
.
Logf
(
"nonce: %v
\n
"
,
nonce
.
Nonce
)
}
func
StartGRPCClient
(
protoAddr
string
)
ringv1
.
RingServiceClient
{
//nolint:staticcheck // SA1019 Existing use of deprecated but supported dial option.
conn
,
err
:=
grpc
.
Dial
(
protoAddr
,
grpc
.
WithInsecure
(),
grpc
.
WithContextDialer
(
dialerFunc
))
if
err
!=
nil
{
panic
(
err
)
}
return
ringv1
.
NewRingServiceClient
(
conn
)
}
func
dialerFunc
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
Connect
(
addr
)
}
func
Connect
(
protoAddr
string
)
(
net
.
Conn
,
error
)
{
proto
,
address
:=
ProtocolAndAddress
(
protoAddr
)
conn
,
err
:=
net
.
Dial
(
proto
,
address
)
return
conn
,
err
}
func
ProtocolAndAddress
(
listenAddr
string
)
(
string
,
string
)
{
protocol
,
address
:=
"tcp"
,
listenAddr
parts
:=
strings
.
SplitN
(
address
,
"://"
,
2
)
if
len
(
parts
)
==
2
{
protocol
,
address
=
parts
[
0
],
parts
[
1
]
}
return
protocol
,
address
}
transaction/bathTest.go
View file @
31b788f2
...
@@ -81,7 +81,9 @@ func broadcastTx(client ring.RingServiceClient) error {
...
@@ -81,7 +81,9 @@ func broadcastTx(client ring.RingServiceClient) error {
if
beforeSendTxTime
.
UnixMilli
()
>
0
&&
time
.
Since
(
beforeSendTxTime
)
.
Milliseconds
()
<
1
{
if
beforeSendTxTime
.
UnixMilli
()
>
0
&&
time
.
Since
(
beforeSendTxTime
)
.
Milliseconds
()
<
1
{
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
1
))
time
.
Sleep
(
time
.
Millisecond
*
time
.
Duration
(
1
))
}
}
txs
,
err
:=
client
.
BroadcastTxs
(
context
.
Background
(),
broadcastEthTxWithFromRequests
,
nil
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
9
)
defer
cancel
()
txs
,
err
:=
client
.
BroadcastTxs
(
ctx
,
broadcastEthTxWithFromRequests
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"BroadcastTxs Error:"
,
err
)
log
.
Error
(
"BroadcastTxs Error:"
,
err
)
}
}
...
...
transaction/signedTx.go
View file @
31b788f2
...
@@ -12,8 +12,9 @@ import (
...
@@ -12,8 +12,9 @@ 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"
"google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"math/big"
"math/big"
"net"
"strings"
"sync/atomic"
"sync/atomic"
"time"
"time"
)
)
...
@@ -61,12 +62,29 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
...
@@ -61,12 +62,29 @@ func newTransactor(cfg TranConfig) (*Transactor, error) {
return
&
res
,
nil
return
&
res
,
nil
}
}
func
dialerFunc
(
ctx
context
.
Context
,
addr
string
)
(
net
.
Conn
,
error
)
{
return
Connect
(
addr
)
}
func
Connect
(
protoAddr
string
)
(
net
.
Conn
,
error
)
{
proto
,
address
:=
ProtocolAndAddress
(
protoAddr
)
conn
,
err
:=
net
.
Dial
(
proto
,
address
)
return
conn
,
err
}
func
ProtocolAndAddress
(
listenAddr
string
)
(
string
,
string
)
{
protocol
,
address
:=
"tcp"
,
listenAddr
parts
:=
strings
.
SplitN
(
address
,
"://"
,
2
)
if
len
(
parts
)
==
2
{
protocol
,
address
=
parts
[
0
],
parts
[
1
]
}
return
protocol
,
address
}
// SignedTxArr 获取全部签名数据
// SignedTxArr 获取全部签名数据
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
func
SignedTxArr
(
sendTxAccountArr
[][]
string
,
cfg
*
tool
.
Config
)
[]
*
types
.
Transaction
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
for
i
:=
0
;
i
<
cfg
.
GoRoutineCount
;
i
++
{
go
signedTxFunc
()
go
signedTxFunc
()
}
}
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
With
TransportCredentials
(
insecure
.
NewCredentials
()
))
client
,
err
:=
grpc
.
Dial
(
cfg
.
RpcNode
,
grpc
.
With
Insecure
(),
grpc
.
WithContextDialer
(
dialerFunc
))
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"grpc dial error:"
,
err
)
log
.
Error
(
"grpc dial error:"
,
err
)
return
nil
return
nil
...
@@ -77,10 +95,13 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) []*types.Transac
...
@@ -77,10 +95,13 @@ func SignedTxArr(sendTxAccountArr [][]string, cfg *tool.Config) []*types.Transac
privateKey
:=
rows
[
1
]
privateKey
:=
rows
[
1
]
fromAddr
:=
metatypes
.
HexToAddress
(
rows
[
0
])
fromAddr
:=
metatypes
.
HexToAddress
(
rows
[
0
])
nonceReq
:=
&
ring
.
NonceRequest
{
nonceReq
:=
&
ring
.
NonceRequest
{
Address
:
&
fromAddr
,
Address
:
(
*
metatypes
.
Address
)(
fromAddr
.
Bytes
())
,
}
}
response
,
err
:=
serviceClient
.
Nonce
(
context
.
Background
(),
nonceReq
,
nil
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
*
9
)
defer
cancel
()
response
,
err
:=
serviceClient
.
Nonce
(
ctx
,
nonceReq
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Error
(
"get account nonce error:"
,
err
)
return
nil
return
nil
}
}
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
response
.
Nonce
)
nonce
:=
new
(
big
.
Int
)
.
SetUint64
(
response
.
Nonce
)
...
...
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