app-cloudep-trade-service/internal/repository/user_wallet.go

42 lines
1.1 KiB
Go

package repository
import (
"app-cloudep-trade-service/internal/domain"
"app-cloudep-trade-service/internal/domain/repository"
"app-cloudep-trade-service/internal/model"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/shopspring/decimal"
)
// 用戶某個幣種餘額
type userLocalWallet struct {
wm model.WalletModel
txConn sqlx.SqlConn
uid string
crypto string
// local wallet 相關計算的餘額存在這裡
walletBalance map[domain.WalletType]model.Wallet
// local order wallet 相關計算的餘額存在這裡
localOrderBalance map[int64]decimal.Decimal
// local wallet 內所有餘額變化紀錄
transactions []model.WalletJournal
}
func NewUserWalletOperator(uid, crypto string, wm model.WalletModel, txConn sqlx.SqlConn) repository.UserWalletOperator {
return &userLocalWallet{
wm: wm,
txConn: txConn,
uid: uid,
crypto: crypto,
walletBalance: make(map[domain.WalletType]model.Wallet, len(domain.AllWalletType)),
localOrderBalance: make(map[int64]decimal.Decimal, len(domain.AllWalletType)),
}
}