Commit fd0c287a authored by tangtuo's avatar tangtuo

修改nft上链逻辑

parent dc6d9e09
......@@ -58,7 +58,7 @@ public class Nft extends BaseEntity {
private String nftHash;
@ApiModelProperty("nft token")
private String tokenId;
private Long tokenId;
@ApiModelProperty("nft发行时间")
private Date publishTime;
......
......@@ -27,6 +27,7 @@ import com.fzm.common.utils.OssUtil;
import com.fzm.common.utils.RedisUtil;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
......@@ -40,6 +41,7 @@ import java.util.stream.Collectors;
* @author tangtuo
* @date 2021/6/30 15:55
*/
@Slf4j
@Service
@Transactional(rollbackFor = RuntimeException.class)
public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftService {
......@@ -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);
userService.updateById(u);
}
// 获取用户的私钥
// 获取用户的钱包地址
String wallet = user.getWallet();
// 获取用户的私钥
String privkey = paraChainClient.walletDumpPrivkey(wallet);
String txHash = paraChainClient.evmPublishNFT1155(contractName, wallet, privkey, 1, true);
if (StringUtils.isBlank(txHash) || !txHash.contains("-")) {
throw GlobalException.newException(ResultCode.FAILED, "nft发行失败");
}
String[] split = txHash.split("-");
long tokenId = Long.parseLong(split[1]);
nft.setNftHash(split[0]);
nft.setTokenId(split[1]);
nft.setTokenId(tokenId);
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);
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