Payment related grpc method

This commit is contained in:
2025-01-26 19:51:35 +08:00
parent fcf1e61d4a
commit 4f38d4291f
7 changed files with 1108 additions and 0 deletions

View File

@ -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
}

View File

@ -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),
}
}