xiongzhu 4 năm trước cách đây
mục cha
commit
9c12d7ec3f

+ 2 - 0
src/main/java/com/izouma/nineth/domain/IdentityAuth.java

@@ -26,10 +26,12 @@ public class IdentityAuth extends BaseEntity {
     @Searchable
     private String realName;
 
+    @Searchable
     private String phone;
 
     private String email;
 
+    @Searchable
     private String idNo;
 
     private String idFront;

+ 17 - 3
src/test/java/com/izouma/nineth/CommonTest.java

@@ -5,7 +5,6 @@ import com.izouma.nineth.config.Constants;
 import com.izouma.nineth.domain.BaseEntity;
 import com.izouma.nineth.domain.BlindBoxItem;
 import com.izouma.nineth.domain.User;
-import com.izouma.nineth.utils.SnowflakeIdWorker;
 import com.izouma.nineth.web.BaseController;
 import io.ipfs.api.IPFS;
 import io.ipfs.api.MerkleNode;
@@ -52,12 +51,16 @@ import java.io.File;
 import java.io.IOException;
 import java.lang.reflect.Method;
 import java.math.BigDecimal;
+import java.math.BigInteger;
 import java.math.RoundingMode;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
 import java.nio.file.Paths;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
 import java.util.List;
 import java.util.*;
+import java.util.concurrent.ThreadLocalRandom;
 import java.util.regex.Pattern;
 
 import static java.nio.file.StandardOpenOption.CREATE;
@@ -374,7 +377,18 @@ public class CommonTest {
     }
 
     @Test
-    public void sdfsdf() {
-        System.out.println(new SnowflakeIdWorker(0, 0).nextId());
+    public void random256() throws NoSuchAlgorithmException {
+        Random random = ThreadLocalRandom.current();
+        byte[] r = new byte[2]; //Means 2048 bit
+        random.nextBytes(r);
+        MessageDigest m = MessageDigest.getInstance("MD5");
+        m.update(r, 0, r.length);
+        BigInteger bi = new BigInteger(1, m.digest());
+        System.out.println(bi);
+        System.out.println(bi.toString(16));
+
+        BigInteger bi1 = new BigInteger(256, new Random());
+        System.out.println(bi1);
+        System.out.println(bi1.toString(16));
     }
 }

+ 112 - 3
src/test/java/com/izouma/nineth/service/NFTServiceTest.java

@@ -1,16 +1,42 @@
 package com.izouma.nineth.service;
 
+import com.alibaba.fastjson.JSON;
+import com.alibaba.fastjson.JSONArray;
+import com.alipay.mychain.sdk.api.utils.Utils;
+import com.alipay.mychain.sdk.domain.transaction.LogEntry;
+import com.antfinancial.mychain.baas.tool.restclient.RestClient;
+import com.antfinancial.mychain.baas.tool.restclient.RestClientProperties;
+import com.antfinancial.mychain.baas.tool.restclient.model.CallRestBizParam;
+import com.antfinancial.mychain.baas.tool.restclient.model.Method;
+import com.antfinancial.mychain.baas.tool.restclient.model.ReceiptDecoration;
+import com.antfinancial.mychain.baas.tool.restclient.response.BaseResp;
 import com.izouma.nineth.ApplicationTests;
+import com.izouma.nineth.config.GeneralProperties;
+import com.izouma.nineth.dto.NFT;
+import com.izouma.nineth.utils.HashUtils;
+import com.izouma.nineth.utils.SnowflakeIdWorker;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.RandomStringUtils;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 
 import java.io.File;
+import java.math.BigInteger;
+import java.security.MessageDigest;
+import java.util.Random;
 import java.util.Scanner;
+import java.util.concurrent.ThreadLocalRandom;
 
+@Slf4j
 public class NFTServiceTest extends ApplicationTests {
     @Autowired
-    private NFTService nftService;
+    private NFTService           nftService;
+    @Autowired
+    private RestClient           restClient;
+    @Autowired
+    private RestClientProperties restClientProperties;
+    @Autowired
+    private GeneralProperties    generalProperties;
 
     @Test
     public void createAccount() {
@@ -19,8 +45,51 @@ public class NFTServiceTest extends ApplicationTests {
 
     @Test
     public void createToken() throws Exception {
-        for (int i = 0; i < 10; i++) {
-            nftService.createToken("raex_official");
+        JSONArray jsonArray = new JSONArray();
+        jsonArray.add(Utils.getIdentityByName("raex_official"));
+        Random random = ThreadLocalRandom.current();
+        byte[] r = new byte[32]; //Means 2048 bit
+        random.nextBytes(r);
+        MessageDigest m = MessageDigest.getInstance("MD5");
+        m.update(r, 0, r.length);
+        BigInteger bi = new BigInteger(1, m.digest());
+        jsonArray.add(bi.toString());
+        log.info("data {}", jsonArray.toJSONString());
+        CallRestBizParam callRestBizParam = CallRestBizParam.builder()
+                .orderId(String.valueOf(new SnowflakeIdWorker(0, 0).nextId()))
+                .bizid(restClientProperties.getBizid())
+                .account(restClientProperties.getAccount())
+                .contractName("raex111")
+                .methodSignature("mint(identity,uint256)")
+                .inputParamListStr(jsonArray.toJSONString())
+                .outTypes("[]")//合约返回值类型
+                .mykmsKeyId(restClientProperties.getKmsId())
+                .method(Method.CALLCONTRACTBIZASYNC)
+                .tenantid(restClientProperties.getTenantid())
+                .gas(500000L)
+                .build();
+        BaseResp resp = restClient.bizChainCallWithReceipt(callRestBizParam);
+        if (!resp.isSuccess()) {
+            log.info("EVM合约执行失败: " + resp.getCode() + ", " + resp.getData());
+        }
+        if ("200".equals(resp.getCode())) {
+            log.info("EVM合约执行成功");
+            // 合约调用交易回执内容
+            ReceiptDecoration txReceipt = JSON.parseObject(resp.getData(), ReceiptDecoration.class);
+            BigInteger gasUsed = txReceipt.getGasUsed();
+            long result = txReceipt.getResult();
+            log.info("EVM合约交易内容: 哈希 " + txReceipt.getHash() + ", 消耗燃料 " + gasUsed + ", 结果 " + result);
+            for (LogEntry logEntry : txReceipt.getLogs()) {
+                if (logEntry.getTopics().get(0).equals(HashUtils.Keccak256("Transfer(identity,identity,uint256)"))) {
+                    String tokenId = logEntry.getTopics().get(3);
+                    txReceipt.getBlockNumber();
+                    NFT nft = new NFT(txReceipt.getHash(), tokenId, txReceipt.getBlockNumber(), txReceipt.getGasUsed());
+                    log.info("NFT生成成功 {}", nft);
+                }
+            }
+        } else {
+            // 异步交易未成功需要根据状态码判断交易状态
+            log.error("EVM合约执行未成功: " + resp.getCode());
         }
     }
 
@@ -70,4 +139,44 @@ public class NFTServiceTest extends ApplicationTests {
 
         nftService.deployContract("nine_space_test" + System.currentTimeMillis(), lines[idx + 2]);
     }
+
+    @Test
+    public void ownerof() throws Exception {
+        CallRestBizParam callRestBizParam = CallRestBizParam.builder()
+                .orderId(String.valueOf(new SnowflakeIdWorker(0, 0).nextId()))
+                .bizid(restClientProperties.getBizid())
+                .account(restClientProperties.getAccount())
+                .contractName("raex111")
+                .methodSignature("ownerOf(uint256)")
+                .inputParamListStr("[\"305596637601946315409962168553415519496\"]")
+                .outTypes("[identity]")//合约返回值类型
+                .mykmsKeyId(restClientProperties.getKmsId())
+                .method(Method.CALLCONTRACTBIZASYNC)
+                .tenantid(restClientProperties.getTenantid())
+                .gas(500000L)
+                .build();
+        BaseResp resp = restClient.bizChainCallWithReceipt(callRestBizParam);
+        if (!resp.isSuccess()) {
+            log.info("EVM合约执行失败: " + resp.getCode() + ", " + resp.getData());
+        }
+        if ("200".equals(resp.getCode())) {
+            log.info("EVM合约执行成功");
+            // 合约调用交易回执内容
+            ReceiptDecoration txReceipt = JSON.parseObject(resp.getData(), ReceiptDecoration.class);
+            BigInteger gasUsed = txReceipt.getGasUsed();
+            long result = txReceipt.getResult();
+            log.info("EVM合约交易内容: 哈希 " + txReceipt.getHash() + ", 消耗燃料 " + gasUsed + ", 结果 " + result);
+            for (LogEntry logEntry : txReceipt.getLogs()) {
+                if (logEntry.getTopics().get(0).equals(HashUtils.Keccak256("Transfer(identity,identity,uint256)"))) {
+                    String tokenId = logEntry.getTopics().get(3);
+                    txReceipt.getBlockNumber();
+                    NFT nft = new NFT(txReceipt.getHash(), tokenId, txReceipt.getBlockNumber(), txReceipt.getGasUsed());
+                    log.info("NFT生成成功 {}", nft);
+                }
+            }
+        } else {
+            // 异步交易未成功需要根据状态码判断交易状态
+            log.error("EVM合约执行未成功: " + resp.getCode());
+        }
+    }
 }