biz

package
v0.0.0-...-5b7c39b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 5, 2024 License: MIT Imports: 12 Imported by: 0

README

Biz

Documentation

Index

Constants

View Source
const (
	QUEUE_PREFIX      = "ico-subround:"
	ENDROUND_SCHEDULE = "endround"
)

Variables

View Source
var (
	SUBSCRIPTION     = "SUBSCRIPTION"
	CHARGE_FEE       = "CHARGE_FEE"
	REFERRAL_REWARD  = "REFERRAL_REWARD"
	MarketingReward  = "MARKETING_REWARD"
	ICO              = "ICO"
	ICO_COMISSION    = "ICO_COMISSION"
	ICO_CASHBACK     = "ICO_CASHBACK"
	DEPOSITE         = "DEPOSITE"
	TRANS_STATUS     = "COMPLETED"
	CURRENCY_SUPPORT = []string{"VND", "USD", "USDT"}
)

ProviderSet is biz providers.

Functions

This section is empty.

Types

type CurrencyRate

type CurrencyRate struct {
	Symbol string
	Rate   string
}

type CurrencyRateRepo

type CurrencyRateRepo interface {
	Tx
	GetCurrencyRate(ctx context.Context, symbol string) (*CurrencyRate, error)
	UpdateCurrencyRateICO(ctx context.Context, rate string) error
	InitData(ctx context.Context) error
}

type ICOHistory

type ICOHistory struct {
	ID       xid.ID
	RoundId  int32
	SubRound int32
	UserId   string
	Price    string
	NumToken string
	Type     string
}

type ICORepo

type ICORepo interface {
	Tx
	GetRounds(context.Context) ([]*ICORound, error)
	EndRoundByRoundId(ctx context.Context, roundId int32) error
	GetRoundByRoundId(ctx context.Context, roundId int32) (*ICORound, error)
	SaveHistories(ctx context.Context, histories []ICOHistory) error

	GetCurrentSubRound(context.Context) (*ICOSubRound, error)
	CloseSubRound(ctx context.Context, roundId, subRound int32, boughtToken string) (*ICOSubRound, error)
	UpdateSubRoundBought(ctx context.Context, roundId, subRound int32, boughtToken string) error
	GetSubRoundById(ctx context.Context, id string) (*ICOSubRound, error)

	InitData(ctx context.Context, startTime time.Time) error
	GetBuyICOUser(ctx context.Context, limit, offset int) ([]*ICOUserBought, error)
	GetBuyICOTotalUser(ctx context.Context) (int, error)
}

type ICORound

type ICORound struct {
	ID        xid.ID
	RoundId   int32
	RoundName string
	Price     string
	NumToken  string
	PriceGap  string
	NumSub    int32
	EndedAt   *time.Time
}

type ICOSubRound

type ICOSubRound struct {
	ID          xid.ID
	RoundId     int32
	RoundName   string
	SubRound    int32
	Price       string
	BoughtToken string
	TotalToken  string
	EndAt       time.Time
	IsEnded     bool
}

type ICOUsecase

type ICOUsecase struct {
	// contains filtered or unexported fields
}

func NewICOUseCase

func NewICOUseCase(repo ICORepo, icoCoupon IcoCouponRepo, currencyRateRepo CurrencyRateRepo) *ICOUsecase

func (*ICOUsecase) AddICOCoupon

func (uc *ICOUsecase) AddICOCoupon(ctx context.Context, userId, coupon, reward, cashback string) error

func (*ICOUsecase) CloseSubRound

func (uc *ICOUsecase) CloseSubRound(ctx context.Context, currentRound *ICOSubRound) error

func (*ICOUsecase) GetICOCoupon

func (uc *ICOUsecase) GetICOCoupon(ctx context.Context, coupon string) (*IcoCoupon, error)

func (*ICOUsecase) GetICOCurrentRound

func (uc *ICOUsecase) GetICOCurrentRound(ctx context.Context) (*ICOSubRound, error)

func (*ICOUsecase) GetICORounds

func (uc *ICOUsecase) GetICORounds(ctx context.Context) ([]*ICORound, error)

func (*ICOUsecase) GetICOUserHistory

func (uc *ICOUsecase) GetICOUserHistory(ctx context.Context, next string, limit int) ([]*ICOUserBought, int, error)

func (*ICOUsecase) ICOHistories

func (uc *ICOUsecase) ICOHistories(ctx context.Context, userId, amount, symbol, icoType string) (decimal.Decimal, error)

func (*ICOUsecase) UpdateCurrencyRateICO

func (uc *ICOUsecase) UpdateCurrencyRateICO(ctx context.Context, oldPrice, newPrice string) error

type ICOUserBought

type ICOUserBought struct {
	Rank     int
	UserId   string
	NumToken string
}

type IcoCoupon

type IcoCoupon struct {
	ID xid.ID `json:"id,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// UserID holds the value of the "user_id" field.
	UserID string `json:"user_id,omitempty"`
	// Coupon holds the value of the "coupon" field.
	Coupon string `json:"coupon,omitempty"`
	// Reward holds the value of the "reward" field.
	Reward string `json:"reward,omitempty"`
	// Cashback holds the value of the "cashback" field.
	Cashback string `json:"cashback,omitempty"`
}

IcoCoupon is the model entity for the IcoCoupon schema.

type IcoCouponRepo

type IcoCouponRepo interface {
	GetCoupon(ctx context.Context, coupon string) (*IcoCoupon, error)
	AddCoupon(ctx context.Context, icoCoupon *IcoCoupon) error
}

type LockRepo

type LockRepo interface {
	Lock(ctx context.Context, key string) error
	UnLock(ctx context.Context, key string) error
}

type QueueJob

type QueueJob interface {
	Enqueue(ctx context.Context, task *Task) error
	Execute(ctx context.Context, task *Task) error
	Start(ctx context.Context) error
	Stop(ctx context.Context) error
}

type QueueRunner

type QueueRunner struct {
	// contains filtered or unexported fields
}

func NewQueueRunner

func NewQueueRunner(repo ICORepo, walletRepo UserWalletRepo, transRepo TransactionRepo, icoUc *ICOUsecase, lockRepo LockRepo) *QueueRunner

func (*QueueRunner) Execute

func (q *QueueRunner) Execute(ctx context.Context, task *Task) error

func (*QueueRunner) GetICOCurrentRound

func (r *QueueRunner) GetICOCurrentRound(ctx context.Context) (*ICOSubRound, error)

type Task

type Task struct {
	ID        string
	Data      string
	Name      string
	ProcessAt time.Time
}

type Transaction

type Transaction struct {
	ID xid.ID `json:"id,omitempty"`
	// CreatedAt holds the value of the "created_at" field.
	CreatedAt time.Time `json:"created_at,omitempty"`
	// UpdatedAt holds the value of the "updated_at" field.
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	// TransType holds the value of the "trans_type" field.
	TransType string `json:"trans_type,omitempty"`
	// Source holds the value of the "source" field.
	Source string `json:"source,omitempty"`
	// SrcSymbol holds the value of the "src_symbol" field.
	SrcSymbol string `json:"src_symbol,omitempty"`
	// SrcAmount holds the value of the "src_amount" field.
	SrcAmount string `json:"src_amount,omitempty"`
	// Destination holds the value of the "destination" field.
	Destination string `json:"destination,omitempty"`
	// DestSymbol holds the value of the "dest_symbol" field.
	DestSymbol string `json:"dest_symbol,omitempty"`
	// DestAmount holds the value of the "dest_amount" field.
	DestAmount string `json:"dest_amount,omitempty"`
	// Rate holds the value of the "rate" field.
	Rate string `json:"rate,omitempty"`
	// SourceService holds the value of the "source_service" field.
	SourceService string `json:"source_service,omitempty"`
	SourceId      string `json:"source_id,omitempty"`
	// Status holds the value of the "status" field.
	Status string `json:"status,omitempty"`
}

type TransactionMessage

type TransactionMessage struct {
	Id        string `json:"id"`
	UserId    string `json:"user_id"`
	Amount    string `json:"amount"`
	Symbol    string `json:"symbol"`
	TransType string `json:"type"`
}

type TransactionPublisher

type TransactionPublisher interface {
	Publish(msg *TransactionMessage)
}

type TransactionRepo

type TransactionRepo interface {
	Tx
	CreateTransaction(ctx context.Context, input *Transaction) (*Transaction, error)
	GetTransactionsByUserId(ctx context.Context, userId, cursor string, limit int32) ([]*Transaction, string, error)
}

type Tx

type Tx interface {
	WithTx(ctx context.Context, fn func(ctx context.Context) error) error
}

type UserWallet

type UserWallet struct {
	ID        xid.ID    `json:"id,omitempty"`
	CreatedAt time.Time `json:"created_at,omitempty"`
	UpdatedAt time.Time `json:"updated_at,omitempty"`
	UserID    string    `json:"user_id,omitempty"`
	Type      string    `json:"type,omitempty"`
	Symbol    string    `json:"symbol,omitempty"`
	Balance   string    `json:"balance,omitempty"`

	IsActive bool `json:"is_active,omitempty"`
}

type UserWalletRepo

type UserWalletRepo interface {
	Tx
	GetWalletByUserId(ctx context.Context, userId, symbol, walletType string) ([]*UserWallet, error)
	CreateWallet(ctx context.Context, userId, symbol, walletType string) (*UserWallet, error)
	DecreaseBalance(ctx context.Context, userId, symbol, amount, walletType string) (int, error)
	IncreaseBalance(ctx context.Context, userId, symbol, amount, walletType string) (int, error)
	InitData(ctx context.Context) error
	CalculateBalance(ctx context.Context, userId, amount, symbol string) (bool, error)
}

type WalletTransactionUseCase

type WalletTransactionUseCase struct {
	// contains filtered or unexported fields
}

func NewWalletTransactionUseCase

func NewWalletTransactionUseCase(repo TransactionRepo, walletRepo UserWalletRepo, icoRepo ICORepo, currencyRateRepo CurrencyRateRepo, icoCoupon IcoCouponRepo, queue QueueJob, publisher TransactionPublisher, icoUc *ICOUsecase, lockRepo LockRepo) *WalletTransactionUseCase

func (*WalletTransactionUseCase) BuyICO

func (uc *WalletTransactionUseCase) BuyICO(ctx context.Context, userId, amount, symbol, sourceId, couponCode string) error

func (*WalletTransactionUseCase) CalcChargeFee

func (*WalletTransactionUseCase) ChargeFee

func (uc *WalletTransactionUseCase) ChargeFee(ctx context.Context, userId, amount, symbol, sourceId, typeFee string) (string, error)

func (*WalletTransactionUseCase) CreateTransaction

func (uc *WalletTransactionUseCase) CreateTransaction(ctx context.Context, trans *Transaction) (*Transaction, error)

func (*WalletTransactionUseCase) DepositICO

func (uc *WalletTransactionUseCase) DepositICO(ctx context.Context, userId, amount, symbol, sourceId, icoType string) error

func (*WalletTransactionUseCase) GetCurrentRate

func (*WalletTransactionUseCase) GetTransactionsByUserId

func (uc *WalletTransactionUseCase) GetTransactionsByUserId(ctx context.Context, userId, nextCursor string, limit int32) ([]*Transaction, string, error)

func (*WalletTransactionUseCase) GetUserWallet

func (uc *WalletTransactionUseCase) GetUserWallet(ctx context.Context, userId string) ([]*UserWallet, error)

func (*WalletTransactionUseCase) GetUserWalletOrCreateWithSymbol

func (uc *WalletTransactionUseCase) GetUserWalletOrCreateWithSymbol(ctx context.Context, userId, symbol, walletType string) ([]*UserWallet, error)

func (*WalletTransactionUseCase) GetUserWalletWithSymbol

func (uc *WalletTransactionUseCase) GetUserWalletWithSymbol(ctx context.Context, userId, symbol string) ([]*UserWallet, error)

func (*WalletTransactionUseCase) ICOTransaction

func (uc *WalletTransactionUseCase) ICOTransaction(ctx context.Context, userId, amount, symbol, sourceId, transType, icoType string) error

func (*WalletTransactionUseCase) InitData

func (uc *WalletTransactionUseCase) InitData(ctx context.Context)

func (*WalletTransactionUseCase) MarketingRewardInternal

func (uc *WalletTransactionUseCase) MarketingRewardInternal(ctx context.Context, userID, amount, symbol, sourceID string) (string, error)

MarketingRewardInternal is used to increase balance for user with symbol and amount

func (*WalletTransactionUseCase) ReferralReward

func (uc *WalletTransactionUseCase) ReferralReward(ctx context.Context, userId, amount, symbol, sourceId string) error

func (*WalletTransactionUseCase) Subscription

func (uc *WalletTransactionUseCase) Subscription(ctx context.Context, userId, amount, symbol, sourceId string) error

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳