105 lines
2.7 KiB
Go
105 lines
2.7 KiB
Go
package nft
|
|
|
|
import (
|
|
"q5"
|
|
"f5"
|
|
"mt"
|
|
"jccommon"
|
|
"main/constant"
|
|
"strings"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type NftApi struct {
|
|
|
|
}
|
|
|
|
func (this *NftApi) Unlock(c *gin.Context) {
|
|
reqJson := struct {
|
|
NetId interface{} `json:"net_id"`
|
|
ContractAddress string `json:"contract_address"`
|
|
To string `json:"to"`
|
|
Tokens []struct {
|
|
TokenId string `json:"token_id"`
|
|
} `json:"tokens"`
|
|
}{}
|
|
if err := c.ShouldBindJSON(&reqJson); err != nil {
|
|
f5.RspErr(c, 401, "params parse error")
|
|
return
|
|
}
|
|
lockMeta := mt.Table.Contract.GetByName(jccommon.CONTRACT_NAME_NFTLock)
|
|
heroMeta := mt.Table.Contract.GetByName(jccommon.CONTRACT_NAME_CFHero)
|
|
normalHeroMeta := mt.Table.Contract.GetByName(jccommon.CONTRACT_NAME_CFNormalHero)
|
|
if (heroMeta == nil && normalHeroMeta == nil) || lockMeta == nil {
|
|
f5.RspErr(c, 1, "contract_address params error")
|
|
return
|
|
}
|
|
if reqJson.To == "" {
|
|
f5.RspErr(c, 1, "to params error")
|
|
return
|
|
}
|
|
if len(reqJson.Tokens) != 1 {
|
|
f5.RspErr(c, 1, "tokens params error")
|
|
return
|
|
}
|
|
accountAddress := c.MustGet("account_address").(string)
|
|
f5.GetGoStyleDb().OrmSelectOne(
|
|
constant.BCNFT_DB,
|
|
"t_nft",
|
|
[][]string{
|
|
{"net_id", q5.SafeToString(reqJson.NetId)},
|
|
{"contract_address", reqJson.ContractAddress},
|
|
{"token_id", reqJson.Tokens[0].TokenId},
|
|
{"owner_address", strings.ToLower(lockMeta.GetAddress())},
|
|
},
|
|
func (err error, ds *f5.DataSet) {
|
|
if err != nil {
|
|
f5.RspErr(c, 500, "server internal error")
|
|
return
|
|
}
|
|
if ds.Next() {
|
|
if accountAddress != ds.GetByName("last_lock_address") {
|
|
f5.RspErr(c, 500, "nft not found")
|
|
return
|
|
}
|
|
params := map[string]string{
|
|
"c": "BcService",
|
|
"a": "nftUnlock",
|
|
"account_address": accountAddress,
|
|
"net_id": ds.GetByName("net_id"),
|
|
"nft_address": ds.GetByName("contract_address"),
|
|
"to_address": reqJson.To,
|
|
"token_ids": ds.GetByName("token_id"),
|
|
}
|
|
rspObj := &struct {
|
|
ErrCode interface{} `json:"errcode"`
|
|
ErrMsg string `json:"errmsg"`
|
|
TransId string `json:"trans_id"`
|
|
TransReq interface{} `json:"trans_req"`
|
|
}{
|
|
}
|
|
f5.GetHttpCliMgr().SendGoStyleRequest(
|
|
mt.Table.Web3SignCluster.RandElement().GetUrl() + "/webapp/index.php",
|
|
params,
|
|
func(rsp f5.HttpCliResponse) {
|
|
if rsp.GetErr() != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
if q5.DecodeJson(rsp.GetRawData(), &rspObj) != nil {
|
|
rspObj.ErrCode = 500
|
|
rspObj.ErrMsg = "server internal error2"
|
|
c.JSON(200, rspObj)
|
|
return
|
|
}
|
|
c.JSON(200, rspObj)
|
|
})
|
|
} else {
|
|
f5.RspErr(c, 500, "nft not found")
|
|
return
|
|
}
|
|
})
|
|
}
|