Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fzm-joying
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lei
fzm-joying
Commits
2d9bbf38
Commit
2d9bbf38
authored
Jul 23, 2021
by
tangtuo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改nft发行逻辑
parent
84fd3bfc
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
18 deletions
+31
-18
ResultCode.java
...common/src/main/java/com/fzm/common/enums/ResultCode.java
+2
-0
CommemorateNftServiceImpl.java
...om/fzm/common/service/impl/CommemorateNftServiceImpl.java
+10
-6
NftServiceImpl.java
...main/java/com/fzm/common/service/impl/NftServiceImpl.java
+19
-12
No files found.
joying-common/src/main/java/com/fzm/common/enums/ResultCode.java
View file @
2d9bbf38
...
...
@@ -14,6 +14,8 @@ public enum ResultCode implements IErrorCode {
TOKEN_VALID_ERROR
(
413
,
"token校验失败"
),
CODE_ERROR
(
414
,
"验证码发送失败"
),
PUBLISH_ERROR
(
415
,
"nft发行失败"
),
RECEIVE_ERROR
(
416
,
"nft领取失败"
),
TRANSFER_ERROR
(
416
,
"nft转让失败"
),
;
...
...
joying-common/src/main/java/com/fzm/common/service/impl/CommemorateNftServiceImpl.java
View file @
2d9bbf38
...
...
@@ -4,6 +4,7 @@ import cn.fzm.chain.simplesdk.client.ParaChainClient;
import
cn.fzm.chain.simplesdk.constant.TxStatusEnum
;
import
cn.fzm.chain.simplesdk.model.TxResult
;
import
cn.hutool.core.bean.BeanUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.fzm.common.constant.RedisConstant
;
...
...
@@ -78,21 +79,23 @@ public class CommemorateNftServiceImpl extends ServiceImpl<CommemorateNftMapper,
long
tokenId
=
Long
.
parseLong
(
split
[
1
]);
// 构建上链信息
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"
author"
,
user
.
getNickname
());
map
.
put
(
"
publishAddress"
,
user
.
getWallet
());
map
.
put
(
"name"
,
commemorateNft
.
getName
());
map
.
put
(
"author"
,
user
.
getNickname
());
map
.
put
(
"hash"
,
commemorateNft
.
getFileHash
());
String
tokenInfo
=
J
sonUtil
.
toJson
(
map
);
String
tokenInfo
=
J
SONUtil
.
toJsonStr
(
map
);
log
.
info
(
"加密上链数据: {}"
,
tokenInfo
);
String
tradeHash
=
paraChainClient
.
evmSetTokenInfo
(
contractName
,
tokenId
,
tokenInfo
,
wallet
,
privkey
,
true
);
if
(
StringUtils
.
isBlank
(
tradeHash
))
{
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH_ERROR
,
"nft发行失败"
);
}
String
realHash
=
paraChainClient
.
getRealTxHashFromGrp
(
hash
);
// 确认交易结果
TxResult
txResult
=
paraChainClient
.
cycleConfirmTxWithHash
(
hash
,
tru
e
,
1000
);
TxResult
txResult
=
paraChainClient
.
cycleConfirmTxWithHash
(
realHash
,
fals
e
,
1000
);
if
(!
TxStatusEnum
.
SUCCESS
.
equals
(
txResult
.
getStatus
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH_ERROR
,
txResult
.
getErrMsg
().
getValue
());
}
commemorateNft
.
setNftHash
(
h
ash
).
setTokenId
(
tokenId
).
setPublishTime
(
new
Date
());
commemorateNft
.
setNftHash
(
realH
ash
).
setTokenId
(
tokenId
).
setPublishTime
(
new
Date
());
save
(
commemorateNft
);
// 使用nft发行量作为Redisson信号量限制领取次数
RSemaphore
semaphore
=
redisson
.
getSemaphore
(
RedisConstant
.
COMMEMORATE_NFT_PREFIX
+
commemorateNft
.
getId
());
...
...
@@ -131,8 +134,9 @@ public class CommemorateNftServiceImpl extends ServiceImpl<CommemorateNftMapper,
if
(!
TxStatusEnum
.
SUCCESS
.
equals
(
txResult
.
getStatus
()))
{
// 领取失败要释放信号量
semaphore
.
release
();
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH
_ERROR
,
txResult
.
getErrMsg
().
getValue
());
throw
GlobalException
.
newException
(
ResultCode
.
RECEIVE
_ERROR
,
txResult
.
getErrMsg
().
getValue
());
}
String
realHash
=
paraChainClient
.
getRealTxHashFromGrp
(
hash
);
Nft
nft
=
new
Nft
();
BeanUtil
.
copyProperties
(
commemorateNft
,
nft
,
true
);
// 获取当前用户领取nft的领取顺序编号
...
...
@@ -140,7 +144,7 @@ public class CommemorateNftServiceImpl extends ServiceImpl<CommemorateNftMapper,
// nft编号为BJIFF11+5为顺序编号 : BJIFF1100123
String
code
=
"00000"
+
availablePermits
;
nft
.
setNftId
(
"BJIFF11"
+
code
.
substring
(
code
.
length
()
-
5
));
nft
.
setTransferHash
(
h
ash
);
nft
.
setTransferHash
(
realH
ash
);
nft
.
setUserId
(
user
.
getId
());
nft
.
setCreateDate
(
new
Date
());
nft
.
setUpdateDate
(
new
Date
());
...
...
joying-common/src/main/java/com/fzm/common/service/impl/NftServiceImpl.java
View file @
2d9bbf38
...
...
@@ -7,6 +7,7 @@ import cn.hutool.core.collection.CollectionUtil;
import
cn.hutool.core.date.DateTime
;
import
cn.hutool.core.date.DateUtil
;
import
cn.hutool.core.util.RandomUtil
;
import
cn.hutool.json.JSONUtil
;
import
com.baomidou.mybatisplus.core.conditions.query.QueryWrapper
;
import
com.baomidou.mybatisplus.extension.service.impl.ServiceImpl
;
import
com.fzm.common.constant.RedisConstant
;
...
...
@@ -103,31 +104,33 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
// 获取用户的私钥
String
privkey
=
paraChainClient
.
walletDumpPrivkey
(
wallet
);
// 发行nft
String
txHash
=
paraChainClient
.
evmPublishNFT1155
(
contractName
,
wallet
,
privkey
,
3
,
true
);
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
(
"-"
);
String
hash
=
split
[
0
];
long
tokenId
=
Long
.
parseLong
(
split
[
1
]);
String
realHash
=
paraChainClient
.
getRealTxHashFromGrp
(
hash
);
Nft
nft
=
getById
(
nftDto
.
getId
());
// 构建上链信息
HashMap
<
String
,
String
>
map
=
new
HashMap
<>();
map
.
put
(
"author"
,
nft
.
getAuthor
());
map
.
put
(
"name"
,
nft
.
getName
());
map
.
put
(
"hash"
,
nft
.
getFileHash
());
String
tokenInfo
=
JsonUtil
.
toJson
(
map
);
map
.
put
(
"publishAddress"
,
nft
.
getPublishAddress
());
String
tokenInfo
=
JSONUtil
.
toJsonStr
(
map
);
log
.
info
(
"加密上链数据: {}"
,
tokenInfo
);
String
tradeHash
=
paraChainClient
.
evmSetTokenInfo
(
contractName
,
tokenId
,
tokenInfo
,
wallet
,
privkey
,
true
);
if
(
StringUtils
.
isBlank
(
tradeHash
))
{
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH_ERROR
,
"nft发行失败"
);
}
// 确认交易结果
TxResult
txResult
=
paraChainClient
.
cycleConfirmTxWithHash
(
hash
,
tru
e
,
1000
);
TxResult
txResult
=
paraChainClient
.
cycleConfirmTxWithHash
(
realHash
,
fals
e
,
1000
);
if
(!
TxStatusEnum
.
SUCCESS
.
equals
(
txResult
.
getStatus
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH_ERROR
,
txResult
.
getErrMsg
().
getValue
());
}
nft
.
setNftHash
(
h
ash
);
nft
.
setNftHash
(
realH
ash
);
nft
.
setTokenId
(
tokenId
);
nft
.
setPublishTime
(
new
Date
());
nft
.
setNftId
(
nftDto
.
getNftId
());
...
...
@@ -151,43 +154,47 @@ public class NftServiceImpl extends ServiceImpl<NftMapper, Nft> implements NftSe
// 转出人的个人信息
User
user
=
userService
.
getUserByToken
();
if
(!
nft
.
getUserId
().
equals
(
user
.
getId
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
FORBIDDEN
,
"您无权转让他人的nft"
);
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
"您无权转让他人的nft"
);
}
// 校验短信验证码
// todo 现在用的是登录验证码模板,后续需要修改短信模板
if
(!
smsUtil
.
validateCode
(
smsProperties
.
getMessageLoginCodetype
(),
user
.
getTelephone
(),
param
.
getCode
(),
param
.
getCodeType
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
FAILED
,
"短信验证码校验失败"
);
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
"短信验证码校验失败"
);
}
// 校验接收人的个人信息
User
receiveUser
=
userService
.
getUserByWallet
(
param
.
getReceiveWallet
());
if
(
receiveUser
==
null
)
{
throw
GlobalException
.
newException
(
ResultCode
.
FAILED
,
"接手人非本系统注册用户,暂不支持转让"
);
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
"接手人非本系统注册用户,暂不支持转让"
);
}
// 不能自己向自己转让nft
if
(
user
.
getWallet
().
equals
(
receiveUser
.
getWallet
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
FAILED
,
"不能向自己转让nft"
);
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
"不能向自己转让nft"
);
}
// 转让nft
String
hash
=
paraChainClient
.
evmTransferNFT1155
(
contractName
,
user
.
getWallet
(),
null
,
param
.
getReceiveWallet
(),
nft
.
getTokenId
(),
param
.
getCount
(),
true
);
if
(
StringUtils
.
isBlank
(
hash
))
{
throw
GlobalException
.
newException
(
ResultCode
.
FAILED
,
"nft领取失败"
);
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
"nft领取失败"
);
}
// 确认转让结果
TxResult
txResult
=
paraChainClient
.
cycleConfirmTxWithHash
(
hash
,
true
,
1000
);
if
(!
TxStatusEnum
.
SUCCESS
.
equals
(
txResult
.
getStatus
()))
{
throw
GlobalException
.
newException
(
ResultCode
.
PUBLISH_ERROR
,
txResult
.
getErrMsg
().
getValue
());
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
,
txResult
.
getErrMsg
().
getValue
());
}
String
realHash
=
paraChainClient
.
getRealTxHashFromGrp
(
hash
);
if
(
StringUtils
.
isBlank
(
realHash
))
{
throw
GlobalException
.
newException
(
ResultCode
.
TRANSFER_ERROR
);
}
// 修改nft的拥有者用户id
Nft
transferNft
=
new
Nft
().
setUserId
(
receiveUser
.
getId
()).
setTransferHash
(
h
ash
);
setTransferHash
(
realH
ash
);
transferNft
.
setId
(
nft
.
getId
());
updateById
(
transferNft
);
// 保存nft的转让记录
NftTransferRecord
record
=
new
NftTransferRecord
();
record
.
setNftId
(
nft
.
getId
()).
setNftHash
(
nft
.
getNftHash
()).
setTransferHash
(
h
ash
).
setTransferHash
(
realH
ash
).
setFromAddress
(
user
.
getWallet
()).
setToAddress
(
receiveUser
.
getWallet
());
nftTransferRecordService
.
save
(
record
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment