86 lines
2.2 KiB
Go
86 lines
2.2 KiB
Go
package spec_transfer721
|
|
|
|
import (
|
|
"q5"
|
|
"main/service"
|
|
"main/constant"
|
|
"mt"
|
|
"jccommon"
|
|
"fmt"
|
|
)
|
|
|
|
type hero struct {
|
|
mailCfgHash *q5.ConcurrentMap[string, *jccommon.MailConfig]
|
|
}
|
|
|
|
func (this* hero) onMint(dbIdx int64, netId int32, contractAddress string, tokenId string,
|
|
from string, to string) bool {
|
|
ok := this.internalSendMail(dbIdx, to, constant.MAIL_HERO_MINT, tokenId)
|
|
return ok
|
|
}
|
|
|
|
func (this* hero) onLock(dbIdx int64, netId int32, contractAddress string, tokenId string,
|
|
from string, to string) bool {
|
|
ok := this.internalSendMail(dbIdx, from, constant.MAIL_HERO_LOCK, tokenId)
|
|
return ok
|
|
}
|
|
|
|
func (this *hero) onUnlock(dbIdx int64, netId int32, contractAddress string, tokenId string,
|
|
from string, to string) bool {
|
|
ok := this.internalSendMail(dbIdx, to, constant.MAIL_HERO_UNLOCK, tokenId)
|
|
return ok
|
|
}
|
|
|
|
func (this* hero) internalSendMail(dbIdx int64, accountAddress string, mailName string, tokenId string) bool {
|
|
var itemId, heroQuality int32
|
|
if !service.GetHeroByTokenId(tokenId, &itemId, &heroQuality) {
|
|
return true
|
|
}
|
|
itemMeta := mt.Table.Item.GetById(q5.ToInt64(itemId))
|
|
if itemMeta == nil {
|
|
return true
|
|
}
|
|
accountId := service.GetAccountIdByAddress(accountAddress)
|
|
if accountId == "" {
|
|
return true
|
|
}
|
|
mailMeta := mt.Table.Mail.GetByName(mailName)
|
|
if mailMeta == nil {
|
|
return true
|
|
}
|
|
mailCfg := this.getMailConfig(mailName)
|
|
if mailCfg == nil {
|
|
return true
|
|
}
|
|
uniKey := fmt.Sprintf("%d_%s_%s", dbIdx, mailName, tokenId)
|
|
if uniKey != "" {
|
|
|
|
}
|
|
return true
|
|
}
|
|
|
|
func (this *hero) getMailConfig(mailName string) *jccommon.MailConfig {
|
|
if v, ok := this.mailCfgHash.Load(mailName); ok {
|
|
return *v
|
|
} else {
|
|
return nil
|
|
}
|
|
}
|
|
|
|
func (this *hero) registerMailConfig(mailName string, tag1 int32, tag2 int32) {
|
|
p := new(jccommon.MailConfig)
|
|
p.MailName = mailName
|
|
p.Tag1 = tag1
|
|
p.Tag2 = tag2
|
|
this.mailCfgHash.Store(mailName, p)
|
|
}
|
|
|
|
func newHero() *hero {
|
|
p := new(hero)
|
|
p.mailCfgHash = new(q5.ConcurrentMap[string, *jccommon.MailConfig])
|
|
p.registerMailConfig(constant.MAIL_HERO_MINT, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_MINT)
|
|
p.registerMailConfig(constant.MAIL_HERO_LOCK, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_LOCK)
|
|
p.registerMailConfig(constant.MAIL_HERO_UNLOCK, jccommon.MAIL_TAG1_HERO, jccommon.MAIL_TAG2_HERO_UNLOCK)
|
|
return p
|
|
}
|