Commit f2a034dd authored by Ubuntu's avatar Ubuntu

generate tx in init func

parent ccb54d9b
...@@ -91,23 +91,29 @@ message Transaction{ ...@@ -91,23 +91,29 @@ message Transaction{
//2. eth std: proto3 eth tx --> grpc --->proto3 eth tx //2. eth std: proto3 eth tx --> grpc --->proto3 eth tx
// proto3 std tx --> grpc --->proto3 std tx // proto3 std tx --> grpc --->proto3 std tx
message TransactionStd{
message TransactionEth{
TxProof tx_proof=1; TxProof tx_proof=1;
int64 timeout_block_num =2; int64 timeout_block_num =2;
StdTx tx =3; EthTx tx =3;
} }
message TransactionEth{
message TransactionStd{
TxProof tx_proof=1; TxProof tx_proof=1;
int64 timeout_block_num =2; int64 timeout_block_num =2;
EthTx tx =3; StdTx tx =3;
} }
//3. bytes //3. bytes
message TransactionBytes{ message TransactionBytes{
TxProof tx_proof=1; TxProof tx_proof=1;
int64 timeout_block_num =2; int64 timeout_block_num =2;
bytes tx =3; // EthTx StdTx bytes tx =3; // EthTx StdTx // proto3 定义的交易,没有对应的函数转bytes。
bytes from =4;
} }
......
This diff is collapsed.
...@@ -33,58 +33,66 @@ var file_ring_v1_service_proto_rawDesc = []byte{ ...@@ -33,58 +33,66 @@ var file_ring_v1_service_proto_rawDesc = []byte{
0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x72, 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, 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, 0x73, 0x65, 0x2f, 0x76, 0x31, 0x2f, 0x72, 0x65, 0x73, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x2e, 0x70,
0x72, 0x6f, 0x74, 0x6f, 0x32, 0xb3, 0x02, 0x0a, 0x0b, 0x52, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72, 0x72, 0x6f, 0x74, 0x6f, 0x32, 0x84, 0x03, 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, 0x76, 0x69, 0x63, 0x65, 0x12, 0x4d, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x78, 0x41, 0x73,
0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x2e, 0x62, 0x61, 0x73, 0x45, 0x74, 0x68, 0x12, 0x17, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72,
0x65, 0x2e, 0x76, 0x31, 0x2e, 0x45, 0x74, 0x68, 0x54, 0x78, 0x1a, 0x23, 0x2e, 0x72, 0x69, 0x6e, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x45, 0x74, 0x68, 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, 0x4d, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x78, 0x41, 0x73, 0x53,
0x74, 0x64, 0x12, 0x17, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61,
0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x74, 0x64, 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, 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, 0x51,
0x0a, 0x0d, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x78, 0x41, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12,
0x19, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61,
0x63, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0x79, 0x74, 0x65, 0x73, 0x1a, 0x23, 0x2e, 0x72, 0x69, 0x6e,
0x67, 0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x61, 0x77, 0x54, 0x72, 0x61, 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, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22,
0x00, 0x12, 0x4a, 0x0a, 0x0b, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x78, 0x41, 0x73, 0x41, 0x6e, 0x79, 0x00, 0x12, 0x38, 0x0a, 0x05, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x69, 0x6e,
0x12, 0x14, 0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73,
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x1a, 0x23, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x74, 0x1a, 0x16, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x6e, 0x63,
0x2e, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x61, 0x77, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0xa7, 0x01, 0x0a, 0x0b,
0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x51, 0x0a, 0x63, 0x6f, 0x6d, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x53, 0x65, 0x72,
0x0d, 0x53, 0x65, 0x6e, 0x64, 0x54, 0x78, 0x41, 0x73, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x19, 0x76, 0x69, 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x4d, 0x67, 0x69, 0x74,
0x2e, 0x62, 0x61, 0x73, 0x65, 0x2e, 0x76, 0x31, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x43, 0x61, 0x64, 0x75, 0x63, 0x65, 0x75, 0x73,
0x74, 0x69, 0x6f, 0x6e, 0x42, 0x79, 0x74, 0x65, 0x73, 0x1a, 0x23, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x4d, 0x65, 0x74, 0x61, 0x76, 0x65, 0x72, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f,
0x2e, 0x76, 0x31, 0x2e, 0x53, 0x65, 0x6e, 0x64, 0x52, 0x61, 0x77, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x6c, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2f, 0x67,
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x65, 0x6e, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x6f, 0x2f, 0x72, 0x69, 0x6e, 0x67,
0x12, 0x38, 0x0a, 0x05, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x12, 0x15, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2f, 0x76, 0x31, 0x3b, 0x72, 0x69, 0x6e, 0x67, 0x76, 0x31, 0xa2, 0x02, 0x03, 0x52, 0x58, 0x58,
0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0xaa, 0x02, 0x07, 0x52, 0x69, 0x6e, 0x67, 0x2e, 0x56, 0x31, 0xca, 0x02, 0x07, 0x52, 0x69, 0x6e,
0x1a, 0x16, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x2e, 0x4e, 0x6f, 0x6e, 0x63, 0x65, 0x67, 0x5c, 0x56, 0x31, 0xe2, 0x02, 0x13, 0x52, 0x69, 0x6e, 0x67, 0x5c, 0x56, 0x31, 0x5c, 0x47,
0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0xa7, 0x01, 0x0a, 0x0b, 0x63, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x52, 0x69, 0x6e,
0x6f, 0x6d, 0x2e, 0x72, 0x69, 0x6e, 0x67, 0x2e, 0x76, 0x31, 0x42, 0x0c, 0x53, 0x65, 0x72, 0x76, 0x67, 0x3a, 0x3a, 0x56, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
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{}{ var file_ring_v1_service_proto_goTypes = []interface{}{
(*v1.EthTx)(nil), // 0: base.v1.EthTx (*v1.TransactionEth)(nil), // 0: base.v1.TransactionEth
(*v1.Transaction)(nil), // 1: base.v1.Transaction (*v1.TransactionStd)(nil), // 1: base.v1.TransactionStd
(*v1.TransactionBytes)(nil), // 2: base.v1.TransactionBytes (*v1.Transaction)(nil), // 2: base.v1.Transaction
(*NonceRequest)(nil), // 3: ring.v1.NonceRequest (*v1.TransactionBytes)(nil), // 3: base.v1.TransactionBytes
(*SendRawTransactionResponse)(nil), // 4: ring.v1.SendRawTransactionResponse (*NonceRequest)(nil), // 4: ring.v1.NonceRequest
(*NonceResponse)(nil), // 5: ring.v1.NonceResponse (*SendRawTransactionResponse)(nil), // 5: ring.v1.SendRawTransactionResponse
(*NonceResponse)(nil), // 6: ring.v1.NonceResponse
} }
var file_ring_v1_service_proto_depIdxs = []int32{ var file_ring_v1_service_proto_depIdxs = []int32{
0, // 0: ring.v1.RingService.SendRawTransaction:input_type -> base.v1.EthTx 0, // 0: ring.v1.RingService.SendTxAsEth:input_type -> base.v1.TransactionEth
1, // 1: ring.v1.RingService.SendTxAsAny:input_type -> base.v1.Transaction 1, // 1: ring.v1.RingService.SendTxAsStd:input_type -> base.v1.TransactionStd
2, // 2: ring.v1.RingService.SendTxAsBytes:input_type -> base.v1.TransactionBytes 2, // 2: ring.v1.RingService.SendTxAsAny:input_type -> base.v1.Transaction
3, // 3: ring.v1.RingService.Nonce:input_type -> ring.v1.NonceRequest 3, // 3: ring.v1.RingService.SendTxAsBytes:input_type -> base.v1.TransactionBytes
4, // 4: ring.v1.RingService.SendRawTransaction:output_type -> ring.v1.SendRawTransactionResponse 4, // 4: ring.v1.RingService.Nonce:input_type -> ring.v1.NonceRequest
4, // 5: ring.v1.RingService.SendTxAsAny:output_type -> ring.v1.SendRawTransactionResponse 5, // 5: ring.v1.RingService.SendTxAsEth:output_type -> ring.v1.SendRawTransactionResponse
4, // 6: ring.v1.RingService.SendTxAsBytes:output_type -> ring.v1.SendRawTransactionResponse 5, // 6: ring.v1.RingService.SendTxAsStd:output_type -> ring.v1.SendRawTransactionResponse
5, // 7: ring.v1.RingService.Nonce:output_type -> ring.v1.NonceResponse 5, // 7: ring.v1.RingService.SendTxAsAny:output_type -> ring.v1.SendRawTransactionResponse
4, // [4:8] is the sub-list for method output_type 5, // 8: ring.v1.RingService.SendTxAsBytes:output_type -> ring.v1.SendRawTransactionResponse
0, // [0:4] is the sub-list for method input_type 6, // 9: ring.v1.RingService.Nonce:output_type -> ring.v1.NonceResponse
5, // [5:10] is the sub-list for method output_type
0, // [0:5] 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 type_name
0, // [0:0] is the sub-list for extension extendee 0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name 0, // [0:0] is the sub-list for field type_name
......
...@@ -24,7 +24,8 @@ const _ = grpc.SupportPackageIsVersion7 ...@@ -24,7 +24,8 @@ const _ = grpc.SupportPackageIsVersion7
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type RingServiceClient interface { type RingServiceClient interface {
// account info service // account info service
SendRawTransaction(ctx context.Context, in *v1.EthTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) SendTxAsEth(ctx context.Context, in *v1.TransactionEth, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsStd(ctx context.Context, in *v1.TransactionStd, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsAny(ctx context.Context, in *v1.Transaction, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) SendTxAsAny(ctx context.Context, in *v1.Transaction, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
SendTxAsBytes(ctx context.Context, in *v1.TransactionBytes, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) SendTxAsBytes(ctx context.Context, in *v1.TransactionBytes, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {}; // rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
...@@ -39,9 +40,18 @@ func NewRingServiceClient(cc grpc.ClientConnInterface) RingServiceClient { ...@@ -39,9 +40,18 @@ func NewRingServiceClient(cc grpc.ClientConnInterface) RingServiceClient {
return &ringServiceClient{cc} return &ringServiceClient{cc}
} }
func (c *ringServiceClient) SendRawTransaction(ctx context.Context, in *v1.EthTx, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) { func (c *ringServiceClient) SendTxAsEth(ctx context.Context, in *v1.TransactionEth, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse) out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendRawTransaction", in, out, opts...) err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendTxAsEth", in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *ringServiceClient) SendTxAsStd(ctx context.Context, in *v1.TransactionStd, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendTxAsStd", in, out, opts...)
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -80,7 +90,8 @@ func (c *ringServiceClient) Nonce(ctx context.Context, in *NonceRequest, opts .. ...@@ -80,7 +90,8 @@ func (c *ringServiceClient) Nonce(ctx context.Context, in *NonceRequest, opts ..
// for forward compatibility // for forward compatibility
type RingServiceServer interface { type RingServiceServer interface {
// account info service // account info service
SendRawTransaction(context.Context, *v1.EthTx) (*SendRawTransactionResponse, error) SendTxAsEth(context.Context, *v1.TransactionEth) (*SendRawTransactionResponse, error)
SendTxAsStd(context.Context, *v1.TransactionStd) (*SendRawTransactionResponse, error)
SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error) SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error)
SendTxAsBytes(context.Context, *v1.TransactionBytes) (*SendRawTransactionResponse, error) SendTxAsBytes(context.Context, *v1.TransactionBytes) (*SendRawTransactionResponse, error)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {}; // rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
...@@ -92,8 +103,11 @@ type RingServiceServer interface { ...@@ -92,8 +103,11 @@ type RingServiceServer interface {
type UnimplementedRingServiceServer struct { type UnimplementedRingServiceServer struct {
} }
func (UnimplementedRingServiceServer) SendRawTransaction(context.Context, *v1.EthTx) (*SendRawTransactionResponse, error) { func (UnimplementedRingServiceServer) SendTxAsEth(context.Context, *v1.TransactionEth) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendRawTransaction not implemented") return nil, status.Errorf(codes.Unimplemented, "method SendTxAsEth not implemented")
}
func (UnimplementedRingServiceServer) SendTxAsStd(context.Context, *v1.TransactionStd) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsStd not implemented")
} }
func (UnimplementedRingServiceServer) SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error) { func (UnimplementedRingServiceServer) SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsAny not implemented") return nil, status.Errorf(codes.Unimplemented, "method SendTxAsAny not implemented")
...@@ -117,20 +131,38 @@ func RegisterRingServiceServer(s grpc.ServiceRegistrar, srv RingServiceServer) { ...@@ -117,20 +131,38 @@ func RegisterRingServiceServer(s grpc.ServiceRegistrar, srv RingServiceServer) {
s.RegisterService(&RingService_ServiceDesc, srv) s.RegisterService(&RingService_ServiceDesc, srv)
} }
func _RingService_SendRawTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _RingService_SendTxAsEth_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.EthTx) in := new(v1.TransactionEth)
if err := dec(in); err != nil { if err := dec(in); err != nil {
return nil, err return nil, err
} }
if interceptor == nil { if interceptor == nil {
return srv.(RingServiceServer).SendRawTransaction(ctx, in) return srv.(RingServiceServer).SendTxAsEth(ctx, in)
} }
info := &grpc.UnaryServerInfo{ info := &grpc.UnaryServerInfo{
Server: srv, Server: srv,
FullMethod: "/ring.v1.RingService/SendRawTransaction", FullMethod: "/ring.v1.RingService/SendTxAsEth",
} }
handler := func(ctx context.Context, req interface{}) (interface{}, error) { handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RingServiceServer).SendRawTransaction(ctx, req.(*v1.EthTx)) return srv.(RingServiceServer).SendTxAsEth(ctx, req.(*v1.TransactionEth))
}
return interceptor(ctx, in, info, handler)
}
func _RingService_SendTxAsStd_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.TransactionStd)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RingServiceServer).SendTxAsStd(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ring.v1.RingService/SendTxAsStd",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RingServiceServer).SendTxAsStd(ctx, req.(*v1.TransactionStd))
} }
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
...@@ -197,8 +229,12 @@ var RingService_ServiceDesc = grpc.ServiceDesc{ ...@@ -197,8 +229,12 @@ var RingService_ServiceDesc = grpc.ServiceDesc{
HandlerType: (*RingServiceServer)(nil), HandlerType: (*RingServiceServer)(nil),
Methods: []grpc.MethodDesc{ Methods: []grpc.MethodDesc{
{ {
MethodName: "SendRawTransaction", MethodName: "SendTxAsEth",
Handler: _RingService_SendRawTransaction_Handler, Handler: _RingService_SendTxAsEth_Handler,
},
{
MethodName: "SendTxAsStd",
Handler: _RingService_SendTxAsStd_Handler,
}, },
{ {
MethodName: "SendTxAsAny", MethodName: "SendTxAsAny",
......
...@@ -4,6 +4,7 @@ import ( ...@@ -4,6 +4,7 @@ import (
"context" "context"
"crypto/ecdsa" "crypto/ecdsa"
"fmt" "fmt"
"sync"
//"encoding/hex" //"encoding/hex"
"math/big" "math/big"
...@@ -33,7 +34,12 @@ type RingServer struct { ...@@ -33,7 +34,12 @@ type RingServer struct {
ring.UnimplementedRingServiceServer ring.UnimplementedRingServiceServer
} }
func (*RingServer) SendRawTransaction(ctx context.Context, req *base.EthTx) (*ring.SendRawTransactionResponse, error) { func (*RingServer) SendTxAsEth(ctx context.Context, req *base.TransactionEth) (*ring.SendRawTransactionResponse, error) {
return &ring.SendRawTransactionResponse{}, nil
}
func (*RingServer) SendTxAsStd(ctx context.Context, req *base.TransactionStd) (*ring.SendRawTransactionResponse, error) {
return &ring.SendRawTransactionResponse{}, nil return &ring.SendRawTransactionResponse{}, nil
} }
...@@ -50,8 +56,6 @@ func (*RingServer) SendTxAsBytes(ctx context.Context, req *base.TransactionBytes ...@@ -50,8 +56,6 @@ func (*RingServer) SendTxAsBytes(ctx context.Context, req *base.TransactionBytes
func TestGrpcServer(t *testing.T) { func TestGrpcServer(t *testing.T) {
//onceFunc := func() {
lis, err := net.Listen("tcp", ":9006") lis, err := net.Listen("tcp", ":9006")
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
...@@ -61,16 +65,10 @@ func TestGrpcServer(t *testing.T) { ...@@ -61,16 +65,10 @@ func TestGrpcServer(t *testing.T) {
ring.RegisterRingServiceServer(s, &RingServer{}) ring.RegisterRingServiceServer(s, &RingServer{})
//go func() {
err = s.Serve(lis) err = s.Serve(lis)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
//}()
//}
//once.Do(onceFunc)
} }
func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gasprice *big.Int, key *ecdsa.PrivateKey) *types.Transaction { func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gasprice *big.Int, key *ecdsa.PrivateKey) *types.Transaction {
...@@ -84,7 +82,30 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric ...@@ -84,7 +82,30 @@ func pricedTransaction(to common.Address, nonce uint64, gaslimit uint64, gaspric
//BenchmarkAny //BenchmarkAny
// go test -v -run Any -bench=. -benchtime=3s // go test -v -run Any -bench=. -benchtime=3s
func BenchmarkAny(b *testing.B) { var once sync.Once
var tx *types.Transaction
var fromAddr common.Address
// var local, remote *ecdsa.PrivateKey
func int() {
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A")
publicKey := local.Public()
publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey)
fromAddr = crypto.PubkeyToAddress(*publicKeyECDSA)
//b.Log(fromAddress)
remote, _ := crypto.GenerateKey()
tx = pricedTransaction(crypto.PubkeyToAddress(remote.PublicKey), 0, 100000, big.NewInt(1), local)
}
func BenchmarkEthTx(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
...@@ -102,17 +123,6 @@ func BenchmarkAny(b *testing.B) { ...@@ -102,17 +123,6 @@ func BenchmarkAny(b *testing.B) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
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{ inner := base.EthTxData{
AccountNonce: tx.Nonce(), AccountNonce: tx.Nonce(),
Price: tx.GasPrice().Bytes(), Price: tx.GasPrice().Bytes(),
...@@ -130,22 +140,9 @@ func BenchmarkAny(b *testing.B) { ...@@ -130,22 +140,9 @@ func BenchmarkAny(b *testing.B) {
addr := base.Address{Address: tx.To().Bytes()} addr := base.Address{Address: tx.To().Bytes()}
inner.Recipient = &addr inner.Recipient = &addr
inner.From = fromAddr.Bytes()
// Each goroutine has its own bytes.Buffer. res, err := c.SendTxAsEth(ctx, &base.TransactionEth{Tx: &base.EthTx{Inner: &inner}})
// 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)
}
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -153,21 +150,12 @@ func BenchmarkAny(b *testing.B) { ...@@ -153,21 +150,12 @@ func BenchmarkAny(b *testing.B) {
_ = res _ = res
//b.Logf("Greeting: %v\n", res)
} }
}) })
} }
func pbany(v interface{}) (*anypb.Any, error) { func BenchmarkStdTx(b *testing.B) {
pv, ok := v.(proto.Message)
if !ok {
return &anypb.Any{}, fmt.Errorf("%v is not proto.Message", pv)
}
return anypb.New(pv)
}
func BenchmarkEthTx(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
...@@ -185,18 +173,7 @@ func BenchmarkEthTx(b *testing.B) { ...@@ -185,18 +173,7 @@ func BenchmarkEthTx(b *testing.B) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A") inner := base.StdTxData{
//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(), AccountNonce: tx.Nonce(),
Price: tx.GasPrice().Bytes(), Price: tx.GasPrice().Bytes(),
GasLimit: tx.Gas(), GasLimit: tx.Gas(),
...@@ -213,12 +190,9 @@ func BenchmarkEthTx(b *testing.B) { ...@@ -213,12 +190,9 @@ func BenchmarkEthTx(b *testing.B) {
addr := base.Address{Address: tx.To().Bytes()} addr := base.Address{Address: tx.To().Bytes()}
inner.Recipient = &addr inner.Recipient = &addr
inner.From = fromAddr.Bytes()
// Each goroutine has its own bytes.Buffer. res, err := c.SendTxAsStd(ctx, &base.TransactionStd{Tx: &base.StdTx{Inner: &inner}})
// The loop body is executed b.N times total across all goroutines.
res, err := c.SendRawTransaction(ctx, &base.EthTx{Inner: &inner})
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -226,15 +200,16 @@ func BenchmarkEthTx(b *testing.B) { ...@@ -226,15 +200,16 @@ func BenchmarkEthTx(b *testing.B) {
_ = res _ = res
//b.Logf("Greeting: %v\n", res)
} }
}) })
} }
func BenchmarkBytes(b *testing.B) { func BenchmarkAnyTx(b *testing.B) {
b.ReportAllocs() b.ReportAllocs()
// The loop body is executed b.N times total across all goroutines.
b.RunParallel(func(pb *testing.PB) { b.RunParallel(func(pb *testing.PB) {
for pb.Next() { for pb.Next() {
...@@ -250,40 +225,66 @@ func BenchmarkBytes(b *testing.B) { ...@@ -250,40 +225,66 @@ func BenchmarkBytes(b *testing.B) {
ctx, cancel := context.WithTimeout(context.Background(), time.Second) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel() defer cancel()
local, _ := crypto.HexToECDSA("FD5CC6F5E7E2805E920AC5DC83D5AF1106F9C92F0C04F9D5E1FD4261B4B4464A") inner := base.EthTxData{
AccountNonce: tx.Nonce(),
Price: tx.GasPrice().Bytes(),
GasLimit: tx.Gas(),
Payload: tx.Data(),
}
v, r, sigs := tx.RawSignatureValues()
//publicKey := local.Public() inner.V = v.Bytes()
//publicKeyECDSA, _ := publicKey.(*ecdsa.PublicKey) inner.R = r.Bytes()
//fromAddress := crypto.PubkeyToAddress(*publicKeyECDSA) inner.S = sigs.Bytes()
//b.Log(fromAddress) inner.Amount = tx.Value().Bytes()
addr := base.Address{Address: tx.To().Bytes()}
inner.Recipient = &addr
ethTx := base.EthTx{Inner: &inner}
ethTxAsAny, err := pbany(ethTx)
res, err := c.SendTxAsAny(ctx, &base.Transaction{Tx: ethTxAsAny})
if err != nil {
b.Fatal(err)
}
remote, _ := crypto.GenerateKey() _ = res
tx := pricedTransaction(crypto.PubkeyToAddress(remote.PublicKey), 0, 100000, big.NewInt(1), local) }
})
}
// inner := base.EthTxData{ func pbany(v interface{}) (*anypb.Any, error) {
// AccountNonce: tx.Nonce(), pv, ok := v.(proto.Message)
// Price: tx.GasPrice().Bytes(), if !ok {
// GasLimit: tx.Gas(), return &anypb.Any{}, fmt.Errorf("%v is not proto.Message", pv)
// Payload: tx.Data(), }
// } return anypb.New(pv)
}
// v, r, sigs := tx.RawSignatureValues() func BenchmarkBytesEth(b *testing.B) {
// inner.V = v.Bytes() b.ReportAllocs()
// inner.R = r.Bytes()
// inner.S = sigs.Bytes()
// inner.Amount = tx.Value().Bytes()
// addr := base.Address{Address: tx.To().Bytes()} b.RunParallel(func(pb *testing.PB) {
// inner.Recipient = &addr for pb.Next() {
// Each goroutine has its own bytes.Buffer. conn, err := grpc.Dial("127.0.0.1:9006", grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
b.Fatal(err)
}
defer conn.Close()
// The loop body is executed b.N times total across all goroutines. c := ring.NewRingServiceClient(conn)
//res, err := c.SendRawTransaction(ctx, &base.EthTx{Inner: &inner}) ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()
txAsBytes, err := tx.MarshalBinary() txAsBytes, err := tx.MarshalBinary()
...@@ -291,7 +292,7 @@ func BenchmarkBytes(b *testing.B) { ...@@ -291,7 +292,7 @@ func BenchmarkBytes(b *testing.B) {
b.Fatal(err) b.Fatal(err)
} }
res, err := c.SendTxAsBytes(ctx, &base.TransactionBytes{Tx: txAsBytes}) res, err := c.SendTxAsBytes(ctx, &base.TransactionBytes{Tx: txAsBytes, From: fromAddr[:]})
if err != nil { if err != nil {
b.Fatal(err) b.Fatal(err)
...@@ -299,8 +300,6 @@ func BenchmarkBytes(b *testing.B) { ...@@ -299,8 +300,6 @@ func BenchmarkBytes(b *testing.B) {
_ = res _ = res
//b.Logf("Greeting: %v\n", res)
} }
}) })
} }
...@@ -35,7 +35,6 @@ type TxCheckServer struct { ...@@ -35,7 +35,6 @@ type TxCheckServer struct {
txchecker.UnimplementedTxCheckerServiceServer txchecker.UnimplementedTxCheckerServiceServer
} }
type RingServer struct { type RingServer struct {
metaring.UnimplementedRingServiceServer metaring.UnimplementedRingServiceServer
} }
......
...@@ -10,10 +10,11 @@ import "base/v1/resource.proto"; ...@@ -10,10 +10,11 @@ import "base/v1/resource.proto";
service RingService{ service RingService{
// account info service // account info service
rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {}; rpc SendTxAsEth(base.v1.TransactionEth) returns (SendRawTransactionResponse) {};
rpc SendTxAsAny(base.v1.Transaction) returns (SendRawTransactionResponse) {}; rpc SendTxAsStd(base.v1.TransactionStd) returns (SendRawTransactionResponse) {};
rpc SendTxAsAny(base.v1.Transaction) returns (SendRawTransactionResponse) {};
rpc SendTxAsBytes(base.v1.TransactionBytes) returns (SendRawTransactionResponse) {}; rpc SendTxAsBytes(base.v1.TransactionBytes) returns (SendRawTransactionResponse) {};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment