- A+
所属分类:区块链
每个合约的token_id可以重复,但是在一个合约中token_id不能重复
表结构
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
SET NAMES utf8mb4; SET FOREIGN_KEY_CHECKS = 0; -- ---------------------------- -- Table structure for fc_contract -- ---------------------------- DROP TABLE IF EXISTS `fc_contract`; CREATE TABLE `fc_contract` ( `id` bigint (0) NOT NULL AUTO_INCREMENT COMMENT '表id' , ` name ` varchar (1024) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'nft name' , `symbol` varchar (512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT 'nft symbol' , `address` varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '合约地址' , `type` int (0) NULL DEFAULT NULL COMMENT '类型 3:ERC721 2.ERC1155' , `short_url` varchar (100) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '短地址' , `version` varchar (10) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '合约版本' , `cover` varchar (512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '图标' , `storage_id` bigint (0) NULL DEFAULT NULL COMMENT '图标保存Id' , `owner` varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '合约拥有者' , `is_admin` tinyint(1) NULL DEFAULT 0 COMMENT '是否是官方合约' , `verify` tinyint(1) NULL DEFAULT 0 COMMENT '是否已验证' , `description` varchar (1000) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '合约描述' , `last_token_id` bigint (0) NULL DEFAULT 0 COMMENT '上一次增发的tokenId' , `banner_url` varchar (512) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT '' COMMENT '封面' , `get_info_times` int (0) NULL DEFAULT 0 COMMENT '获取name和symbol次数' , `is_royalties` tinyint(1) NULL DEFAULT NULL COMMENT '是否支持版权' , `signer` varchar (50) CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci NULL DEFAULT NULL COMMENT '签名人账号' , `is_sync` tinyint(1) NULL DEFAULT 0 COMMENT '是否已经同步' , `deleted` tinyint(1) NULL DEFAULT 0 COMMENT '逻辑删除' , `create_time` bigint (0) NULL DEFAULT NULL COMMENT '创建时间' , `update_time` bigint (0) NULL DEFAULT NULL COMMENT '更新时间' , PRIMARY KEY (`id`) USING BTREE, INDEX `index2`(`address`) USING BTREE, INDEX `index3`(`symbol`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 3 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_0900_ai_ci ROW_FORMAT = Dynamic ; SET FOREIGN_KEY_CHECKS = 1; |
代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
@Transactional (rollbackFor = Exception. class ) public List<BigInteger> getTokenId(String address,BigInteger count) { List<BigInteger> tokens= new ArrayList<>(); String tokenId = this .contractExtMapper.getContractWithLock(address); BigInteger start= new BigInteger( "0" ); if ( null == tokenId) { tokenId = count+ "" ; start=start.add(BigInteger.ZERO); } else { start=start.add( new BigInteger(tokenId)); tokenId = new BigInteger(tokenId).add(count).toString(); } BigInteger end=start.add(count); for (BigInteger i=start;(i.compareTo(end)<= 0 );i=i.add(BigInteger.ONE)){ if (i.compareTo(start)== 0 ){ continue ; } tokens.add(i); } this .contractExtMapper.updateLastTokenId(tokenId, address); return tokens; } |
相关方法
1
2
3
4
5
6
|
@Select (value = "select last_token_id from fc_contract where address = #{address} for update" ) String getContractWithLock( @Param ( "address" ) String address); @Update (value = "update fc_contract t set t.last_token_id = #{lastTokenId} where t.address = #{address}" ) Integer updateLastTokenId( @Param ( "lastTokenId" ) String lastTokenId, @Param ( "address" ) String address); |