80 lines
2.1 KiB
Go
80 lines
2.1 KiB
Go
package spec_transfer721
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"fmt"
|
|
"mt"
|
|
"jccommon"
|
|
"main/constant"
|
|
"math/rand"
|
|
)
|
|
|
|
type SpecTransfer721 struct {
|
|
handleHash *q5.ConcurrentMap[string, specTransfer721Handle]
|
|
}
|
|
|
|
func (this* SpecTransfer721) Init() {
|
|
this.handleHash = new(q5.ConcurrentMap[string, specTransfer721Handle])
|
|
this.handleHash.Store(jccommon.CONTRACT_NAME_CFHero, newHero())
|
|
this.handleHash.Store(jccommon.CONTRACT_NAME_GoldBrick, newGoldBullion())
|
|
go this.process()
|
|
}
|
|
|
|
func (this* SpecTransfer721) UnInit() {
|
|
}
|
|
|
|
func (this* SpecTransfer721) process() {
|
|
f5.GetGoStyleDb().LoopLoad(
|
|
constant.BCEVENT_DB,
|
|
"t_721nft_spec_transfer",
|
|
"t_721nft_spec_transfer",
|
|
func () int64 {
|
|
return 3 + q5.ToInt64(rand.Intn(2))
|
|
},
|
|
func (lastIdx int64) string {
|
|
nowTime := f5.GetApp().GetRealSeconds()
|
|
expiredTime := nowTime - 3600 * 24 * 7
|
|
sql := fmt.Sprintf(`
|
|
SELECT * FROM t_721nft_spec_transfer WHERE idx > %d AND status = 0 AND createtime > %d LIMIT 1000
|
|
`,
|
|
lastIdx,
|
|
expiredTime)
|
|
return sql
|
|
},
|
|
[]string{
|
|
},
|
|
func () int64{
|
|
return 3
|
|
},
|
|
func () int64 {
|
|
return 60 * 1
|
|
},
|
|
this.dispatch)
|
|
}
|
|
|
|
func (this* SpecTransfer721) dispatch(ds *f5.DataSet) bool {
|
|
idx := q5.ToInt64(ds.GetByName("idx"))
|
|
netId := q5.ToInt32(ds.GetByName("net_id"))
|
|
contractAddress := ds.GetByName("contract_address")
|
|
tokenId := ds.GetByName("token_id")
|
|
fromAddress := ds.GetByName("from_address")
|
|
toAddress := ds.GetByName("to_address")
|
|
contractMeta := mt.Table.Contract.GetByNetIdAddress(netId, contractAddress)
|
|
nftLockMeta := mt.Table.Contract.GetByNetIdName(netId, jccommon.CONTRACT_NAME_NFTLock)
|
|
if contractMeta != nil {
|
|
if p, ok := this.handleHash.Load(contractMeta.GetName()); ok {
|
|
if q5.IsWeb3ZeroAddress(fromAddress) {
|
|
return (*p).onMint(idx, netId, contractAddress, tokenId, fromAddress, toAddress)
|
|
} else if nftLockMeta != nil {
|
|
if toAddress == nftLockMeta.GetAddress() {
|
|
return (*p).onLock(idx, netId, contractAddress, tokenId, fromAddress, toAddress)
|
|
} else if fromAddress == nftLockMeta.GetAddress() {
|
|
return (*p).onUnlock(idx, netId, contractAddress, tokenId, fromAddress, toAddress)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return false
|
|
}
|