From 61c9726b4fd04d463258fa455a42f4fff19783fc Mon Sep 17 00:00:00 2001 From: Anh Minh <1phamminh0811@gmail.com> Date: Wed, 8 Oct 2025 09:48:11 +0700 Subject: [PATCH] add origin grpc methods --- nockchain/service.pb.go | 290 ++++++++++++++++++++++++++++++----- nockchain/service_grpc.pb.go | 126 ++++++++++++++- proto/service.proto | 25 +++ wallet/service.go | 18 +++ 4 files changed, 411 insertions(+), 48 deletions(-) diff --git a/nockchain/service.pb.go b/nockchain/service.pb.go index c0549c4..6f6ef70 100644 --- a/nockchain/service.pb.go +++ b/nockchain/service.pb.go @@ -789,11 +789,187 @@ func (x *ScanResponse) GetScanData() []*ScanData { return nil } +type GetBalanceRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Address string `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetBalanceRequest) Reset() { + *x = GetBalanceRequest{} + mi := &file_service_proto_msgTypes[12] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetBalanceRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBalanceRequest) ProtoMessage() {} + +func (x *GetBalanceRequest) ProtoReflect() protoreflect.Message { + mi := &file_service_proto_msgTypes[12] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBalanceRequest.ProtoReflect.Descriptor instead. +func (*GetBalanceRequest) Descriptor() ([]byte, []int) { + return file_service_proto_rawDescGZIP(), []int{12} +} + +func (x *GetBalanceRequest) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +type GetBalanceResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Data *WalletBalanceData `protobuf:"bytes,1,opt,name=data,proto3" json:"data,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *GetBalanceResponse) Reset() { + *x = GetBalanceResponse{} + mi := &file_service_proto_msgTypes[13] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetBalanceResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetBalanceResponse) ProtoMessage() {} + +func (x *GetBalanceResponse) ProtoReflect() protoreflect.Message { + mi := &file_service_proto_msgTypes[13] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetBalanceResponse.ProtoReflect.Descriptor instead. +func (*GetBalanceResponse) Descriptor() ([]byte, []int) { + return file_service_proto_rawDescGZIP(), []int{13} +} + +func (x *GetBalanceResponse) GetData() *WalletBalanceData { + if x != nil { + return x.Data + } + return nil +} + +type SendTransactionRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + RawTx *RawTx `protobuf:"bytes,1,opt,name=raw_tx,json=rawTx,proto3" json:"raw_tx,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SendTransactionRequest) Reset() { + *x = SendTransactionRequest{} + mi := &file_service_proto_msgTypes[14] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SendTransactionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SendTransactionRequest) ProtoMessage() {} + +func (x *SendTransactionRequest) ProtoReflect() protoreflect.Message { + mi := &file_service_proto_msgTypes[14] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SendTransactionRequest.ProtoReflect.Descriptor instead. +func (*SendTransactionRequest) Descriptor() ([]byte, []int) { + return file_service_proto_rawDescGZIP(), []int{14} +} + +func (x *SendTransactionRequest) GetRawTx() *RawTx { + if x != nil { + return x.RawTx + } + return nil +} + +type SendTransactionResponse struct { + state protoimpl.MessageState `protogen:"open.v1"` + Response *WalletSendTransactionResponse `protobuf:"bytes,1,opt,name=response,proto3" json:"response,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SendTransactionResponse) Reset() { + *x = SendTransactionResponse{} + mi := &file_service_proto_msgTypes[15] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SendTransactionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SendTransactionResponse) ProtoMessage() {} + +func (x *SendTransactionResponse) ProtoReflect() protoreflect.Message { + mi := &file_service_proto_msgTypes[15] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SendTransactionResponse.ProtoReflect.Descriptor instead. +func (*SendTransactionResponse) Descriptor() ([]byte, []int) { + return file_service_proto_rawDescGZIP(), []int{15} +} + +func (x *SendTransactionResponse) GetResponse() *WalletSendTransactionResponse { + if x != nil { + return x.Response + } + return nil +} + var File_service_proto protoreflect.FileDescriptor const file_service_proto_rawDesc = "" + "\n" + - "\rservice.proto\x12\x13nockchain.public.v1\x1a\vtypes.proto\"\x0f\n" + + "\rservice.proto\x12\x13nockchain.public.v1\x1a\vtypes.proto\x1a\x10blockchain.proto\x1a\x0fnockchain.proto\"\x0f\n" + "\rKeygenRequest\"\xdd\x01\n" + "\x0eKeygenResponse\x12\x1d\n" + "\n" + @@ -863,7 +1039,15 @@ const file_service_proto_rawDesc = "" + "\x11include_timelocks\x18\x04 \x01(\bR\x10includeTimelocks\x12)\n" + "\x10include_multisig\x18\x05 \x01(\bR\x0fincludeMultisig\"J\n" + "\fScanResponse\x12:\n" + - "\tscan_data\x18\x01 \x03(\v2\x1d.nockchain.public.v1.ScanDataR\bscanData2\x9c\x04\n" + + "\tscan_data\x18\x01 \x03(\v2\x1d.nockchain.public.v1.ScanDataR\bscanData\"-\n" + + "\x11GetBalanceRequest\x12\x18\n" + + "\aaddress\x18\x01 \x01(\tR\aaddress\"P\n" + + "\x12GetBalanceResponse\x12:\n" + + "\x04data\x18\x01 \x01(\v2&.nockchain.public.v1.WalletBalanceDataR\x04data\"K\n" + + "\x16SendTransactionRequest\x121\n" + + "\x06raw_tx\x18\x01 \x01(\v2\x1a.nockchain.public.v1.RawTxR\x05rawTx\"i\n" + + "\x17SendTransactionResponse\x12N\n" + + "\bresponse\x18\x01 \x01(\v22.nockchain.public.v1.WalletSendTransactionResponseR\bresponse2\xef\x06\n" + "\rWalletService\x12Q\n" + "\x06Keygen\x12\".nockchain.public.v1.KeygenRequest\x1a#.nockchain.public.v1.KeygenResponse\x12]\n" + "\n" + @@ -871,7 +1055,10 @@ const file_service_proto_rawDesc = "" + "\vDeriveChild\x12'.nockchain.public.v1.DeriveChildRequest\x1a(.nockchain.public.v1.DeriveChildResponse\x12W\n" + "\bCreateTx\x12$.nockchain.public.v1.CreateTxRequest\x1a%.nockchain.public.v1.CreateTxResponse\x12Q\n" + "\x06SignTx\x12\".nockchain.public.v1.SignTxRequest\x1a#.nockchain.public.v1.SignTxResponse\x12K\n" + - "\x04Scan\x12 .nockchain.public.v1.ScanRequest\x1a!.nockchain.public.v1.ScanResponseB\x0eZ\f./;nockchainb\x06proto3" + "\x04Scan\x12 .nockchain.public.v1.ScanRequest\x1a!.nockchain.public.v1.ScanResponse\x12c\n" + + "\x10WalletGetBalance\x12&.nockchain.public.v1.GetBalanceRequest\x1a'.nockchain.public.v1.GetBalanceResponse\x12r\n" + + "\x15WalletSendTransaction\x12+.nockchain.public.v1.SendTransactionRequest\x1a,.nockchain.public.v1.SendTransactionResponse\x12x\n" + + "\x13TransactionAccepted\x12/.nockchain.public.v1.TransactionAcceptedRequest\x1a0.nockchain.public.v1.TransactionAcceptedResponseB\x0eZ\f./;nockchainb\x06proto3" var ( file_service_proto_rawDescOnce sync.Once @@ -885,47 +1072,64 @@ func file_service_proto_rawDescGZIP() []byte { return file_service_proto_rawDescData } -var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 12) +var file_service_proto_msgTypes = make([]protoimpl.MessageInfo, 16) var file_service_proto_goTypes = []any{ - (*KeygenRequest)(nil), // 0: nockchain.public.v1.KeygenRequest - (*KeygenResponse)(nil), // 1: nockchain.public.v1.KeygenResponse - (*ImportKeysRequest)(nil), // 2: nockchain.public.v1.ImportKeysRequest - (*ImportKeysResponse)(nil), // 3: nockchain.public.v1.ImportKeysResponse - (*DeriveChildRequest)(nil), // 4: nockchain.public.v1.DeriveChildRequest - (*DeriveChildResponse)(nil), // 5: nockchain.public.v1.DeriveChildResponse - (*CreateTxRequest)(nil), // 6: nockchain.public.v1.CreateTxRequest - (*CreateTxResponse)(nil), // 7: nockchain.public.v1.CreateTxResponse - (*SignTxRequest)(nil), // 8: nockchain.public.v1.SignTxRequest - (*SignTxResponse)(nil), // 9: nockchain.public.v1.SignTxResponse - (*ScanRequest)(nil), // 10: nockchain.public.v1.ScanRequest - (*ScanResponse)(nil), // 11: nockchain.public.v1.ScanResponse - (ImportType)(0), // 12: nockchain.public.v1.ImportType - (*TimelockIntent)(nil), // 13: nockchain.public.v1.TimelockIntent - (*RawTx)(nil), // 14: nockchain.public.v1.RawTx - (*ScanData)(nil), // 15: nockchain.public.v1.ScanData + (*KeygenRequest)(nil), // 0: nockchain.public.v1.KeygenRequest + (*KeygenResponse)(nil), // 1: nockchain.public.v1.KeygenResponse + (*ImportKeysRequest)(nil), // 2: nockchain.public.v1.ImportKeysRequest + (*ImportKeysResponse)(nil), // 3: nockchain.public.v1.ImportKeysResponse + (*DeriveChildRequest)(nil), // 4: nockchain.public.v1.DeriveChildRequest + (*DeriveChildResponse)(nil), // 5: nockchain.public.v1.DeriveChildResponse + (*CreateTxRequest)(nil), // 6: nockchain.public.v1.CreateTxRequest + (*CreateTxResponse)(nil), // 7: nockchain.public.v1.CreateTxResponse + (*SignTxRequest)(nil), // 8: nockchain.public.v1.SignTxRequest + (*SignTxResponse)(nil), // 9: nockchain.public.v1.SignTxResponse + (*ScanRequest)(nil), // 10: nockchain.public.v1.ScanRequest + (*ScanResponse)(nil), // 11: nockchain.public.v1.ScanResponse + (*GetBalanceRequest)(nil), // 12: nockchain.public.v1.GetBalanceRequest + (*GetBalanceResponse)(nil), // 13: nockchain.public.v1.GetBalanceResponse + (*SendTransactionRequest)(nil), // 14: nockchain.public.v1.SendTransactionRequest + (*SendTransactionResponse)(nil), // 15: nockchain.public.v1.SendTransactionResponse + (ImportType)(0), // 16: nockchain.public.v1.ImportType + (*TimelockIntent)(nil), // 17: nockchain.public.v1.TimelockIntent + (*RawTx)(nil), // 18: nockchain.public.v1.RawTx + (*ScanData)(nil), // 19: nockchain.public.v1.ScanData + (*WalletBalanceData)(nil), // 20: nockchain.public.v1.WalletBalanceData + (*WalletSendTransactionResponse)(nil), // 21: nockchain.public.v1.WalletSendTransactionResponse + (*TransactionAcceptedRequest)(nil), // 22: nockchain.public.v1.TransactionAcceptedRequest + (*TransactionAcceptedResponse)(nil), // 23: nockchain.public.v1.TransactionAcceptedResponse } var file_service_proto_depIdxs = []int32{ - 12, // 0: nockchain.public.v1.ImportKeysRequest.import_type:type_name -> nockchain.public.v1.ImportType - 13, // 1: nockchain.public.v1.CreateTxRequest.timelock_intent:type_name -> nockchain.public.v1.TimelockIntent - 14, // 2: nockchain.public.v1.CreateTxResponse.rawTx:type_name -> nockchain.public.v1.RawTx - 15, // 3: nockchain.public.v1.ScanResponse.scan_data:type_name -> nockchain.public.v1.ScanData - 0, // 4: nockchain.public.v1.WalletService.Keygen:input_type -> nockchain.public.v1.KeygenRequest - 2, // 5: nockchain.public.v1.WalletService.ImportKeys:input_type -> nockchain.public.v1.ImportKeysRequest - 4, // 6: nockchain.public.v1.WalletService.DeriveChild:input_type -> nockchain.public.v1.DeriveChildRequest - 6, // 7: nockchain.public.v1.WalletService.CreateTx:input_type -> nockchain.public.v1.CreateTxRequest - 8, // 8: nockchain.public.v1.WalletService.SignTx:input_type -> nockchain.public.v1.SignTxRequest - 10, // 9: nockchain.public.v1.WalletService.Scan:input_type -> nockchain.public.v1.ScanRequest - 1, // 10: nockchain.public.v1.WalletService.Keygen:output_type -> nockchain.public.v1.KeygenResponse - 3, // 11: nockchain.public.v1.WalletService.ImportKeys:output_type -> nockchain.public.v1.ImportKeysResponse - 5, // 12: nockchain.public.v1.WalletService.DeriveChild:output_type -> nockchain.public.v1.DeriveChildResponse - 7, // 13: nockchain.public.v1.WalletService.CreateTx:output_type -> nockchain.public.v1.CreateTxResponse - 9, // 14: nockchain.public.v1.WalletService.SignTx:output_type -> nockchain.public.v1.SignTxResponse - 11, // 15: nockchain.public.v1.WalletService.Scan:output_type -> nockchain.public.v1.ScanResponse - 10, // [10:16] is the sub-list for method output_type - 4, // [4:10] is the sub-list for method input_type - 4, // [4:4] is the sub-list for extension type_name - 4, // [4:4] is the sub-list for extension extendee - 0, // [0:4] is the sub-list for field type_name + 16, // 0: nockchain.public.v1.ImportKeysRequest.import_type:type_name -> nockchain.public.v1.ImportType + 17, // 1: nockchain.public.v1.CreateTxRequest.timelock_intent:type_name -> nockchain.public.v1.TimelockIntent + 18, // 2: nockchain.public.v1.CreateTxResponse.rawTx:type_name -> nockchain.public.v1.RawTx + 19, // 3: nockchain.public.v1.ScanResponse.scan_data:type_name -> nockchain.public.v1.ScanData + 20, // 4: nockchain.public.v1.GetBalanceResponse.data:type_name -> nockchain.public.v1.WalletBalanceData + 18, // 5: nockchain.public.v1.SendTransactionRequest.raw_tx:type_name -> nockchain.public.v1.RawTx + 21, // 6: nockchain.public.v1.SendTransactionResponse.response:type_name -> nockchain.public.v1.WalletSendTransactionResponse + 0, // 7: nockchain.public.v1.WalletService.Keygen:input_type -> nockchain.public.v1.KeygenRequest + 2, // 8: nockchain.public.v1.WalletService.ImportKeys:input_type -> nockchain.public.v1.ImportKeysRequest + 4, // 9: nockchain.public.v1.WalletService.DeriveChild:input_type -> nockchain.public.v1.DeriveChildRequest + 6, // 10: nockchain.public.v1.WalletService.CreateTx:input_type -> nockchain.public.v1.CreateTxRequest + 8, // 11: nockchain.public.v1.WalletService.SignTx:input_type -> nockchain.public.v1.SignTxRequest + 10, // 12: nockchain.public.v1.WalletService.Scan:input_type -> nockchain.public.v1.ScanRequest + 12, // 13: nockchain.public.v1.WalletService.WalletGetBalance:input_type -> nockchain.public.v1.GetBalanceRequest + 14, // 14: nockchain.public.v1.WalletService.WalletSendTransaction:input_type -> nockchain.public.v1.SendTransactionRequest + 22, // 15: nockchain.public.v1.WalletService.TransactionAccepted:input_type -> nockchain.public.v1.TransactionAcceptedRequest + 1, // 16: nockchain.public.v1.WalletService.Keygen:output_type -> nockchain.public.v1.KeygenResponse + 3, // 17: nockchain.public.v1.WalletService.ImportKeys:output_type -> nockchain.public.v1.ImportKeysResponse + 5, // 18: nockchain.public.v1.WalletService.DeriveChild:output_type -> nockchain.public.v1.DeriveChildResponse + 7, // 19: nockchain.public.v1.WalletService.CreateTx:output_type -> nockchain.public.v1.CreateTxResponse + 9, // 20: nockchain.public.v1.WalletService.SignTx:output_type -> nockchain.public.v1.SignTxResponse + 11, // 21: nockchain.public.v1.WalletService.Scan:output_type -> nockchain.public.v1.ScanResponse + 13, // 22: nockchain.public.v1.WalletService.WalletGetBalance:output_type -> nockchain.public.v1.GetBalanceResponse + 15, // 23: nockchain.public.v1.WalletService.WalletSendTransaction:output_type -> nockchain.public.v1.SendTransactionResponse + 23, // 24: nockchain.public.v1.WalletService.TransactionAccepted:output_type -> nockchain.public.v1.TransactionAcceptedResponse + 16, // [16:25] is the sub-list for method output_type + 7, // [7:16] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name } func init() { file_service_proto_init() } @@ -934,13 +1138,15 @@ func file_service_proto_init() { return } file_types_proto_init() + file_blockchain_proto_init() + file_nockchain_proto_init() type x struct{} out := protoimpl.TypeBuilder{ File: protoimpl.DescBuilder{ GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: unsafe.Slice(unsafe.StringData(file_service_proto_rawDesc), len(file_service_proto_rawDesc)), NumEnums: 0, - NumMessages: 12, + NumMessages: 16, NumExtensions: 0, NumServices: 1, }, diff --git a/nockchain/service_grpc.pb.go b/nockchain/service_grpc.pb.go index 33828f9..a8f205e 100644 --- a/nockchain/service_grpc.pb.go +++ b/nockchain/service_grpc.pb.go @@ -19,12 +19,15 @@ import ( const _ = grpc.SupportPackageIsVersion9 const ( - WalletService_Keygen_FullMethodName = "/nockchain.public.v1.WalletService/Keygen" - WalletService_ImportKeys_FullMethodName = "/nockchain.public.v1.WalletService/ImportKeys" - WalletService_DeriveChild_FullMethodName = "/nockchain.public.v1.WalletService/DeriveChild" - WalletService_CreateTx_FullMethodName = "/nockchain.public.v1.WalletService/CreateTx" - WalletService_SignTx_FullMethodName = "/nockchain.public.v1.WalletService/SignTx" - WalletService_Scan_FullMethodName = "/nockchain.public.v1.WalletService/Scan" + WalletService_Keygen_FullMethodName = "/nockchain.public.v1.WalletService/Keygen" + WalletService_ImportKeys_FullMethodName = "/nockchain.public.v1.WalletService/ImportKeys" + WalletService_DeriveChild_FullMethodName = "/nockchain.public.v1.WalletService/DeriveChild" + WalletService_CreateTx_FullMethodName = "/nockchain.public.v1.WalletService/CreateTx" + WalletService_SignTx_FullMethodName = "/nockchain.public.v1.WalletService/SignTx" + WalletService_Scan_FullMethodName = "/nockchain.public.v1.WalletService/Scan" + WalletService_WalletGetBalance_FullMethodName = "/nockchain.public.v1.WalletService/WalletGetBalance" + WalletService_WalletSendTransaction_FullMethodName = "/nockchain.public.v1.WalletService/WalletSendTransaction" + WalletService_TransactionAccepted_FullMethodName = "/nockchain.public.v1.WalletService/TransactionAccepted" ) // WalletServiceClient is the client API for WalletService service. @@ -37,6 +40,9 @@ type WalletServiceClient interface { CreateTx(ctx context.Context, in *CreateTxRequest, opts ...grpc.CallOption) (*CreateTxResponse, error) SignTx(ctx context.Context, in *SignTxRequest, opts ...grpc.CallOption) (*SignTxResponse, error) Scan(ctx context.Context, in *ScanRequest, opts ...grpc.CallOption) (*ScanResponse, error) + WalletGetBalance(ctx context.Context, in *GetBalanceRequest, opts ...grpc.CallOption) (*GetBalanceResponse, error) + WalletSendTransaction(ctx context.Context, in *SendTransactionRequest, opts ...grpc.CallOption) (*SendTransactionResponse, error) + TransactionAccepted(ctx context.Context, in *TransactionAcceptedRequest, opts ...grpc.CallOption) (*TransactionAcceptedResponse, error) } type walletServiceClient struct { @@ -107,6 +113,36 @@ func (c *walletServiceClient) Scan(ctx context.Context, in *ScanRequest, opts .. return out, nil } +func (c *walletServiceClient) WalletGetBalance(ctx context.Context, in *GetBalanceRequest, opts ...grpc.CallOption) (*GetBalanceResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetBalanceResponse) + err := c.cc.Invoke(ctx, WalletService_WalletGetBalance_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *walletServiceClient) WalletSendTransaction(ctx context.Context, in *SendTransactionRequest, opts ...grpc.CallOption) (*SendTransactionResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(SendTransactionResponse) + err := c.cc.Invoke(ctx, WalletService_WalletSendTransaction_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *walletServiceClient) TransactionAccepted(ctx context.Context, in *TransactionAcceptedRequest, opts ...grpc.CallOption) (*TransactionAcceptedResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(TransactionAcceptedResponse) + err := c.cc.Invoke(ctx, WalletService_TransactionAccepted_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + // WalletServiceServer is the server API for WalletService service. // All implementations must embed UnimplementedWalletServiceServer // for forward compatibility. @@ -117,6 +153,9 @@ type WalletServiceServer interface { CreateTx(context.Context, *CreateTxRequest) (*CreateTxResponse, error) SignTx(context.Context, *SignTxRequest) (*SignTxResponse, error) Scan(context.Context, *ScanRequest) (*ScanResponse, error) + WalletGetBalance(context.Context, *GetBalanceRequest) (*GetBalanceResponse, error) + WalletSendTransaction(context.Context, *SendTransactionRequest) (*SendTransactionResponse, error) + TransactionAccepted(context.Context, *TransactionAcceptedRequest) (*TransactionAcceptedResponse, error) mustEmbedUnimplementedWalletServiceServer() } @@ -145,6 +184,15 @@ func (UnimplementedWalletServiceServer) SignTx(context.Context, *SignTxRequest) func (UnimplementedWalletServiceServer) Scan(context.Context, *ScanRequest) (*ScanResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method Scan not implemented") } +func (UnimplementedWalletServiceServer) WalletGetBalance(context.Context, *GetBalanceRequest) (*GetBalanceResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WalletGetBalance not implemented") +} +func (UnimplementedWalletServiceServer) WalletSendTransaction(context.Context, *SendTransactionRequest) (*SendTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method WalletSendTransaction not implemented") +} +func (UnimplementedWalletServiceServer) TransactionAccepted(context.Context, *TransactionAcceptedRequest) (*TransactionAcceptedResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method TransactionAccepted not implemented") +} func (UnimplementedWalletServiceServer) mustEmbedUnimplementedWalletServiceServer() {} func (UnimplementedWalletServiceServer) testEmbeddedByValue() {} @@ -274,6 +322,60 @@ func _WalletService_Scan_Handler(srv interface{}, ctx context.Context, dec func( return interceptor(ctx, in, info, handler) } +func _WalletService_WalletGetBalance_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetBalanceRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WalletServiceServer).WalletGetBalance(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WalletService_WalletGetBalance_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WalletServiceServer).WalletGetBalance(ctx, req.(*GetBalanceRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _WalletService_WalletSendTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(SendTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WalletServiceServer).WalletSendTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WalletService_WalletSendTransaction_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WalletServiceServer).WalletSendTransaction(ctx, req.(*SendTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _WalletService_TransactionAccepted_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(TransactionAcceptedRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(WalletServiceServer).TransactionAccepted(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: WalletService_TransactionAccepted_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(WalletServiceServer).TransactionAccepted(ctx, req.(*TransactionAcceptedRequest)) + } + return interceptor(ctx, in, info, handler) +} + // WalletService_ServiceDesc is the grpc.ServiceDesc for WalletService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -305,6 +407,18 @@ var WalletService_ServiceDesc = grpc.ServiceDesc{ MethodName: "Scan", Handler: _WalletService_Scan_Handler, }, + { + MethodName: "WalletGetBalance", + Handler: _WalletService_WalletGetBalance_Handler, + }, + { + MethodName: "WalletSendTransaction", + Handler: _WalletService_WalletSendTransaction_Handler, + }, + { + MethodName: "TransactionAccepted", + Handler: _WalletService_TransactionAccepted_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "service.proto", diff --git a/proto/service.proto b/proto/service.proto index 5b4ded4..d37aad1 100644 --- a/proto/service.proto +++ b/proto/service.proto @@ -4,6 +4,8 @@ package nockchain.public.v1; option go_package = "./;nockchain"; import "types.proto"; +import "blockchain.proto"; +import "nockchain.proto"; service WalletService { rpc Keygen(KeygenRequest) returns (KeygenResponse); rpc ImportKeys(ImportKeysRequest) returns (ImportKeysResponse); @@ -11,6 +13,12 @@ service WalletService { rpc CreateTx(CreateTxRequest) returns (CreateTxResponse); rpc SignTx(SignTxRequest) returns (SignTxResponse); rpc Scan(ScanRequest) returns (ScanResponse); + rpc WalletGetBalance(GetBalanceRequest) + returns (GetBalanceResponse); + rpc WalletSendTransaction(SendTransactionRequest) + returns (SendTransactionResponse); + rpc TransactionAccepted(TransactionAcceptedRequest) + returns (TransactionAcceptedResponse); } message KeygenRequest {} @@ -89,3 +97,20 @@ message ScanRequest { message ScanResponse { repeated ScanData scan_data = 1; } + +message GetBalanceRequest { + string address = 1; +} + +message GetBalanceResponse { + WalletBalanceData data = 1; +} + +message SendTransactionRequest { + RawTx raw_tx = 1; +} + +message SendTransactionResponse { + WalletSendTransactionResponse response = 1; +} + diff --git a/wallet/service.go b/wallet/service.go index b3b2a3c..568c24a 100644 --- a/wallet/service.go +++ b/wallet/service.go @@ -527,6 +527,24 @@ func (h *GprcHandler) Scan(ctx context.Context, req *nockchain.ScanRequest) (*no }, nil } +func (h *GprcHandler) WalletGetBalance(_ context.Context, req *nockchain.GetBalanceRequest) (*nockchain.GetBalanceResponse, error) { + data, err := h.client.WalletGetBalance(req.Address) + return &nockchain.GetBalanceResponse{ + Data: data, + }, err +} + +func (h *GprcHandler) WalletSendTransaction(_ context.Context, req *nockchain.SendTransactionRequest) (*nockchain.SendTransactionResponse, error) { + resp, err := h.client.WalletSendTransaction(req.RawTx) + return &nockchain.SendTransactionResponse{ + Response: resp, + }, err +} + +func (h *GprcHandler) TransactionAccepted(_ context.Context, req *nockchain.TransactionAcceptedRequest) (*nockchain.TransactionAcceptedResponse, error) { + return h.client.TxAccepted(req.TxId.Hash) +} + func (h *GprcHandler) SignTx(context.Context, *nockchain.SignTxRequest) (*nockchain.SignTxResponse, error) { return nil, nil }