Commit fd0c287a authored by tangtuo's avatar tangtuo

修改nft上链逻辑

parent dc6d9e09
...@@ -58,7 +58,7 @@ public class Nft extends BaseEntity { ...@@ -58,7 +58,7 @@ public class Nft extends BaseEntity {
private String nftHash; private String nftHash;
@ApiModelProperty("nft token") @ApiModelProperty("nft token")
private String tokenId; private Long tokenId;
@ApiModelProperty("nft发行时间") @ApiModelProperty("nft发行时间")
private Date publishTime; private Date publishTime;
......
...@@ -27,6 +27,7 @@ import com.fzm.common.utils.OssUtil; ...@@ -27,6 +27,7 @@ import com.fzm.common.utils.OssUtil;
import com.fzm.common.utils.RedisUtil; import com.fzm.common.utils.RedisUtil;
import com.github.pagehelper.PageHelper; import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo; import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
...@@ -40,6 +41,7 @@ import java.util.stream.Collectors; ...@@ -40,6 +41,7 @@ import java.util.stream.Collectors;
* @author tangtuo * @author tangtuo
* @date 2021/6/30 15:55 * @date 2021/6/30 15:55
*/ */
@Slf4j
@Service @Service
@Transactional(rollbackFor = RuntimeException.class) @Transactional(rollbackFor = RuntimeException.class)
public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftService { public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftService {
...@@ -73,17 +75,30 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe ...@@ -73,17 +75,30 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
User u = new User().setId(user.getId()).setIsPublish(SystemConstant.BOOLEAN_DATA_TRUE); User u = new User().setId(user.getId()).setIsPublish(SystemConstant.BOOLEAN_DATA_TRUE);
userService.updateById(u); userService.updateById(u);
} }
// 获取用户的私钥 // 获取用户的钱包地址
String wallet = user.getWallet(); String wallet = user.getWallet();
// 获取用户的私钥
String privkey = paraChainClient.walletDumpPrivkey(wallet); String privkey = paraChainClient.walletDumpPrivkey(wallet);
String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true); String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true);
if (StringUtils.isBlank(txHash) || !txHash.contains("-")) { if (StringUtils.isBlank(txHash) || !txHash.contains("-")) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败"); throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
} }
String[] split = txHash.split("-"); String[] split = txHash.split("-");
long tokenId = Long.parseLong(split[1]);
nft.setNftHash(split[0]); nft.setNftHash(split[0]);
nft.setTokenId(split[1]); nft.setTokenId(tokenId);
nft.setPublishTime(new Date()); nft.setPublishTime(new Date());
// 构建上链信息
HashMap<String, String> map = new HashMap<>();
map.put("author", nft.getAuthor());
map.put("name", nft.getName());
map.put("hash", nft.getNftHash());
String tokenInfo = JsonUtil.toJson(map);
log.info("加密上链数据: {}", tokenInfo);
String tradeHash = paraChainClient.evmSetTokenInfo(contractName, tokenId, tokenInfo, wallet, privkey, true);
if (StringUtils.isBlank(tradeHash)) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
}
save(nft); save(nft);
return getById(nft.getId()); return getById(nft.getId());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment