Commit ccb54d9b authored by Ubuntu's avatar Ubuntu

add tx as bytes for grpc

parent 19de5d65
......@@ -33,7 +33,7 @@ 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, 0xe0, 0x01, 0x0a, 0x0b, 0x52, 0x69, 0x6e, 0x67, 0x53, 0x65, 0x72,
0x72, 0x6f, 0x74, 0x6f, 0x32, 0xb3, 0x02, 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,
......@@ -43,40 +43,48 @@ var file_ring_v1_service_proto_rawDesc = []byte{
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,
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, 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
(*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
(*v1.TransactionBytes)(nil), // 2: base.v1.TransactionBytes
(*NonceRequest)(nil), // 3: ring.v1.NonceRequest
(*SendRawTransactionResponse)(nil), // 4: ring.v1.SendRawTransactionResponse
(*NonceResponse)(nil), // 5: 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.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
2, // 2: ring.v1.RingService.SendTxAsBytes:input_type -> base.v1.TransactionBytes
3, // 3: ring.v1.RingService.Nonce:input_type -> ring.v1.NonceRequest
4, // 4: ring.v1.RingService.SendRawTransaction:output_type -> ring.v1.SendRawTransactionResponse
4, // 5: ring.v1.RingService.SendTxAsAny:output_type -> ring.v1.SendRawTransactionResponse
4, // 6: ring.v1.RingService.SendTxAsBytes:output_type -> ring.v1.SendRawTransactionResponse
5, // 7: ring.v1.RingService.Nonce:output_type -> ring.v1.NonceResponse
4, // [4:8] is the sub-list for method output_type
0, // [0:4] 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
......
......@@ -26,6 +26,7 @@ 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)
SendTxAsBytes(ctx context.Context, in *v1.TransactionBytes, opts ...grpc.CallOption) (*SendRawTransactionResponse, error)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce(ctx context.Context, in *NonceRequest, opts ...grpc.CallOption) (*NonceResponse, error)
}
......@@ -56,6 +57,15 @@ func (c *ringServiceClient) SendTxAsAny(ctx context.Context, in *v1.Transaction,
return out, nil
}
func (c *ringServiceClient) SendTxAsBytes(ctx context.Context, in *v1.TransactionBytes, opts ...grpc.CallOption) (*SendRawTransactionResponse, error) {
out := new(SendRawTransactionResponse)
err := c.cc.Invoke(ctx, "/ring.v1.RingService/SendTxAsBytes", 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...)
......@@ -72,6 +82,7 @@ type RingServiceServer interface {
// account info service
SendRawTransaction(context.Context, *v1.EthTx) (*SendRawTransactionResponse, error)
SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error)
SendTxAsBytes(context.Context, *v1.TransactionBytes) (*SendRawTransactionResponse, error)
// rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
Nonce(context.Context, *NonceRequest) (*NonceResponse, error)
mustEmbedUnimplementedRingServiceServer()
......@@ -87,6 +98,9 @@ func (UnimplementedRingServiceServer) SendRawTransaction(context.Context, *v1.Et
func (UnimplementedRingServiceServer) SendTxAsAny(context.Context, *v1.Transaction) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsAny not implemented")
}
func (UnimplementedRingServiceServer) SendTxAsBytes(context.Context, *v1.TransactionBytes) (*SendRawTransactionResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method SendTxAsBytes not implemented")
}
func (UnimplementedRingServiceServer) Nonce(context.Context, *NonceRequest) (*NonceResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method Nonce not implemented")
}
......@@ -139,6 +153,24 @@ func _RingService_SendTxAsAny_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler)
}
func _RingService_SendTxAsBytes_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(v1.TransactionBytes)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(RingServiceServer).SendTxAsBytes(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: "/ring.v1.RingService/SendTxAsBytes",
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(RingServiceServer).SendTxAsBytes(ctx, req.(*v1.TransactionBytes))
}
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 {
......@@ -172,6 +204,10 @@ var RingService_ServiceDesc = grpc.ServiceDesc{
MethodName: "SendTxAsAny",
Handler: _RingService_SendTxAsAny_Handler,
},
{
MethodName: "SendTxAsBytes",
Handler: _RingService_SendTxAsBytes_Handler,
},
{
MethodName: "Nonce",
Handler: _RingService_Nonce_Handler,
......
......@@ -43,6 +43,11 @@ func (*RingServer) SendTxAsAny(ctx context.Context, req *base.Transaction) (*rin
return &ring.SendRawTransactionResponse{}, nil
}
func (*RingServer) SendTxAsBytes(ctx context.Context, req *base.TransactionBytes) (*ring.SendRawTransactionResponse, error) {
return &ring.SendRawTransactionResponse{}, nil
}
func TestGrpcServer(t *testing.T) {
//onceFunc := func() {
......@@ -226,3 +231,76 @@ func BenchmarkEthTx(b *testing.B) {
}
})
}
func BenchmarkBytes(b *testing.B) {
b.ReportAllocs()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
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()
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.
//res, err := c.SendRawTransaction(ctx, &base.EthTx{Inner: &inner})
txAsBytes, err := tx.MarshalBinary()
if err != nil {
b.Fatal(err)
}
res, err := c.SendTxAsBytes(ctx, &base.TransactionBytes{Tx: txAsBytes})
if err != nil {
b.Fatal(err)
}
_ = res
//b.Logf("Greeting: %v\n", res)
}
})
}
......@@ -14,6 +14,9 @@ service RingService{
rpc SendTxAsAny(base.v1.Transaction) returns (SendRawTransactionResponse) {};
rpc SendTxAsBytes(base.v1.TransactionBytes) returns (SendRawTransactionResponse) {};
//rpc SendRawTransaction(base.v1.EthTx) returns (SendRawTransactionResponse) {};
rpc Nonce(NonceRequest) returns (NonceResponse) {};
......
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