Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
MetaProtocol
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
Nebula
MetaProtocol
Commits
19de5d65
Commit
19de5d65
authored
Nov 29, 2022
by
Ubuntu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add tx as any grpc
parent
e6fdb174
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
199 additions
and
61 deletions
+199
-61
resource.proto
baseapi/base/v1/resource.proto
+2
-2
resource.pb.go
gen/proto/go/base/v1/resource.pb.go
+8
-8
service.pb.go
gen/proto/go/ring/v1/service.pb.go
+32
-24
service_grpc.pb.go
gen/proto/go/ring/v1/service_grpc.pb.go
+38
-0
grcp-tx_test.go
grcp-tx_test.go
+115
-27
service.proto
ringapi/ring/v1/service.proto
+4
-0
No files found.
baseapi/base/v1/resource.proto
View file @
19de5d65
...
...
@@ -94,13 +94,13 @@ message Transaction{
message
TransactionStd
{
TxProof
tx_proof
=
1
;
int64
timeout_block_num
=
2
;
EthTx
tx
=
3
;
StdTx
tx
=
3
;
}
message
TransactionEth
{
TxProof
tx_proof
=
1
;
int64
timeout_block_num
=
2
;
Std
Tx
tx
=
3
;
Eth
Tx
tx
=
3
;
}
//3. bytes
...
...
gen/proto/go/base/v1/resource.pb.go
View file @
19de5d65
...
...
@@ -720,7 +720,7 @@ type TransactionStd struct {
TxProof
*
TxProof
`protobuf:"bytes,1,opt,name=tx_proof,json=txProof,proto3" json:"tx_proof,omitempty"`
TimeoutBlockNum
int64
`protobuf:"varint,2,opt,name=timeout_block_num,json=timeoutBlockNum,proto3" json:"timeout_block_num,omitempty"`
Tx
*
Eth
Tx
`protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"`
Tx
*
Std
Tx
`protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"`
}
func
(
x
*
TransactionStd
)
Reset
()
{
...
...
@@ -769,7 +769,7 @@ func (x *TransactionStd) GetTimeoutBlockNum() int64 {
return
0
}
func
(
x
*
TransactionStd
)
GetTx
()
*
Eth
Tx
{
func
(
x
*
TransactionStd
)
GetTx
()
*
Std
Tx
{
if
x
!=
nil
{
return
x
.
Tx
}
...
...
@@ -783,7 +783,7 @@ type TransactionEth struct {
TxProof
*
TxProof
`protobuf:"bytes,1,opt,name=tx_proof,json=txProof,proto3" json:"tx_proof,omitempty"`
TimeoutBlockNum
int64
`protobuf:"varint,2,opt,name=timeout_block_num,json=timeoutBlockNum,proto3" json:"timeout_block_num,omitempty"`
Tx
*
Std
Tx
`protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"`
Tx
*
Eth
Tx
`protobuf:"bytes,3,opt,name=tx,proto3" json:"tx,omitempty"`
}
func
(
x
*
TransactionEth
)
Reset
()
{
...
...
@@ -832,7 +832,7 @@ func (x *TransactionEth) GetTimeoutBlockNum() int64 {
return
0
}
func
(
x
*
TransactionEth
)
GetTx
()
*
Std
Tx
{
func
(
x
*
TransactionEth
)
GetTx
()
*
Eth
Tx
{
if
x
!=
nil
{
return
x
.
Tx
}
...
...
@@ -993,7 +993,7 @@ var file_base_v1_resource_proto_rawDesc = []byte{
0x6c
,
0x6f
,
0x63
,
0x6b
,
0x5f
,
0x6e
,
0x75
,
0x6d
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x03
,
0x52
,
0x0f
,
0x74
,
0x69
,
0x6d
,
0x65
,
0x6f
,
0x75
,
0x74
,
0x42
,
0x6c
,
0x6f
,
0x63
,
0x6b
,
0x4e
,
0x75
,
0x6d
,
0x12
,
0x1e
,
0x0a
,
0x02
,
0x74
,
0x78
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x0b
,
0x32
,
0x0e
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x
45
,
0x74
,
0x68
,
0x54
,
0x78
,
0x52
,
0x02
,
0x74
,
0x78
,
0x22
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x
53
,
0x74
,
0x64
,
0x54
,
0x78
,
0x52
,
0x02
,
0x74
,
0x78
,
0x22
,
0x89
,
0x01
,
0x0a
,
0x0e
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x45
,
0x74
,
0x68
,
0x12
,
0x2b
,
0x0a
,
0x08
,
0x74
,
0x78
,
0x5f
,
0x70
,
0x72
,
0x6f
,
0x6f
,
0x66
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x0b
,
0x32
,
0x10
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x54
,
...
...
@@ -1002,7 +1002,7 @@ var file_base_v1_resource_proto_rawDesc = []byte{
0x5f
,
0x6e
,
0x75
,
0x6d
,
0x18
,
0x02
,
0x20
,
0x01
,
0x28
,
0x03
,
0x52
,
0x0f
,
0x74
,
0x69
,
0x6d
,
0x65
,
0x6f
,
0x75
,
0x74
,
0x42
,
0x6c
,
0x6f
,
0x63
,
0x6b
,
0x4e
,
0x75
,
0x6d
,
0x12
,
0x1e
,
0x0a
,
0x02
,
0x74
,
0x78
,
0x18
,
0x03
,
0x20
,
0x01
,
0x28
,
0x0b
,
0x32
,
0x0e
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x
53
,
0x74
,
0x64
,
0x54
,
0x78
,
0x52
,
0x02
,
0x74
,
0x78
,
0x22
,
0x7b
,
0x0a
,
0x10
,
0x54
,
0x31
,
0x2e
,
0x
45
,
0x74
,
0x68
,
0x54
,
0x78
,
0x52
,
0x02
,
0x74
,
0x78
,
0x22
,
0x7b
,
0x0a
,
0x10
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x42
,
0x79
,
0x74
,
0x65
,
0x73
,
0x12
,
0x2b
,
0x0a
,
0x08
,
0x74
,
0x78
,
0x5f
,
0x70
,
0x72
,
0x6f
,
0x6f
,
0x66
,
0x18
,
0x01
,
0x20
,
0x01
,
0x28
,
0x0b
,
0x32
,
0x10
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x54
,
0x78
,
0x50
,
0x72
,
...
...
@@ -1066,9 +1066,9 @@ var file_base_v1_resource_proto_depIdxs = []int32{
8
,
// 8: base.v1.Transaction.tx_proof:type_name -> base.v1.TxProof
14
,
// 9: base.v1.Transaction.tx:type_name -> google.protobuf.Any
8
,
// 10: base.v1.TransactionStd.tx_proof:type_name -> base.v1.TxProof
4
,
// 11: base.v1.TransactionStd.tx:type_name -> base.v1.Eth
Tx
7
,
// 11: base.v1.TransactionStd.tx:type_name -> base.v1.Std
Tx
8
,
// 12: base.v1.TransactionEth.tx_proof:type_name -> base.v1.TxProof
7
,
// 13: base.v1.TransactionEth.tx:type_name -> base.v1.Std
Tx
4
,
// 13: base.v1.TransactionEth.tx:type_name -> base.v1.Eth
Tx
8
,
// 14: base.v1.TransactionBytes.tx_proof:type_name -> base.v1.TxProof
15
,
// [15:15] is the sub-list for method output_type
15
,
// [15:15] is the sub-list for method input_type
...
...
gen/proto/go/ring/v1/service.pb.go
View file @
19de5d65
...
...
@@ -33,42 +33,50 @@ var file_ring_v1_service_proto_rawDesc = []byte{
0x69
,
0x6e
,
0x67
,
0x2f
,
0x76
,
0x31
,
0x2f
,
0x61
,
0x63
,
0x63
,
0x6f
,
0x75
,
0x6e
,
0x74
,
0x5f
,
0x72
,
0x65
,
0x71
,
0x5f
,
0x72
,
0x65
,
0x73
,
0x2e
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x1a
,
0x16
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2f
,
0x76
,
0x31
,
0x2f
,
0x72
,
0x65
,
0x73
,
0x6f
,
0x75
,
0x72
,
0x63
,
0x65
,
0x2e
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x32
,
0x
94
,
0x01
,
0x0a
,
0x0b
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x53
,
0x65
,
0x72
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x32
,
0x
e0
,
0x01
,
0x0a
,
0x0b
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x53
,
0x65
,
0x72
,
0x76
,
0x69
,
0x63
,
0x65
,
0x12
,
0x4b
,
0x0a
,
0x12
,
0x53
,
0x65
,
0x6e
,
0x64
,
0x52
,
0x61
,
0x77
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x12
,
0x0e
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x45
,
0x74
,
0x68
,
0x54
,
0x78
,
0x1a
,
0x23
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x53
,
0x65
,
0x6e
,
0x64
,
0x52
,
0x61
,
0x77
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x6e
,
0x73
,
0x65
,
0x22
,
0x00
,
0x12
,
0x38
,
0x0a
,
0x05
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x12
,
0x15
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x52
,
0x65
,
0x71
,
0x75
,
0x65
,
0x73
,
0x74
,
0x1a
,
0x16
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x6e
,
0x73
,
0x65
,
0x22
,
0x00
,
0x42
,
0xa7
,
0x01
,
0x0a
,
0x0b
,
0x63
,
0x6f
,
0x6d
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x42
,
0x0c
,
0x53
,
0x65
,
0x72
,
0x76
,
0x69
,
0x63
,
0x65
,
0x50
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x50
,
0x01
,
0x5a
,
0x4d
,
0x67
,
0x69
,
0x74
,
0x68
,
0x75
,
0x62
,
0x2e
,
0x63
,
0x6f
,
0x6d
,
0x2f
,
0x43
,
0x61
,
0x64
,
0x75
,
0x63
,
0x65
,
0x75
,
0x73
,
0x4d
,
0x65
,
0x74
,
0x61
,
0x76
,
0x65
,
0x72
,
0x73
,
0x65
,
0x50
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x63
,
0x6f
,
0x6c
,
0x2f
,
0x6d
,
0x65
,
0x74
,
0x61
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x63
,
0x6f
,
0x6c
,
0x2f
,
0x67
,
0x65
,
0x6e
,
0x2f
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x2f
,
0x67
,
0x6f
,
0x2f
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2f
,
0x76
,
0x31
,
0x3b
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x76
,
0x31
,
0xa2
,
0x02
,
0x03
,
0x52
,
0x58
,
0x58
,
0xaa
,
0x02
,
0x07
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x56
,
0x31
,
0xca
,
0x02
,
0x07
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x5c
,
0x56
,
0x31
,
0xe2
,
0x02
,
0x13
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x5c
,
0x56
,
0x31
,
0x5c
,
0x47
,
0x50
,
0x42
,
0x4d
,
0x65
,
0x74
,
0x61
,
0x64
,
0x61
,
0x74
,
0x61
,
0xea
,
0x02
,
0x08
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x3a
,
0x3a
,
0x56
,
0x31
,
0x62
,
0x06
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x33
,
0x00
,
0x12
,
0x4a
,
0x0a
,
0x0b
,
0x53
,
0x65
,
0x6e
,
0x64
,
0x54
,
0x78
,
0x41
,
0x73
,
0x41
,
0x6e
,
0x79
,
0x12
,
0x14
,
0x2e
,
0x62
,
0x61
,
0x73
,
0x65
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x1a
,
0x23
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x53
,
0x65
,
0x6e
,
0x64
,
0x52
,
0x61
,
0x77
,
0x54
,
0x72
,
0x61
,
0x6e
,
0x73
,
0x61
,
0x63
,
0x74
,
0x69
,
0x6f
,
0x6e
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x6e
,
0x73
,
0x65
,
0x22
,
0x00
,
0x12
,
0x38
,
0x0a
,
0x05
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x12
,
0x15
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x52
,
0x65
,
0x71
,
0x75
,
0x65
,
0x73
,
0x74
,
0x1a
,
0x16
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x2e
,
0x4e
,
0x6f
,
0x6e
,
0x63
,
0x65
,
0x52
,
0x65
,
0x73
,
0x70
,
0x6f
,
0x6e
,
0x73
,
0x65
,
0x22
,
0x00
,
0x42
,
0xa7
,
0x01
,
0x0a
,
0x0b
,
0x63
,
0x6f
,
0x6d
,
0x2e
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x76
,
0x31
,
0x42
,
0x0c
,
0x53
,
0x65
,
0x72
,
0x76
,
0x69
,
0x63
,
0x65
,
0x50
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x50
,
0x01
,
0x5a
,
0x4d
,
0x67
,
0x69
,
0x74
,
0x68
,
0x75
,
0x62
,
0x2e
,
0x63
,
0x6f
,
0x6d
,
0x2f
,
0x43
,
0x61
,
0x64
,
0x75
,
0x63
,
0x65
,
0x75
,
0x73
,
0x4d
,
0x65
,
0x74
,
0x61
,
0x76
,
0x65
,
0x72
,
0x73
,
0x65
,
0x50
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x63
,
0x6f
,
0x6c
,
0x2f
,
0x6d
,
0x65
,
0x74
,
0x61
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x63
,
0x6f
,
0x6c
,
0x2f
,
0x67
,
0x65
,
0x6e
,
0x2f
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x2f
,
0x67
,
0x6f
,
0x2f
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x2f
,
0x76
,
0x31
,
0x3b
,
0x72
,
0x69
,
0x6e
,
0x67
,
0x76
,
0x31
,
0xa2
,
0x02
,
0x03
,
0x52
,
0x58
,
0x58
,
0xaa
,
0x02
,
0x07
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x2e
,
0x56
,
0x31
,
0xca
,
0x02
,
0x07
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x5c
,
0x56
,
0x31
,
0xe2
,
0x02
,
0x13
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x5c
,
0x56
,
0x31
,
0x5c
,
0x47
,
0x50
,
0x42
,
0x4d
,
0x65
,
0x74
,
0x61
,
0x64
,
0x61
,
0x74
,
0x61
,
0xea
,
0x02
,
0x08
,
0x52
,
0x69
,
0x6e
,
0x67
,
0x3a
,
0x3a
,
0x56
,
0x31
,
0x62
,
0x06
,
0x70
,
0x72
,
0x6f
,
0x74
,
0x6f
,
0x33
,
}
var
file_ring_v1_service_proto_goTypes
=
[]
interface
{}{
(
*
v1
.
EthTx
)(
nil
),
// 0: base.v1.EthTx
(
*
NonceRequest
)(
nil
),
// 1: ring.v1.NonceRequest
(
*
SendRawTransactionResponse
)(
nil
),
// 2: ring.v1.SendRawTransactionResponse
(
*
NonceResponse
)(
nil
),
// 3: ring.v1.NonceResponse
(
*
v1
.
Transaction
)(
nil
),
// 1: base.v1.Transaction
(
*
NonceRequest
)(
nil
),
// 2: ring.v1.NonceRequest
(
*
SendRawTransactionResponse
)(
nil
),
// 3: ring.v1.SendRawTransactionResponse
(
*
NonceResponse
)(
nil
),
// 4: ring.v1.NonceResponse
}
var
file_ring_v1_service_proto_depIdxs
=
[]
int32
{
0
,
// 0: ring.v1.RingService.SendRawTransaction:input_type -> base.v1.EthTx
1
,
// 1: ring.v1.RingService.Nonce:input_type -> ring.v1.NonceRequest
2
,
// 2: ring.v1.RingService.SendRawTransaction:output_type -> ring.v1.SendRawTransactionResponse
3
,
// 3: ring.v1.RingService.Nonce:output_type -> ring.v1.NonceResponse
2
,
// [2:4] is the sub-list for method output_type
0
,
// [0:2] is the sub-list for method input_type
1
,
// 1: ring.v1.RingService.SendTxAsAny:input_type -> base.v1.Transaction
2
,
// 2: ring.v1.RingService.Nonce:input_type -> ring.v1.NonceRequest
3
,
// 3: ring.v1.RingService.SendRawTransaction:output_type -> ring.v1.SendRawTransactionResponse
3
,
// 4: ring.v1.RingService.SendTxAsAny:output_type -> ring.v1.SendRawTransactionResponse
4
,
// 5: ring.v1.RingService.Nonce:output_type -> ring.v1.NonceResponse
3
,
// [3:6] is the sub-list for method output_type
0
,
// [0:3] is the sub-list for method input_type
0
,
// [0:0] is the sub-list for extension type_name
0
,
// [0:0] is the sub-list for extension extendee
0
,
// [0:0] is the sub-list for field type_name
...
...
gen/proto/go/ring/v1/service_grpc.pb.go
View file @
19de5d65
...
...
@@ -25,6 +25,8 @@ const _ = grpc.SupportPackageIsVersion7
type
RingServiceClient
interface
{
// account info service
SendRawTransaction
(
ctx
context
.
Context
,
in
*
v1
.
EthTx
,
opts
...
grpc
.
CallOption
)
(
*
SendRawTransactionResponse
,
error
)
SendTxAsAny
(
ctx
context
.
Context
,
in
*
v1
.
Transaction
,
opts
...
grpc
.
CallOption
)
(
*
SendRawTransactionResponse
,
error
)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce
(
ctx
context
.
Context
,
in
*
NonceRequest
,
opts
...
grpc
.
CallOption
)
(
*
NonceResponse
,
error
)
}
...
...
@@ -45,6 +47,15 @@ func (c *ringServiceClient) SendRawTransaction(ctx context.Context, in *v1.EthTx
return
out
,
nil
}
func
(
c
*
ringServiceClient
)
SendTxAsAny
(
ctx
context
.
Context
,
in
*
v1
.
Transaction
,
opts
...
grpc
.
CallOption
)
(
*
SendRawTransactionResponse
,
error
)
{
out
:=
new
(
SendRawTransactionResponse
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
"/ring.v1.RingService/SendTxAsAny"
,
in
,
out
,
opts
...
)
if
err
!=
nil
{
return
nil
,
err
}
return
out
,
nil
}
func
(
c
*
ringServiceClient
)
Nonce
(
ctx
context
.
Context
,
in
*
NonceRequest
,
opts
...
grpc
.
CallOption
)
(
*
NonceResponse
,
error
)
{
out
:=
new
(
NonceResponse
)
err
:=
c
.
cc
.
Invoke
(
ctx
,
"/ring.v1.RingService/Nonce"
,
in
,
out
,
opts
...
)
...
...
@@ -60,6 +71,8 @@ func (c *ringServiceClient) Nonce(ctx context.Context, in *NonceRequest, opts ..
type
RingServiceServer
interface
{
// account info service
SendRawTransaction
(
context
.
Context
,
*
v1
.
EthTx
)
(
*
SendRawTransactionResponse
,
error
)
SendTxAsAny
(
context
.
Context
,
*
v1
.
Transaction
)
(
*
SendRawTransactionResponse
,
error
)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce
(
context
.
Context
,
*
NonceRequest
)
(
*
NonceResponse
,
error
)
mustEmbedUnimplementedRingServiceServer
()
}
...
...
@@ -71,6 +84,9 @@ type UnimplementedRingServiceServer struct {
func
(
UnimplementedRingServiceServer
)
SendRawTransaction
(
context
.
Context
,
*
v1
.
EthTx
)
(
*
SendRawTransactionResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method SendRawTransaction not implemented"
)
}
func
(
UnimplementedRingServiceServer
)
SendTxAsAny
(
context
.
Context
,
*
v1
.
Transaction
)
(
*
SendRawTransactionResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method SendTxAsAny not implemented"
)
}
func
(
UnimplementedRingServiceServer
)
Nonce
(
context
.
Context
,
*
NonceRequest
)
(
*
NonceResponse
,
error
)
{
return
nil
,
status
.
Errorf
(
codes
.
Unimplemented
,
"method Nonce not implemented"
)
}
...
...
@@ -105,6 +121,24 @@ func _RingService_SendRawTransaction_Handler(srv interface{}, ctx context.Contex
return
interceptor
(
ctx
,
in
,
info
,
handler
)
}
func
_RingService_SendTxAsAny_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
v1
.
Transaction
)
if
err
:=
dec
(
in
);
err
!=
nil
{
return
nil
,
err
}
if
interceptor
==
nil
{
return
srv
.
(
RingServiceServer
)
.
SendTxAsAny
(
ctx
,
in
)
}
info
:=
&
grpc
.
UnaryServerInfo
{
Server
:
srv
,
FullMethod
:
"/ring.v1.RingService/SendTxAsAny"
,
}
handler
:=
func
(
ctx
context
.
Context
,
req
interface
{})
(
interface
{},
error
)
{
return
srv
.
(
RingServiceServer
)
.
SendTxAsAny
(
ctx
,
req
.
(
*
v1
.
Transaction
))
}
return
interceptor
(
ctx
,
in
,
info
,
handler
)
}
func
_RingService_Nonce_Handler
(
srv
interface
{},
ctx
context
.
Context
,
dec
func
(
interface
{})
error
,
interceptor
grpc
.
UnaryServerInterceptor
)
(
interface
{},
error
)
{
in
:=
new
(
NonceRequest
)
if
err
:=
dec
(
in
);
err
!=
nil
{
...
...
@@ -134,6 +168,10 @@ var RingService_ServiceDesc = grpc.ServiceDesc{
MethodName
:
"SendRawTransaction"
,
Handler
:
_RingService_SendRawTransaction_Handler
,
},
{
MethodName
:
"SendTxAsAny"
,
Handler
:
_RingService_SendTxAsAny_Handler
,
},
{
MethodName
:
"Nonce"
,
Handler
:
_RingService_Nonce_Handler
,
...
...
grcp-tx_test.go
View file @
19de5d65
...
...
@@ -3,6 +3,7 @@ package main_test
import
(
"context"
"crypto/ecdsa"
"fmt"
//"encoding/hex"
"math/big"
...
...
@@ -10,10 +11,10 @@ import (
"testing"
"time"
"sync"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/anypb"
base
"github.com/CaduceusMetaverseProtocol/metaprotocol/gen/proto/go/base/v1"
ring
"github.com/CaduceusMetaverseProtocol/metaprotocol/gen/proto/go/ring/v1"
...
...
@@ -34,41 +35,135 @@ type RingServer struct {
func
(
*
RingServer
)
SendRawTransaction
(
ctx
context
.
Context
,
req
*
base
.
EthTx
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
// txHashAsBytes, err := hex.DecodeString("0xba8e1c42813d24f48b4c785fb893dcf9d9635c660701af1a7f84734f320e8dea")
return
&
ring
.
SendRawTransactionResponse
{},
nil
}
// if err != nil {
// return nil, err
// }
func
(
*
RingServer
)
SendTxAsAny
(
ctx
context
.
Context
,
req
*
base
.
Transaction
)
(
*
ring
.
SendRawTransactionResponse
,
error
)
{
// _ = txHashAsBytes
return
&
ring
.
SendRawTransactionResponse
{},
nil
}
var
once
sync
.
Once
func
TestGrpcServer
(
t
*
testing
.
T
)
{
func
BenchmarkEthTx
(
b
*
testing
.
B
)
{
//onceFunc := func() {
lis
,
err
:=
net
.
Listen
(
"tcp"
,
":9006"
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
s
:=
grpc
.
NewServer
()
ring
.
RegisterRingServiceServer
(
s
,
&
RingServer
{})
//go func() {
err
=
s
.
Serve
(
lis
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
//}()
//}
//once.Do(onceFunc)
}
func
pricedTransaction
(
to
common
.
Address
,
nonce
uint64
,
gaslimit
uint64
,
gasprice
*
big
.
Int
,
key
*
ecdsa
.
PrivateKey
)
*
types
.
Transaction
{
tx
,
_
:=
types
.
SignTx
(
types
.
NewTransaction
(
nonce
,
to
,
big
.
NewInt
(
100
),
gaslimit
,
gasprice
,
nil
),
types
.
HomesteadSigner
{},
key
)
return
tx
}
// go test -v -run EthTx -bench=. -benchtime=3s
// go test -v -run TestGrpcServer -timeout 0
//BenchmarkAny
// go test -v -run Any -bench=. -benchtime=3s
func
BenchmarkAny
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
onceFunc
:=
func
(
)
{
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
lis
,
err
:=
net
.
Listen
(
"tcp"
,
":9006"
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
for
pb
.
Next
()
{
s
:=
grpc
.
NewServer
()
conn
,
err
:=
grpc
.
Dial
(
"127.0.0.1:9006"
,
grpc
.
WithTransportCredentials
(
insecure
.
NewCredentials
()))
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
defer
conn
.
Close
()
c
:=
ring
.
NewRingServiceClient
(
conn
)
ctx
,
cancel
:=
context
.
WithTimeout
(
context
.
Background
(),
time
.
Second
)
defer
cancel
()
ring
.
RegisterRingServiceServer
(
s
,
&
RingServer
{})
local
,
_
:=
crypto
.
HexToECDSA
(
"FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A"
)
//publicKey := local.Public()
//publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
//fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA)
//b.Log(fromAddress)
remote
,
_
:=
crypto
.
GenerateKey
()
tx
:=
pricedTransaction
(
crypto
.
PubkeyToAddress
(
remote
.
PublicKey
),
0
,
100000
,
big
.
NewInt
(
1
),
local
)
inner
:=
base
.
EthTxData
{
AccountNonce
:
tx
.
Nonce
(),
Price
:
tx
.
GasPrice
()
.
Bytes
(),
GasLimit
:
tx
.
Gas
(),
Payload
:
tx
.
Data
(),
}
v
,
r
,
sigs
:=
tx
.
RawSignatureValues
()
inner
.
V
=
v
.
Bytes
()
inner
.
R
=
r
.
Bytes
()
inner
.
S
=
sigs
.
Bytes
()
inner
.
Amount
=
tx
.
Value
()
.
Bytes
()
addr
:=
base
.
Address
{
Address
:
tx
.
To
()
.
Bytes
()}
inner
.
Recipient
=
&
addr
// Each goroutine has its own bytes.Buffer.
// The loop body is executed b.N times total across all goroutines.
ethTx
:=
base
.
EthTx
{
Inner
:
&
inner
}
ethTxAsAny
,
err
:=
pbany
(
ethTx
)
c
.
SendTxAsAny
(
ctx
,
&
base
.
Transaction
{
Tx
:
ethTxAsAny
})
res
,
err
:=
c
.
SendRawTransaction
(
ctx
,
&
base
.
EthTx
{
Inner
:
&
inner
})
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
go
func
()
{
err
=
s
.
Serve
(
lis
)
if
err
!=
nil
{
b
.
Fatal
(
err
)
}
}()
_
=
res
//b.Logf("Greeting: %v\n", res)
}
})
}
func
pbany
(
v
interface
{})
(
*
anypb
.
Any
,
error
)
{
pv
,
ok
:=
v
.
(
proto
.
Message
)
if
!
ok
{
return
&
anypb
.
Any
{},
fmt
.
Errorf
(
"%v is not proto.Message"
,
pv
)
}
return
anypb
.
New
(
pv
)
}
once
.
Do
(
onceFunc
)
func
BenchmarkEthTx
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
RunParallel
(
func
(
pb
*
testing
.
PB
)
{
...
...
@@ -131,10 +226,3 @@ func BenchmarkEthTx(b *testing.B) {
}
})
}
func
pricedTransaction
(
to
common
.
Address
,
nonce
uint64
,
gaslimit
uint64
,
gasprice
*
big
.
Int
,
key
*
ecdsa
.
PrivateKey
)
*
types
.
Transaction
{
tx
,
_
:=
types
.
SignTx
(
types
.
NewTransaction
(
nonce
,
to
,
big
.
NewInt
(
100
),
gaslimit
,
gasprice
,
nil
),
types
.
HomesteadSigner
{},
key
)
return
tx
}
// go test -bench=.
ringapi/ring/v1/service.proto
View file @
19de5d65
...
...
@@ -11,6 +11,10 @@ service RingService{
// account info service
rpc
SendRawTransaction
(
base.v1.EthTx
)
returns
(
SendRawTransactionResponse
)
{};
rpc
SendTxAsAny
(
base.v1.Transaction
)
returns
(
SendRawTransactionResponse
)
{};
//rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
rpc
Nonce
(
NonceRequest
)
returns
(
NonceResponse
)
{};
}
\ No newline at end of file
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