nft质押任务逻辑
This commit is contained in:
@@ -2,6 +2,7 @@ package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"nova_task/internal/pkg/aptos"
|
||||
@@ -15,7 +16,8 @@ type (
|
||||
NhWalletModel interface {
|
||||
nhWalletModel
|
||||
withSession(session sqlx.Session) NhWalletModel
|
||||
FindWalletByAddress(ctx context.Context, address string) (uint, error)
|
||||
FindUidByAddress(ctx context.Context, address string) (uint, error)
|
||||
FindAddressByUid(ctx context.Context, uid uint) (string, error)
|
||||
}
|
||||
|
||||
customNhWalletModel struct {
|
||||
@@ -23,10 +25,23 @@ type (
|
||||
}
|
||||
)
|
||||
|
||||
func (m *customNhWalletModel) FindWalletByAddress(ctx context.Context, address string) (uint, error) {
|
||||
func (m *customNhWalletModel) FindAddressByUid(ctx context.Context, uid uint) (string, error) {
|
||||
query := fmt.Sprintf("select `address` from %s where `uid` = ? and `status` = 0 limit 1", m.table)
|
||||
var address string
|
||||
err := m.conn.QueryRowCtx(ctx, &address, query, uid)
|
||||
if errors.Is(err, sqlx.ErrNotFound) {
|
||||
return "", ErrNotFound
|
||||
}
|
||||
return address, err
|
||||
}
|
||||
|
||||
func (m *customNhWalletModel) FindUidByAddress(ctx context.Context, address string) (uint, error) {
|
||||
query := fmt.Sprintf("select `uid` from %s where `address` = ? or `address` = ? limit 1", m.table)
|
||||
var uid uint
|
||||
err := m.conn.QueryRowCtx(ctx, &uid, query, address, aptos.StrPadAptosAddress(address))
|
||||
if errors.Is(err, sqlx.ErrNotFound) {
|
||||
return 0, ErrNotFound
|
||||
}
|
||||
return uid, err
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user