From 4f38d4291f65436e6126659ec8512fa078ad9ee3 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sun, 26 Jan 2025 19:51:35 +0800 Subject: [PATCH] :sparkles: Payment related grpc method --- pkg/internal/grpc/payment.go | 92 ++++ pkg/internal/models/transaction.go | 18 + pkg/internal/models/wallet.go | 11 + pkg/internal/server/api/wallet_api.go | 9 + pkg/proto/payment.pb.go | 683 ++++++++++++++++++++++++++ pkg/proto/payment.proto | 60 +++ pkg/proto/payment_grpc.pb.go | 235 +++++++++ 7 files changed, 1108 insertions(+) create mode 100644 pkg/internal/grpc/payment.go create mode 100644 pkg/proto/payment.pb.go create mode 100644 pkg/proto/payment.proto create mode 100644 pkg/proto/payment_grpc.pb.go diff --git a/pkg/internal/grpc/payment.go b/pkg/internal/grpc/payment.go new file mode 100644 index 0000000..42040f4 --- /dev/null +++ b/pkg/internal/grpc/payment.go @@ -0,0 +1,92 @@ +package grpc + +import ( + "context" + "git.solsynth.dev/hypernet/wallet/pkg/internal/database" + "git.solsynth.dev/hypernet/wallet/pkg/internal/models" + "git.solsynth.dev/hypernet/wallet/pkg/proto" + "github.com/samber/lo" + "github.com/shopspring/decimal" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (v *Server) GetWallet(ctx context.Context, request *proto.GetWalletRequest) (*proto.GetWalletResponse, error) { + var wallet models.Wallet + if err := database.C.Where("account_id = ?", request.AccountId).First(&wallet).Error; err != nil { + return nil, status.Errorf(codes.NotFound, "wallet not found") + } + + return &proto.GetWalletResponse{ + Wallet: wallet.ToWalletInfo(), + }, nil +} + +func (v *Server) GetTransaction(ctx context.Context, request *proto.GetTransactionRequest) (*proto.GetTransactionResponse, error) { + var transaction models.Transaction + if err := database.C.Where("id = ?", request.Id).First(&transaction).Error; err != nil { + return nil, status.Errorf(codes.NotFound, "transaction not found") + } + + return &proto.GetTransactionResponse{ + Transaction: transaction.ToTransactionInfo(), + }, nil +} + +func (v *Server) MakeTransaction(ctx context.Context, request *proto.MakeTransactionRequest) (*proto.TransactionInfo, error) { + if request.PayerId == nil && request.PayeeId == nil { + return nil, status.Errorf(codes.InvalidArgument, "payer and payee cannot be both nil") + } + + transaction := models.Transaction{ + Amount: decimal.NewFromFloat(request.Amount), + Remark: request.Remark, + } + if request.PayerId != nil { + transaction.PayerID = lo.ToPtr(uint(*request.PayerId)) + } + if request.PayeeId != nil { + transaction.PayeeID = lo.ToPtr(uint(*request.PayeeId)) + } + + if err := database.C.Create(&transaction).Error; err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) + } + + return transaction.ToTransactionInfo(), nil +} + +func (v *Server) MakeTransactionWithAccount(ctx context.Context, request *proto.MakeTransactionWithAccountRequest) (*proto.TransactionInfo, error) { + if request.PayerAccountId == nil && request.PayeeAccountId == nil { + return nil, status.Errorf(codes.InvalidArgument, "payer and payee cannot be both nil") + } + + transaction := models.Transaction{ + Amount: decimal.NewFromFloat(request.Amount), + Remark: request.Remark, + } + if request.PayerAccountId != nil { + val := uint(*request.PayerAccountId) + var wallet models.Wallet + if err := database.C.Where("account_id = ?", val).First(&wallet).Error; err != nil { + return nil, status.Errorf(codes.NotFound, "payer wallet not found") + } + transaction.Payer = &wallet + transaction.PayerID = &wallet.ID + } + if request.PayeeAccountId != nil { + val := uint(*request.PayeeAccountId) + var wallet models.Wallet + if err := database.C.Where("account_id = ?", val).First(&wallet).Error; err != nil { + return nil, status.Errorf(codes.NotFound, "payee wallet not found") + } + transaction.Payee = &wallet + transaction.PayeeID = &wallet.ID + } + + if err := database.C.Create(&transaction).Error; err != nil { + return nil, status.Errorf(codes.Internal, err.Error()) + } + + return transaction.ToTransactionInfo(), nil +} diff --git a/pkg/internal/models/transaction.go b/pkg/internal/models/transaction.go index bffe78e..de4dcc1 100644 --- a/pkg/internal/models/transaction.go +++ b/pkg/internal/models/transaction.go @@ -2,6 +2,8 @@ package models import ( "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda" + "git.solsynth.dev/hypernet/wallet/pkg/proto" + "github.com/samber/lo" "github.com/shopspring/decimal" ) @@ -15,3 +17,19 @@ type Transaction struct { PayerID *uint `json:"payer_id"` // Leave this field as nil means pay from the system PayeeID *uint `json:"payee_id"` // Leave this field as nil means pay to the system } + +func (v *Transaction) ToTransactionInfo() *proto.TransactionInfo { + amount, _ := v.Amount.Float64() + info := &proto.TransactionInfo{ + Id: uint64(v.ID), + Amount: amount, + Remark: v.Remark, + } + if v.PayerID != nil { + info.PayerId = lo.ToPtr(uint64(*v.PayerID)) + } + if v.PayeeID != nil { + info.PayeeId = lo.ToPtr(uint64(*v.PayeeID)) + } + return info +} diff --git a/pkg/internal/models/wallet.go b/pkg/internal/models/wallet.go index acde363..ece052a 100644 --- a/pkg/internal/models/wallet.go +++ b/pkg/internal/models/wallet.go @@ -2,6 +2,7 @@ package models import ( "git.solsynth.dev/hypernet/nexus/pkg/nex/cruda" + "git.solsynth.dev/hypernet/wallet/pkg/proto" "github.com/shopspring/decimal" ) @@ -10,5 +11,15 @@ type Wallet struct { Transactions []Transaction `json:"transactions"` Balance decimal.Decimal `json:"amount" sql:"type:decimal(30,2);"` + Password string `json:"password"` AccountID uint `json:"account_id"` } + +func (v *Wallet) ToWalletInfo() *proto.WalletInfo { + balance, _ := v.Balance.Float64() + return &proto.WalletInfo{ + Id: uint64(v.ID), + Balance: balance, + AccountId: uint64(v.AccountID), + } +} diff --git a/pkg/internal/server/api/wallet_api.go b/pkg/internal/server/api/wallet_api.go index 44521dc..1f15884 100644 --- a/pkg/internal/server/api/wallet_api.go +++ b/pkg/internal/server/api/wallet_api.go @@ -2,6 +2,7 @@ package api import ( "errors" + "git.solsynth.dev/hypernet/wallet/pkg/internal/server/exts" "git.solsynth.dev/hypernet/nexus/pkg/nex/sec" "git.solsynth.dev/hypernet/wallet/pkg/internal/database" @@ -17,6 +18,14 @@ func createWallet(c *fiber.Ctx) error { } user := c.Locals("user").(*sec.UserInfo) + var data struct { + Password string `json:"password" validate:"min=4"` + } + + if err := exts.BindAndValidate(c, &data); err != nil { + return err + } + var wallet models.Wallet if err := database.C.Where("account_id = ?", user.ID). First(&wallet).Error; err == nil || errors.Is(err, gorm.ErrRecordNotFound) { diff --git a/pkg/proto/payment.pb.go b/pkg/proto/payment.pb.go new file mode 100644 index 0000000..b9d8c37 --- /dev/null +++ b/pkg/proto/payment.pb.go @@ -0,0 +1,683 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.35.1 +// protoc v5.28.3 +// source: payment.proto + +package proto + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type WalletInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + Balance float64 `protobuf:"fixed64,2,opt,name=balance,proto3" json:"balance,omitempty"` + AccountId uint64 `protobuf:"varint,3,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"` +} + +func (x *WalletInfo) Reset() { + *x = WalletInfo{} + mi := &file_payment_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *WalletInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*WalletInfo) ProtoMessage() {} + +func (x *WalletInfo) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[0] + 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 WalletInfo.ProtoReflect.Descriptor instead. +func (*WalletInfo) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{0} +} + +func (x *WalletInfo) GetId() uint64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *WalletInfo) GetBalance() float64 { + if x != nil { + return x.Balance + } + return 0 +} + +func (x *WalletInfo) GetAccountId() uint64 { + if x != nil { + return x.AccountId + } + return 0 +} + +type TransactionInfo struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` + PayerId *uint64 `protobuf:"varint,2,opt,name=payer_id,json=payerId,proto3,oneof" json:"payer_id,omitempty"` + PayeeId *uint64 `protobuf:"varint,3,opt,name=payee_id,json=payeeId,proto3,oneof" json:"payee_id,omitempty"` + Amount float64 `protobuf:"fixed64,4,opt,name=amount,proto3" json:"amount,omitempty"` + Remark string `protobuf:"bytes,5,opt,name=remark,proto3" json:"remark,omitempty"` +} + +func (x *TransactionInfo) Reset() { + *x = TransactionInfo{} + mi := &file_payment_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *TransactionInfo) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*TransactionInfo) ProtoMessage() {} + +func (x *TransactionInfo) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[1] + 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 TransactionInfo.ProtoReflect.Descriptor instead. +func (*TransactionInfo) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{1} +} + +func (x *TransactionInfo) GetId() uint64 { + if x != nil { + return x.Id + } + return 0 +} + +func (x *TransactionInfo) GetPayerId() uint64 { + if x != nil && x.PayerId != nil { + return *x.PayerId + } + return 0 +} + +func (x *TransactionInfo) GetPayeeId() uint64 { + if x != nil && x.PayeeId != nil { + return *x.PayeeId + } + return 0 +} + +func (x *TransactionInfo) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *TransactionInfo) GetRemark() string { + if x != nil { + return x.Remark + } + return "" +} + +type GetWalletRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + AccountId uint64 `protobuf:"varint,1,opt,name=account_id,json=accountId,proto3" json:"account_id,omitempty"` +} + +func (x *GetWalletRequest) Reset() { + *x = GetWalletRequest{} + mi := &file_payment_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetWalletRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetWalletRequest) ProtoMessage() {} + +func (x *GetWalletRequest) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[2] + 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 GetWalletRequest.ProtoReflect.Descriptor instead. +func (*GetWalletRequest) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{2} +} + +func (x *GetWalletRequest) GetAccountId() uint64 { + if x != nil { + return x.AccountId + } + return 0 +} + +type GetWalletResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Wallet *WalletInfo `protobuf:"bytes,1,opt,name=wallet,proto3" json:"wallet,omitempty"` +} + +func (x *GetWalletResponse) Reset() { + *x = GetWalletResponse{} + mi := &file_payment_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetWalletResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetWalletResponse) ProtoMessage() {} + +func (x *GetWalletResponse) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[3] + 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 GetWalletResponse.ProtoReflect.Descriptor instead. +func (*GetWalletResponse) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{3} +} + +func (x *GetWalletResponse) GetWallet() *WalletInfo { + if x != nil { + return x.Wallet + } + return nil +} + +type GetTransactionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id uint64 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetTransactionRequest) Reset() { + *x = GetTransactionRequest{} + mi := &file_payment_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetTransactionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetTransactionRequest) ProtoMessage() {} + +func (x *GetTransactionRequest) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[4] + 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 GetTransactionRequest.ProtoReflect.Descriptor instead. +func (*GetTransactionRequest) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{4} +} + +func (x *GetTransactionRequest) GetId() uint64 { + if x != nil { + return x.Id + } + return 0 +} + +type GetTransactionResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Transaction *TransactionInfo `protobuf:"bytes,1,opt,name=transaction,proto3" json:"transaction,omitempty"` +} + +func (x *GetTransactionResponse) Reset() { + *x = GetTransactionResponse{} + mi := &file_payment_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *GetTransactionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetTransactionResponse) ProtoMessage() {} + +func (x *GetTransactionResponse) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[5] + 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 GetTransactionResponse.ProtoReflect.Descriptor instead. +func (*GetTransactionResponse) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{5} +} + +func (x *GetTransactionResponse) GetTransaction() *TransactionInfo { + if x != nil { + return x.Transaction + } + return nil +} + +type MakeTransactionRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PayerId *uint64 `protobuf:"varint,1,opt,name=payer_id,json=payerId,proto3,oneof" json:"payer_id,omitempty"` + PayeeId *uint64 `protobuf:"varint,2,opt,name=payee_id,json=payeeId,proto3,oneof" json:"payee_id,omitempty"` + Amount float64 `protobuf:"fixed64,3,opt,name=amount,proto3" json:"amount,omitempty"` + Remark string `protobuf:"bytes,4,opt,name=remark,proto3" json:"remark,omitempty"` +} + +func (x *MakeTransactionRequest) Reset() { + *x = MakeTransactionRequest{} + mi := &file_payment_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MakeTransactionRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MakeTransactionRequest) ProtoMessage() {} + +func (x *MakeTransactionRequest) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[6] + 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 MakeTransactionRequest.ProtoReflect.Descriptor instead. +func (*MakeTransactionRequest) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{6} +} + +func (x *MakeTransactionRequest) GetPayerId() uint64 { + if x != nil && x.PayerId != nil { + return *x.PayerId + } + return 0 +} + +func (x *MakeTransactionRequest) GetPayeeId() uint64 { + if x != nil && x.PayeeId != nil { + return *x.PayeeId + } + return 0 +} + +func (x *MakeTransactionRequest) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *MakeTransactionRequest) GetRemark() string { + if x != nil { + return x.Remark + } + return "" +} + +type MakeTransactionResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Transaction *TransactionInfo `protobuf:"bytes,1,opt,name=transaction,proto3" json:"transaction,omitempty"` +} + +func (x *MakeTransactionResponse) Reset() { + *x = MakeTransactionResponse{} + mi := &file_payment_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MakeTransactionResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MakeTransactionResponse) ProtoMessage() {} + +func (x *MakeTransactionResponse) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[7] + 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 MakeTransactionResponse.ProtoReflect.Descriptor instead. +func (*MakeTransactionResponse) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{7} +} + +func (x *MakeTransactionResponse) GetTransaction() *TransactionInfo { + if x != nil { + return x.Transaction + } + return nil +} + +type MakeTransactionWithAccountRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + PayerAccountId *uint64 `protobuf:"varint,1,opt,name=payer_account_id,json=payerAccountId,proto3,oneof" json:"payer_account_id,omitempty"` + PayeeAccountId *uint64 `protobuf:"varint,2,opt,name=payee_account_id,json=payeeAccountId,proto3,oneof" json:"payee_account_id,omitempty"` + Amount float64 `protobuf:"fixed64,3,opt,name=amount,proto3" json:"amount,omitempty"` + Remark string `protobuf:"bytes,4,opt,name=remark,proto3" json:"remark,omitempty"` +} + +func (x *MakeTransactionWithAccountRequest) Reset() { + *x = MakeTransactionWithAccountRequest{} + mi := &file_payment_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *MakeTransactionWithAccountRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*MakeTransactionWithAccountRequest) ProtoMessage() {} + +func (x *MakeTransactionWithAccountRequest) ProtoReflect() protoreflect.Message { + mi := &file_payment_proto_msgTypes[8] + 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 MakeTransactionWithAccountRequest.ProtoReflect.Descriptor instead. +func (*MakeTransactionWithAccountRequest) Descriptor() ([]byte, []int) { + return file_payment_proto_rawDescGZIP(), []int{8} +} + +func (x *MakeTransactionWithAccountRequest) GetPayerAccountId() uint64 { + if x != nil && x.PayerAccountId != nil { + return *x.PayerAccountId + } + return 0 +} + +func (x *MakeTransactionWithAccountRequest) GetPayeeAccountId() uint64 { + if x != nil && x.PayeeAccountId != nil { + return *x.PayeeAccountId + } + return 0 +} + +func (x *MakeTransactionWithAccountRequest) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *MakeTransactionWithAccountRequest) GetRemark() string { + if x != nil { + return x.Remark + } + return "" +} + +var File_payment_proto protoreflect.FileDescriptor + +var file_payment_proto_rawDesc = []byte{ + 0x0a, 0x0d, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x05, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x55, 0x0a, 0x0a, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, + 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x07, 0x62, 0x61, 0x6c, 0x61, 0x6e, 0x63, 0x65, 0x12, 0x1d, + 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0xab, 0x01, + 0x0a, 0x0f, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, + 0x6f, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, + 0x64, 0x12, 0x1e, 0x0a, 0x08, 0x70, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x07, 0x70, 0x61, 0x79, 0x65, 0x72, 0x49, 0x64, 0x88, 0x01, + 0x01, 0x12, 0x1e, 0x0a, 0x08, 0x70, 0x61, 0x79, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x04, 0x48, 0x01, 0x52, 0x07, 0x70, 0x61, 0x79, 0x65, 0x65, 0x49, 0x64, 0x88, 0x01, + 0x01, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x6d, + 0x61, 0x72, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, + 0x6b, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x79, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x42, 0x0b, + 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x79, 0x65, 0x65, 0x5f, 0x69, 0x64, 0x22, 0x31, 0x0a, 0x10, 0x47, + 0x65, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1d, 0x0a, 0x0a, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x09, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x3e, + 0x0a, 0x11, 0x47, 0x65, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x06, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x57, 0x61, 0x6c, 0x6c, + 0x65, 0x74, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x06, 0x77, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x22, 0x27, + 0x0a, 0x15, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x02, 0x69, 0x64, 0x22, 0x52, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x12, 0x38, 0x0a, 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, + 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xa2, 0x01, 0x0a, 0x16, + 0x4d, 0x61, 0x6b, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1e, 0x0a, 0x08, 0x70, 0x61, 0x79, 0x65, 0x72, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x07, 0x70, 0x61, 0x79, 0x65, + 0x72, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1e, 0x0a, 0x08, 0x70, 0x61, 0x79, 0x65, 0x65, 0x5f, + 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x48, 0x01, 0x52, 0x07, 0x70, 0x61, 0x79, 0x65, + 0x65, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x16, + 0x0a, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x79, 0x65, 0x72, + 0x5f, 0x69, 0x64, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x79, 0x65, 0x65, 0x5f, 0x69, 0x64, + 0x22, 0x53, 0x0a, 0x17, 0x4d, 0x61, 0x6b, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x38, 0x0a, 0x0b, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x0b, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x61, + 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0xdb, 0x01, 0x0a, 0x21, 0x4d, 0x61, 0x6b, 0x65, 0x54, 0x72, + 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x69, 0x74, 0x68, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2d, 0x0a, 0x10, 0x70, + 0x61, 0x79, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x0e, 0x70, 0x61, 0x79, 0x65, 0x72, 0x41, 0x63, + 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x2d, 0x0a, 0x10, 0x70, 0x61, + 0x79, 0x65, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x04, 0x48, 0x01, 0x52, 0x0e, 0x70, 0x61, 0x79, 0x65, 0x65, 0x41, 0x63, 0x63, + 0x6f, 0x75, 0x6e, 0x74, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, + 0x74, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x72, 0x65, 0x6d, 0x61, 0x72, 0x6b, 0x42, 0x13, 0x0a, 0x11, 0x5f, 0x70, 0x61, + 0x79, 0x65, 0x72, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x42, 0x13, + 0x0a, 0x11, 0x5f, 0x70, 0x61, 0x79, 0x65, 0x65, 0x5f, 0x61, 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x5f, 0x69, 0x64, 0x32, 0xd1, 0x02, 0x0a, 0x0e, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x40, 0x0a, 0x09, 0x47, 0x65, 0x74, 0x57, 0x61, 0x6c, + 0x6c, 0x65, 0x74, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x57, + 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x57, 0x61, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4f, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x54, + 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1d, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x47, 0x65, 0x74, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x4a, 0x0a, 0x0f, 0x4d, 0x61, 0x6b, + 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1d, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x61, 0x6b, 0x65, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, + 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x49, + 0x6e, 0x66, 0x6f, 0x22, 0x00, 0x12, 0x60, 0x0a, 0x1a, 0x4d, 0x61, 0x6b, 0x65, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x69, 0x74, 0x68, 0x41, 0x63, 0x63, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x28, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x4d, 0x61, 0x6b, 0x65, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x57, 0x69, 0x74, 0x68, 0x41, + 0x63, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x16, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x61, 0x63, 0x74, 0x69, 0x6f, + 0x6e, 0x49, 0x6e, 0x66, 0x6f, 0x22, 0x00, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x3b, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_payment_proto_rawDescOnce sync.Once + file_payment_proto_rawDescData = file_payment_proto_rawDesc +) + +func file_payment_proto_rawDescGZIP() []byte { + file_payment_proto_rawDescOnce.Do(func() { + file_payment_proto_rawDescData = protoimpl.X.CompressGZIP(file_payment_proto_rawDescData) + }) + return file_payment_proto_rawDescData +} + +var file_payment_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_payment_proto_goTypes = []any{ + (*WalletInfo)(nil), // 0: proto.WalletInfo + (*TransactionInfo)(nil), // 1: proto.TransactionInfo + (*GetWalletRequest)(nil), // 2: proto.GetWalletRequest + (*GetWalletResponse)(nil), // 3: proto.GetWalletResponse + (*GetTransactionRequest)(nil), // 4: proto.GetTransactionRequest + (*GetTransactionResponse)(nil), // 5: proto.GetTransactionResponse + (*MakeTransactionRequest)(nil), // 6: proto.MakeTransactionRequest + (*MakeTransactionResponse)(nil), // 7: proto.MakeTransactionResponse + (*MakeTransactionWithAccountRequest)(nil), // 8: proto.MakeTransactionWithAccountRequest +} +var file_payment_proto_depIdxs = []int32{ + 0, // 0: proto.GetWalletResponse.wallet:type_name -> proto.WalletInfo + 1, // 1: proto.GetTransactionResponse.transaction:type_name -> proto.TransactionInfo + 1, // 2: proto.MakeTransactionResponse.transaction:type_name -> proto.TransactionInfo + 2, // 3: proto.PaymentService.GetWallet:input_type -> proto.GetWalletRequest + 4, // 4: proto.PaymentService.GetTransaction:input_type -> proto.GetTransactionRequest + 6, // 5: proto.PaymentService.MakeTransaction:input_type -> proto.MakeTransactionRequest + 8, // 6: proto.PaymentService.MakeTransactionWithAccount:input_type -> proto.MakeTransactionWithAccountRequest + 3, // 7: proto.PaymentService.GetWallet:output_type -> proto.GetWalletResponse + 5, // 8: proto.PaymentService.GetTransaction:output_type -> proto.GetTransactionResponse + 1, // 9: proto.PaymentService.MakeTransaction:output_type -> proto.TransactionInfo + 1, // 10: proto.PaymentService.MakeTransactionWithAccount:output_type -> proto.TransactionInfo + 7, // [7:11] is the sub-list for method output_type + 3, // [3:7] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name +} + +func init() { file_payment_proto_init() } +func file_payment_proto_init() { + if File_payment_proto != nil { + return + } + file_payment_proto_msgTypes[1].OneofWrappers = []any{} + file_payment_proto_msgTypes[6].OneofWrappers = []any{} + file_payment_proto_msgTypes[8].OneofWrappers = []any{} + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_payment_proto_rawDesc, + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_payment_proto_goTypes, + DependencyIndexes: file_payment_proto_depIdxs, + MessageInfos: file_payment_proto_msgTypes, + }.Build() + File_payment_proto = out.File + file_payment_proto_rawDesc = nil + file_payment_proto_goTypes = nil + file_payment_proto_depIdxs = nil +} diff --git a/pkg/proto/payment.proto b/pkg/proto/payment.proto new file mode 100644 index 0000000..b71509f --- /dev/null +++ b/pkg/proto/payment.proto @@ -0,0 +1,60 @@ +syntax = "proto3"; + +option go_package = ".;proto"; + +package proto; + +service PaymentService { + rpc GetWallet(GetWalletRequest) returns (GetWalletResponse) {} + rpc GetTransaction(GetTransactionRequest) returns (GetTransactionResponse) {} + rpc MakeTransaction(MakeTransactionRequest) returns (TransactionInfo) {} + rpc MakeTransactionWithAccount(MakeTransactionWithAccountRequest) returns (TransactionInfo) {} +} + +message WalletInfo { + uint64 id = 1; + double balance = 2; + uint64 account_id = 3; +} + +message TransactionInfo { + uint64 id = 1; + optional uint64 payer_id = 2; + optional uint64 payee_id = 3; + double amount = 4; + string remark = 5; +} + +message GetWalletRequest { + uint64 account_id = 1; +} + +message GetWalletResponse { + WalletInfo wallet = 1; +} + +message GetTransactionRequest { + uint64 id = 1; +} + +message GetTransactionResponse { + TransactionInfo transaction = 1; +} + +message MakeTransactionRequest { + optional uint64 payer_id = 1; + optional uint64 payee_id = 2; + double amount = 3; + string remark = 4; +} + +message MakeTransactionResponse { + TransactionInfo transaction = 1; +} + +message MakeTransactionWithAccountRequest { + optional uint64 payer_account_id = 1; + optional uint64 payee_account_id = 2; + double amount = 3; + string remark = 4; +} diff --git a/pkg/proto/payment_grpc.pb.go b/pkg/proto/payment_grpc.pb.go new file mode 100644 index 0000000..05aee4c --- /dev/null +++ b/pkg/proto/payment_grpc.pb.go @@ -0,0 +1,235 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.28.3 +// source: payment.proto + +package proto + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + PaymentService_GetWallet_FullMethodName = "/proto.PaymentService/GetWallet" + PaymentService_GetTransaction_FullMethodName = "/proto.PaymentService/GetTransaction" + PaymentService_MakeTransaction_FullMethodName = "/proto.PaymentService/MakeTransaction" + PaymentService_MakeTransactionWithAccount_FullMethodName = "/proto.PaymentService/MakeTransactionWithAccount" +) + +// PaymentServiceClient is the client API for PaymentService service. +// +// 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 PaymentServiceClient interface { + GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error) + GetTransaction(ctx context.Context, in *GetTransactionRequest, opts ...grpc.CallOption) (*GetTransactionResponse, error) + MakeTransaction(ctx context.Context, in *MakeTransactionRequest, opts ...grpc.CallOption) (*TransactionInfo, error) + MakeTransactionWithAccount(ctx context.Context, in *MakeTransactionWithAccountRequest, opts ...grpc.CallOption) (*TransactionInfo, error) +} + +type paymentServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewPaymentServiceClient(cc grpc.ClientConnInterface) PaymentServiceClient { + return &paymentServiceClient{cc} +} + +func (c *paymentServiceClient) GetWallet(ctx context.Context, in *GetWalletRequest, opts ...grpc.CallOption) (*GetWalletResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetWalletResponse) + err := c.cc.Invoke(ctx, PaymentService_GetWallet_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) GetTransaction(ctx context.Context, in *GetTransactionRequest, opts ...grpc.CallOption) (*GetTransactionResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(GetTransactionResponse) + err := c.cc.Invoke(ctx, PaymentService_GetTransaction_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) MakeTransaction(ctx context.Context, in *MakeTransactionRequest, opts ...grpc.CallOption) (*TransactionInfo, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(TransactionInfo) + err := c.cc.Invoke(ctx, PaymentService_MakeTransaction_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *paymentServiceClient) MakeTransactionWithAccount(ctx context.Context, in *MakeTransactionWithAccountRequest, opts ...grpc.CallOption) (*TransactionInfo, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(TransactionInfo) + err := c.cc.Invoke(ctx, PaymentService_MakeTransactionWithAccount_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// PaymentServiceServer is the server API for PaymentService service. +// All implementations must embed UnimplementedPaymentServiceServer +// for forward compatibility. +type PaymentServiceServer interface { + GetWallet(context.Context, *GetWalletRequest) (*GetWalletResponse, error) + GetTransaction(context.Context, *GetTransactionRequest) (*GetTransactionResponse, error) + MakeTransaction(context.Context, *MakeTransactionRequest) (*TransactionInfo, error) + MakeTransactionWithAccount(context.Context, *MakeTransactionWithAccountRequest) (*TransactionInfo, error) + mustEmbedUnimplementedPaymentServiceServer() +} + +// UnimplementedPaymentServiceServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedPaymentServiceServer struct{} + +func (UnimplementedPaymentServiceServer) GetWallet(context.Context, *GetWalletRequest) (*GetWalletResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetWallet not implemented") +} +func (UnimplementedPaymentServiceServer) GetTransaction(context.Context, *GetTransactionRequest) (*GetTransactionResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetTransaction not implemented") +} +func (UnimplementedPaymentServiceServer) MakeTransaction(context.Context, *MakeTransactionRequest) (*TransactionInfo, error) { + return nil, status.Errorf(codes.Unimplemented, "method MakeTransaction not implemented") +} +func (UnimplementedPaymentServiceServer) MakeTransactionWithAccount(context.Context, *MakeTransactionWithAccountRequest) (*TransactionInfo, error) { + return nil, status.Errorf(codes.Unimplemented, "method MakeTransactionWithAccount not implemented") +} +func (UnimplementedPaymentServiceServer) mustEmbedUnimplementedPaymentServiceServer() {} +func (UnimplementedPaymentServiceServer) testEmbeddedByValue() {} + +// UnsafePaymentServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to PaymentServiceServer will +// result in compilation errors. +type UnsafePaymentServiceServer interface { + mustEmbedUnimplementedPaymentServiceServer() +} + +func RegisterPaymentServiceServer(s grpc.ServiceRegistrar, srv PaymentServiceServer) { + // If the following call pancis, it indicates UnimplementedPaymentServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&PaymentService_ServiceDesc, srv) +} + +func _PaymentService_GetWallet_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetWalletRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).GetWallet(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_GetWallet_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).GetWallet(ctx, req.(*GetWalletRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_GetTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).GetTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_GetTransaction_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).GetTransaction(ctx, req.(*GetTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_MakeTransaction_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MakeTransactionRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).MakeTransaction(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_MakeTransaction_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).MakeTransaction(ctx, req.(*MakeTransactionRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _PaymentService_MakeTransactionWithAccount_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(MakeTransactionWithAccountRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(PaymentServiceServer).MakeTransactionWithAccount(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: PaymentService_MakeTransactionWithAccount_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(PaymentServiceServer).MakeTransactionWithAccount(ctx, req.(*MakeTransactionWithAccountRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// PaymentService_ServiceDesc is the grpc.ServiceDesc for PaymentService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var PaymentService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "proto.PaymentService", + HandlerType: (*PaymentServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "GetWallet", + Handler: _PaymentService_GetWallet_Handler, + }, + { + MethodName: "GetTransaction", + Handler: _PaymentService_GetTransaction_Handler, + }, + { + MethodName: "MakeTransaction", + Handler: _PaymentService_MakeTransaction_Handler, + }, + { + MethodName: "MakeTransactionWithAccount", + Handler: _PaymentService_MakeTransactionWithAccount_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "payment.proto", +}