You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

164 lines
3.7 KiB

package biz
import (
"context"
"github.com/go-kratos/kratos/v2/log"
)
// Wallet
// @Description:
type Wallet struct {
From string `json:"from,omitempty"` // 转账地址
To string `json:"to,omitempty"` // 接收地址
Amount uint32 `json:"amount,omitempty"` // 转账金额
Contract string `json:"contract,omitempty"` // 合约地址(Trc20签名传入,其他签名不用传)
TrcCheck string `json:"trc_check,omitempty"` // 签名钱包标识
TokenId string `json:"token_id,omitempty"` // Trc10签名传入,其他签名不用传
FeeLimit uint32 `json:"fee_limit,omitempty"` // 限制交易费
}
// WalletRepo
// @Description:
type WalletRepo interface {
GenerateAddress(context.Context, string, uint32) ([]string, error)
SignatureTrc20Grpc(context.Context, *Wallet) (bool, string, error)
WalletApprove(ctx context.Context, wallet *Wallet) (bool, []byte, error)
GetAllAddress(context.Context) ([]string, error)
GetAllAddressAndPrivateKey(context.Context) (map[string][]byte, error)
GetPrivateKeyByAddress(context.Context, string) (string, error)
DeleteAddress(context.Context) error
}
// WalletInfo
// @Description:
type WalletInfo struct {
repo WalletRepo
log *log.Helper
}
// NewWalletInfo new a Wallet Info.
//
// @Description:
// @param repo
// @param logger
// @return *WalletInfo
func NewWalletInfo(repo WalletRepo, logger log.Logger) *WalletInfo {
return &WalletInfo{repo: repo, log: log.NewHelper(logger)}
}
// GenerateAddress .
//
// @Description:
// @receiver w
// @param ctx
// @param wallet
// @param number
// @return []string
// @return error
func (w *WalletInfo) GenerateAddress(ctx context.Context, wallet string, number uint32) ([]string, error) {
data, err := w.repo.GenerateAddress(ctx, wallet, number)
if err != nil {
return nil, err
}
return data, nil
}
// SignatureTrc20Grpc .
//
// @Description:
// @receiver w
// @param ctx
// @param wallet
// @return bool
// @return string
// @return error
func (w *WalletInfo) SignatureTrc20Grpc(ctx context.Context, wallet *Wallet) (bool, string, error) {
check, data, err := w.repo.SignatureTrc20Grpc(ctx, wallet)
if err != nil {
return false, "", err
}
return check, data, nil
}
// WalletApprove .
//
// @Description:
// @receiver w
// @param ctx
// @param wallet
// @return bool
// @return []byte
// @return error
func (w *WalletInfo) WalletApprove(ctx context.Context, wallet *Wallet) (bool, []byte, error) {
check, tx, err := w.WalletApprove(ctx, wallet)
if err != nil {
return check, []byte{}, nil
}
return check, tx, nil
}
// GetAllAddress .
//
// @Description:
// @receiver w
// @param ctx
// @return []string
// @return error
func (w *WalletInfo) GetAllAddress(ctx context.Context) ([]string, error) {
data, err := w.repo.GetAllAddress(ctx)
if err != nil {
return nil, err
}
return data, nil
}
// GetAllAddressAndPrivateKey .
//
// @Description:
// @receiver w
// @param ctx
// @return map[string][]byte
// @return error
func (w *WalletInfo) GetAllAddressAndPrivateKey(ctx context.Context) (map[string][]byte, error) {
data, err := w.repo.GetAllAddressAndPrivateKey(ctx)
if err != nil {
return nil, err
}
return data, nil
}
// GetPrivateKeyByAddress .
//
// @Description:
// @receiver w
// @param ctx
// @param address
// @return string
// @return error
func (w *WalletInfo) GetPrivateKeyByAddress(ctx context.Context, address string) (string, error) {
data, err := w.repo.GetPrivateKeyByAddress(ctx, address)
if err != nil {
return "", err
}
return data, nil
}
// DeleteAddress .
//
// @Description:
// @receiver w
// @param ctx
// @return error
func (w *WalletInfo) DeleteAddress(ctx context.Context) error {
if err := w.repo.DeleteAddress(ctx); err != nil {
return err
}
return nil
}